You are not logged in. Please login at www.codechef.com to post your questions!

×

binary search base case

if(low==high)
    {
        if(a[low]==key)
           {
               return low;
           }
        else
           {cout<<"THE value doesnt exist";
             return nill;
           }

why is this base case not working for binary search

asked 25 Aug '13, 20:11

surajkvm007's gravatar image

1★surajkvm007
3191317
accept rate: 0%

edited 25 Aug '13, 21:09

kuruma's gravatar image

3★kuruma
17.7k72143209

can u give ur whole code...or maybe the whole of ur binary search implementation!!!

(25 Aug '13, 22:24) kunal3614★

it might be a case that in while loop , the low index has passed (become greater) ,than 'high' index , therefore , i guess your if condition is not getting satisfied and hence , not giving desired output.

link

answered 25 Aug '13, 20:22

priyanshuid's gravatar image

3★priyanshuid
3866818
accept rate: 0%

can u please provide a simple test case ?? i mean what u are saying is the standard recursive definition but i am just curious to know why this case isnt working

(25 Aug '13, 20:29) surajkvm0071★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×690
×166
×68

question asked: 25 Aug '13, 20:11

question was seen: 1,886 times

last updated: 25 Aug '13, 22:24