Question discussion

Binary search algorithm cannot be applied to which of following?

207523Medium 1 reply 607 views
21
Binary search algorithm cannot be applied to which of following?
  • ASorted linked list
  • BSorted binary tree
  • CSorted linear array
  • DPointer array
Answer not set

Discussion 1

0
CCommunity
Binary search is also known as half-interval search. It works efficiently with a sorted list. Binary search compares the target value to the middle element of the list. If they are not equal narrow the interval to the lower half (i.e. elements appear before middle element). Otherwise, narrow it to the upper half (i.e. element appear after middle element). Repeatedly check until the target value is found.

Pre-requisite for binary search is to have a sorted array.