COMPUTER SCIENCE AND ENGINEERING
ALGORITHMS
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
A BINARY SEARCH looks through a list named studentList finds an what it was searching for in the first spot it looked. Where was it?
|
at index 0
|
|
at index studentList.length / 2
|
|
at index studentList.length
|
|
None of the above
|
Explanation:
Detailed explanation-1: -The divide and conquer strategy is used in binary search, where the item is compared to the middle element of the list after the list is divided into two halves.
Detailed explanation-2: -Binary search is an efficient algorithm for finding an item from a sorted list of items. It works by repeatedly dividing in half the portion of the list that could contain the item, until you’ve narrowed down the possible locations to just one.
Detailed explanation-3: -When we binary search on an answer, we start with a search space of size N which we know the answer lies in. Then each iteration of the binary search cuts the search space in half, so the algorithm tests O(logN) values.
There is 1 question to complete.