in Algorithms
455 views
0 votes
0 votes
Suppose we have the following sorted list:

[3,5,6,8,11,12,14,15,17,18]

Array data structure is used. we are using recursive binary search algorithm to search an element 8. Which of the following group of numbers correctly shows the sequence of comparisons used to find element 8?

Assume array indexing starts with 0.

(a) 11,6,5,8

(b) 12,6,11,8

(c) 3,5,6,8

(d) 18,12,6,8
in Algorithms
455 views

9 Comments

What will be the answer? I am getting 11,5,6,8 as answer. But answer is given as option (b)...How?
0
0
You got the order correct i.e. 11,5,6,8 and option A is 11,6,5,8.

Now another way in which this can be done is by taking mid=ceil{(low+up)/2}. Though convention is to take the floor value. But one option has to be right and taking ceil won't give wrong result. So by doing so you can get B).
3
3

MiNiPandu   yes you're right

0
0

 @Magma

MiNiPandu  

!! :v :v

0
0
Ooh by mistake :p

lol !
0
0
@MiniPanda ok got it..but if nothing is mentioned, then by default it is floor((low+high)/2) right?
0
0
0
0
ok..thanks MiniPanda :)
0
0
in GATE, the question doesn't force to the students in to the ambiguity in general, but there are some exceptions
0
0

Please log in or register to answer this question.