Question
Asked by:
AF_Programmer
AF_Programmer
Rating : No Rating
Questions Asked: 3
Tutorials Posted: 0
 

$15.00 Binary Search Routine

Q:
Please reference the attached C++ file. The question I need answered is:

Suppose that line 15 in the binary search routine had the statement low = mid instead of low = mid + 1. Would the routine still work?

I need to be able to prove the answer. Thank you for any help you can provide.
 
Attachments:
binarySearch.cpp (0K)


   
   
   
   
 
Available Tutorials to this Question
Posted by:
wintermute
wintermute
Rating : No Rating
Questions Asked: 0
Tutorials Posted: 3, earned $0.00
 

$15.00 No: And here is why...

  • This tutorial hasn't been purchased yet.
  • Posted on Jan 01, 2009 at 7:42:10PM
A:
Preview: ... ts to the end of array. Each iteration you move either Low pointer higher, or High pointer lower. As a result, your remainder of the unsearched array is halved in size (hence binary search). Now, as this process nears the end of the array ( ...

The full tutorial is about 224 words long .
Posted by:
stevesov
stevesov
Rating (14): A-
Questions Asked: 0
Tutorials Posted: 109, earned $214.74
 

$10.00 Unfortunately, no. Worse, you may never "return"...

  • This tutorial was purchased 3 times and rated A- by students like you.
  • Posted on Jan 01, 2009 at 8:09:48PM
A:
Preview: ... binary search is pretty clear:<br><br>Start with a sorted list, check the middle "item" and if it is NOT a match, then you cut your list in half (either above or below the middle that you just checked.)<br><br>However, look at the circumstance where your data consists of a 2 element vector, and the "match" you are looking for is the "second" element.<br><br>You come into the code, set up your low and high limits as zero and one, then calculate th "middle". (0+1)=1, divide by 2 is .5, but you are using INTEGER math.. ...

The full tutorial is about 457 words long .
   
Join Now or Log In
Get Tutoring
Get Paid
Academic Honesty