The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
39 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 (6k points)
closed by | 39 views

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)
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.
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.
Yes thanks! I was considering that while implementing also.


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

29,961 questions
37,632 answers
96,399 comments
35,286 users