168 views

In this given question I find all answers false because while implementing binary seach or tracing it for an example we need to follow same approach Right? if we are taking ceil for evaluation then it should be considered throughout and if we are taking floor accordingly it should be traced.Therefore applying both operating individually I find none of the options matching.
Correct Me If I am wrong here.

closed with the note: Sorted.Misconception Regarding Calculation Of mid element.
closed | 168 views
+2

option 1 is correct,  see below,

bolded keys show target array for binary search and bolded key show target key.

mid = floor(10+1/2) = 5

 3(1) 5(2) 6(3) 8(4) 11(5) 12(6) 14(7) 15(8) 17(9) 18(10)

mid = floor(1+4/2) = 2

 3(1) 5(2) 6(3) 8(4) 11(5) 12(6) 14(7) 15(8) 17(9) 18(10)

mid = floor(3+4/2) = 3

 3(1) 5(2) 6(3) 8(4) 11(5) 12(6) 14(7) 15(8) 17(9) 18(10)

mid = floor(4+4/2) = 4

 3(1) 5(2) 6(3) 8(4) 11(5) 12(6) 14(7) 15(8) 17(9) 18(10)
0
In second step a[5]>8 Then lb=1 same and ub=5 then mid =(5+1)/2=3 Though you started with 1 given is 0 but this solution also doesnt follow any sequence Chek it please.
+1
it does'nt matter either you take start index=0 or 1,

next mid should be (1+4)/2, why are you taking (1+5)/2, new target array is from A[1...4], because A[5] is already checked.
0
Yes thanks! I was considering that while implementing also.
0
Both sequence a and b are possible.

1
2
+1 vote