Professional Documents
Culture Documents
Untitled 1
Untitled 1
linear search
first assign the index no
a= [“brown”,|”red”,”blue"] a = 0,1,2
then assign counter to zero\
counter = 0
check the value at position counter with the search alue
a[counter] == search value
a[0] == red
brown== red
false
if the value is not equal, increment cunter by 1
counter = counter + 1
counter = 0 + 1
counter 1
a[counter] = search value
a[1] == 20
20 == 20
true
Hence value was found at position 1
Binary search
first arrange the array in ascending order
a= [20,30,10] a=[10,20,30]
assign index no to each value
a= 0,1,2
assign begin, end and calculate mid= (begin + end )/ 2
begin = 0 end = 2
mid 0 + 2 /2 1
else assign mid to begin or end depending on the value you are searhing
begin = 1 end 2