MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Given this array:1, 2, 4, 5, 6, 7, 8, 12, 14, 21, 22, 42, 53How many comparisons are required to find 42 using the Linear Search / Sequential Search?
A
3
B
2
C
12
D
5
Explanation: 

Detailed explanation-1: -In general, the average number of comparisons per pass in selection sort will always be one half of the number of items to be sorted. For eight items, we have 1/2(82 + 8) = 1/2(64 + 8) = 1/2(72) = 36 comparisons.

Detailed explanation-2: -What must be true before performing a binary search? The elements must be sorted.

Detailed explanation-3: -Since 64=2log2(64)=26 64 = 2 log 2 ⁡ ( 64 ) = 2 6, the number of comparisons required for an array of length 64 is 1+log2(64)=1+6=7 1 + log 2 ⁡ ( 64 ) = 1 + 6 = 7 .

Detailed explanation-4: -The number of comparisons will be N-1 times the average length of the sorted list.

There is 1 question to complete.