retagged by
1,276 views
0 votes
0 votes
The average number of comparisons made by binary search for an unsuccessful search in array A
retagged by

1 Answer

1 votes
1 votes

let us consider binary search tree for array elements ={10,8,15,3,12}.

consider the diagram :

black circle = elements present in array

red circle = elements not present in Array ( unsuccessful search keys).

.

now suppose we search for key 1 :

we will first search at root =10 (absent). then we will drop dowm next level as (1<10) and goto left tree. value of new node = 8( not equal to 1 and 1<8) we will drop down new node where key = 3 (not equal to 1 ).

now here we know that 3 does not have any child node so we will stop here (in other words we know that array is empty)

#comparisons = 3. 

similarly for other keys :   

keys(unsuccessful search) #comparisons
1 3
4 3
9 2
11 3
13 3
16 2

overall comparison = 3+3+2+3+3+2 (or total external node length El)

considering unsuccessful keys = external nodes

#number of candidates = 6 (or number of internal nodes(I) +1).

so average comparisons = total comparisons/ #keys(US)

                                           =  ( E) / (I+1) answer

Related questions