MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
The algorithm below is used to find the largest element in a list of numbers.By modifying one of the lines in the program it is possible to make the algorithm find the SMALLEST element. Which line would need to be modified and how?01 target <-list[1]02 FOR EACH num IN list03 {04 IF(num > target)05 {06 target <-num07 }08 }09 DISPLAY(target)
A
Line 01 becomes target <-list[2]
B
Line 04 becomes IF (num < target)
C
Line 04 becomes if (num <= target)
D
Line 01 becomes list[0] <-target
Explanation: 

Detailed explanation-1: -Expert-Verified Answer. All the numbers in the list are arranged in the ascending order such that the smallest number comes at the beginning and so on. Now, the number which occur at the last is the required largest number.

Detailed explanation-2: -We are given an integer array of size N or we can say number of elements is equal to N. 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 kth largest element can be found with the help of the heap. Here, we have used max heap; we first convert the given array into a max-heap first, then replace the root with the last element, decrease the heap size by one and then convert it into a max-heap again. We follow the same steps k-1 times.

Detailed explanation-4: -log(max); var min = numbers. reduce((total, value, index, array) => if(index === 0) return array[0]; return total < value ? total : value; ); console. log(min);

There is 1 question to complete.