You are on page 1of 1

www.eazynotes.

com

Gursharan Singh Tatla

Page No. 1

BINARY SEARCH
Binary Search ( ):
Description: Here A is a sorted array having N elements. ITEM is the value to be searched. BEG denotes first element and END denotes last element in the array. MID denotes the middle value. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. Exit Else Print: ITEM doesnt exist [End of If] Else Set BEG = MID + 1 [End of If] Set MID = (BEG + END) / 2 [End of While Loop] If (A[MID] == ITEM) Then Print: ITEM exists at location MID Set BEG = 1 and END = N Set MID = (BEG + END) / 2 Repeat While (BEG <= END) and (A[MID] ITEM) If (ITEM < A[MID]) Then Set END = MID 1