2079 5

CSC211 ยท 2079 ยท 5 marks

Write a program to implement binary search.

Write a program to implement binary search. [5]

Data Structures and AlgorithmsChapter 7: Searching and HashingIntroduction to Searching, Search Algorithms

Binary search works on a sorted array by repeatedly dividing the search interval in half. It compares the target key with the middle element and narrows the search to the left or right sub-list accordingly. --- --- --- --- Step l r m a[m] Action ----------------------------- 1 0 6 3 40 key == a[m...