ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Sorted array
Array = 11, 22, 30, 33, 40, 44, 45
Term = 40
Step 1:
BEG = 1 and END = 7
MID = BEG+END/2 = 1+7/2 = 4
Array[MID] = Array[4] = 33
Step 2:
33 < 40
BEG = MID + 1 = 4+1 = 5
MID = BEG+END/2 = 5+7/2 = 6
Array[MID] =44
Step 3:
44 > 40
END = MID ¨C 1 = 6 ¨C 1 = 5
MID = BEG+END/2 = 5 + 5/2 = 5
Array[MID] = 40
ITEM IS FOUND AT POSITION NO. 5

More Related Content

Binary Search

  • 1. Sorted array Array = 11, 22, 30, 33, 40, 44, 45 Term = 40 Step 1: BEG = 1 and END = 7 MID = BEG+END/2 = 1+7/2 = 4 Array[MID] = Array[4] = 33 Step 2: 33 < 40 BEG = MID + 1 = 4+1 = 5 MID = BEG+END/2 = 5+7/2 = 6 Array[MID] =44 Step 3: 44 > 40 END = MID ¨C 1 = 6 ¨C 1 = 5 MID = BEG+END/2 = 5 + 5/2 = 5 Array[MID] = 40 ITEM IS FOUND AT POSITION NO. 5