COMPUTER SCIENCE AND ENGINEERING
DATA STRUCTURES
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
With a data set of 0, 1, 3, 6, 7, 8, 9How many steps would a binary search take to find the value 8?
|
2
|
|
4
|
|
3
|
|
7
|
Explanation:
Detailed explanation-1: -It would take only three iterations with the Binary Search algorithm. However, the main disadvantage of the Binary Search algorithm is that it requires a sorted array to discard half of the search space at each iteration.
Detailed explanation-2: -So with an array of length 8, binary search needs at most four guesses.
Detailed explanation-3: -Step 1-Read the search element from the user. Step 2-Find the middle element in the sorted list. Step 3-Compare the search element with the middle element in the sorted list. Step 4-If both are matched, then display “Given element is found!!!” and terminate the function.
There is 1 question to complete.