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

1 Answer

1 1 vote

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)

                                           =  ( El ) / (I+1) answer

Position:
Show:

Related questions

0 0 votes
1 1 answer
154
154 views
GO Classes asked Aug 26
154 views
Which of the following cannot be a sequence of keys compared during a binary search for some target key?$500,200,450,180$ $500,450,200,180$ $180,500,200,450$ $180,200,500...
2 2 votes
2 2 answers
184
184 views
GO Classes asked Aug 12
184 views
Suppose Binary Search is used in Insertion Sort to locate where the $i$th element should be inserted among the first $i-1$ elements.What is the worst-case running time of...
2 2 votes
1 1 answer
210
210 views
GO Classes asked Aug 4
210 views
A sorted table contains $2000$ distinct elements in increasing order. A key is searched using binary search, and it is guaranteed that the key exists in the table.What is...
4 4 votes
2 2 answers
888
888 views
gatecse asked Feb 23
888 views
Let A be a sorted array containing $1000$ distinct integers. You perform a recursive binary search on $\text{A}$ to find an element $\text{y}$. Suppose each comparison ch...