MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
EXAMPLE 1 Consider the problem of finding the value of the largest element in a list of n numbers. For simplicity, we assume that the list is implemented as an array. The following is pseudocode of a standard algorithm for solving the problem. ALGORITHM MaxElement(A[0..n-1]) //Determines the value of the largest element in a given array //Input:An array A[0..n-1] of real numbers //Output:The value of the largest element in A maxval ← A[0]for i ← 1 to n-1 do if A[i] > maxval maxval ← A[i]return maxvalIs the algorithm correct for the above question?
A
yes
B
no
C
Either A or B
D
None of the above
Explanation: 

Detailed explanation-1: -To find the largest element from the array, a simple way is to arrange the elements in ascending order. After sorting, the first element will represent the smallest element, the next element will be the second smallest, and going on, the last element will be the largest element of the array.

Detailed explanation-2: -We have to find the largest/ maximum element in an array. The time complexity to solve this is linear O(N) and space compexity is O(1).

Detailed explanation-3: -The worst-case time complexity is O(log N) . This means that as the number of values in a dataset increases, the performance time of the algorithm (the number of comparisons) increases as a function of the base-2 logarithm of the number of values.

There is 1 question to complete.