b. Given an array containing 286 telephone area codes assigned to the United States of America as shown below, and with the aid of illustration, show how the binary search can be used to locate the area code for: i. Silicon Valley area, which is 650 ii. Alaska area Code, which is 907 and iii. North Dakota Area Code of 701
search is 650
Initially, start will be 0 and end will be 285 and mid = (0+285)/2 = 142 and array[142]=602<650
So, start will be 143 and end will be 285 and mid= (143+285)/2 = 214 and array[214]=805>650
So, start will be 143 and end will be 213 and mid= (143+213)/2 = 178 and array[178]=708>650
So, start will be 143 and end will be 177 and mid= (143+177)/2 = 160 and array[160]=630<650
So, start will be 161 and end will be 177 and mid= (161+177)/2 = 169 and array[169]=662>650
So, start will be 161 and end will be 168 and mid= (161+168)/2 = 164 and array[164]=646<650
So, start will be 164 and end will be 168 and mid= (164+168)/2 = 166 and array[166]=651>650
So, start will be 164 and end will be 165 and mid= (164+165)/2 = 164 and array[164]=646<650
So, start will be 165 and end will be 165 and mid= (165+165)/2 = 165 and array[165]=650=650
Thus, element found
Step by step
Solved in 3 steps