First time here? Checkout the FAQ!
0 votes
If the binary search algorithm determines that the scanned argument is in upper half of the array,which of the following statement will set the appropriate variable to the appropriate value.

A) startsub= middlesub-1;

B) startsub=middlesub+1;


asked in DS by (421 points)   | 190 views

2 Answers

+2 votes
Best answer
Option B is Ans

Cz as we know the Searching element is in Upper half then We will Increase the middlesub index  by 1. So that our search space is reduced by half.

So stopsub as it is and startsub=middlesub+1

So option B is correct Ans.
answered by Veteran (16.8k points)  
selected by
For the binary search ,the array is order(ascending).So if we know searching element is in upper half ,means that we should continue search in upper half.So our lower index would change and not the upperindex..

My confusion is with the understanding of the question.what the question mean when it says "Scanned argument".Is it the key that we want to search (search argument) or the scanned array element.

If search argument is less than the middle element the we do stopsub=middle -1;

And if the search argument is greater than middle element then we do startsub=middlesub+1;

Please solve my doubt around the question understanding.
Oh..Yes I have drawn the array vertically ;;So I Thought that Upper half means LHS..

But Now I drawn it horizontally..Cz max people do so.

&Ur Doubt:--It is the search element


See my Edited Ans..->>Thanks for Comment
+1 vote
B. startsub = middlesub + 1
answered by Loyal (3.5k points)  

Top Users May 2017
  1. akash.dinkar12

    3578 Points

  2. pawan kumarln

    2314 Points

  3. Bikram

    1950 Points

  4. Arjun

    1848 Points

  5. sh!va

    1682 Points

  6. Debashish Deka

    1296 Points

  7. Devshree Dubey

    1282 Points

  8. Arunav Khare

    1122 Points

  9. Angkit

    1072 Points

  10. LeenSharma

    1028 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 29 - Jun 04
  1. Arunav Khare

    246 Points

  2. Arjun

    198 Points

  3. pawan kumarln

    108 Points

  4. Niharika 1

    90 Points

  5. pC

    90 Points

22,909 questions
29,242 answers
27,744 users