Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Gaming > Development Programming Algorithms > Re: Binary sear...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 11 Topic 665 of 680
Post > Topic >>

Re: Binary search with timestamps

by Miss Elaine Eos <Misc@[EMAIL PROTECTED] > Feb 13, 2008 at 06:15 AM

In article <qq0a85-q99.ln1@[EMAIL PROTECTED]
>,
 Luc The Perverse <ataylor_no_spa_am@[EMAIL PROTECTED]
> wrote:

> I suggest calling your variables top and bottom.
> 
> And there are 3 cases, not two.  One is your pivot point is less than 
> the target, your pivot point is greater than the target or your pivot 
> point equals the target.  You exit if top<bottom.

To clarify, what he's suggesting is this:

(NOTE: logic completely done in newsreader, no syntax or correctness 
checking done.  But this should be easy to debug.)

top = array.length
bottom = 0
foundIndex = -1
while (top > bottom)
{
   mid = (top + bottom) / 2
   if array [mid] == desiredValue
      foundIndex = mid
      break
   else if array [mid] > desiredValue
      top = mid
   else
      bottom = mid
}

return (foundIndex)

-- 
Please take off your pants or I won't read your e-mail.
I will not, no matter how "good" the deal, patronise any business which
sends
unsolicited commercial e-mail or that advertises in discussion newsgroups.
 




 11 Posts in Topic:
Binary search with timestamps
Makhno <root@[EMAIL PR  2008-02-12 21:27:40 
Re: Binary search with timestamps
Luc The Perverse <atay  2008-02-12 18:21:45 
Re: Binary search with timestamps
Miss Elaine Eos <Misc@  2008-02-13 06:15:07 
Re: Binary search with timestamps
Makhno <root@[EMAIL PR  2008-02-13 20:34:36 
Re: Binary search with timestamps
Makhno <root@[EMAIL PR  2008-02-13 21:07:58 
Re: Binary search with timestamps
Miss Elaine Eos <Misc@  2008-02-14 05:05:19 
Re: Binary search with timestamps
Luc The Perverse <atay  2008-02-15 08:35:05 
Re: Binary search with timestamps
Makhno <root@[EMAIL PR  2008-02-18 22:24:10 
Re: Binary search with timestamps
Makhno <root@[EMAIL PR  2008-02-13 20:42:16 
Re: Binary search with timestamps
Luc The Perverse <atay  2008-02-12 18:24:50 
Re: Binary search with timestamps
Makhno <root@[EMAIL PR  2008-02-13 20:51:21 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 19:25:53 CDT 2008.