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 7 of 11 Topic 665 of 675
Post > Topic >>

Re: Binary search with timestamps

by Luc The Perverse <ataylor_no_spa_am@[EMAIL PROTECTED] > Feb 15, 2008 at 08:35 AM

Miss Elaine Eos wrote:
> In article <5qWdnVOXpYvXyS7aRVnyiwA@[EMAIL PROTECTED]
>, Makhno <root@[EMAIL PROTECTED]
> 
> wrote:
> 
>>> 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)
>> Afraid this doesn't work, as it assumes desiredValue is an integer, or 
>> at least directly present in the list. eg I could have
>>
>> 0.5
>> 1.2
>> 5.6
>> 5.8
>> 7.4
>> 9.0
>>
>> for desiredValue=6.2 then I would like index 3, because index 3&4 
>> bracket the desiredValue.
> 
> Ah, that wasn't in the original spec.  I thought you were searching for 
> an exact value.
> 
>> It was not as easy as I initially assumed, even though my algorithm 
>> works for most cases.
> 
> If the value does not exist in the array, then what is it you'd like to 
> be returned?  1 greater than the largest index still smaller than the 
> value?  I don't think your other solution (posted after this) does that.
> 

I agree - this is nothing like what you originally asked for.

It is im****tant to define exactly what it is that you want - this 
enables you to test it and know if it is working.

It doesn't have to be elaborate.  For example:

A function which returns the first item in a sorted array greater than 
or equal to a given value.

I work in QA right now, and it is my job to find minor discrepancies 
such as these :)

--
LTP

:)
 




 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 Wed Jul 9 4:43:25 CDT 2008.