The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+2 votes
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.
asked in Algorithms by Boss (11.8k points)
closed by | 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.

Related questions

+1 vote
1 answer
3
+3 votes
1 answer
4
asked Nov 23, 2017 in Algorithms by saxena0612 Boss (11.8k points) | 318 views
+3 votes
1 answer
5


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

42,687 questions
48,653 answers
156,493 comments
63,963 users