Add a gif showing binary search and linear search (#32384)
This commit is contained in:
@ -17,6 +17,8 @@ Because we know that names in the phonebook are sorted alphabetically, we could
|
||||
3. Otherwise, throw away the half of the phonebook that does not contain the name
|
||||
4. Repeat until you find the name or there are no more pages left in the phonebook
|
||||
|
||||
[]
|
||||
|
||||
Time complexity: As we dispose off one part of the search case during every step of binary search, and perform the search operation on the other half, this results in a worst case time complexity of *O*(*log<sub>2</sub>N*).
|
||||
The best case occurs when the element to be found is in the middle of the list. The best case time complexity is *O*(*1*).
|
||||
|
||||
|
Reference in New Issue
Block a user