SEARCH

SEARCH

Post by Ernesto Gutiérre » Fri, 04 Jan 2002 14:35:32



HI.

I need a search algorithm. This is my case.

I have an array of integers, the numbers are sorted.   Now I want o find the
firts number greater than a X number.

Example:

Array : 2-6-7-9-10-15-16-18-20
Then I need to find the firts number greater ( >= ) than 10. The number is
15.

BUT I WANT A LINEAR ALGORITM I NEED A FAST ALGORITM LIKE BINARY SEARCH!!!!!>

THANKS

Ernesto Gutirrez

 
 
 

SEARCH

Post by Amir Cica » Sat, 05 Jan 2002 12:59:23


So, why dont you use binary search?

Btw, if it is linear it can not be fast like binary search, because binary
is log.


Quote:> HI.

> I need a search algorithm. This is my case.

> I have an array of integers, the numbers are sorted.   Now I want o find
the
> firts number greater than a X number.

> Example:

> Array : 2-6-7-9-10-15-16-18-20
> Then I need to find the firts number greater ( >= ) than 10. The number is
> 15.

> BUT I WANT A LINEAR ALGORITM I NEED A FAST ALGORITM LIKE BINARY
SEARCH!!!!!>

> THANKS

> Ernesto Gutirrez


 
 
 

SEARCH

Post by Ernesto Gutiérre » Sat, 05 Jan 2002 14:17:23


Well, i can't use binary search because I'm don't know what's the number i
want to find... the binary search need an argument that say the number that
i want to search not the first number greater than this number.

Someone Knows ?

Thanks

Ernesto

 
 
 

SEARCH

Post by Warren Marshal » Sat, 05 Jan 2002 23:32:43


How can you search when you don't know what you're searching for?


Quote:> Well, i can't use binary search because I'm don't know what's the number i
> want to find... the binary search need an argument that say the number
that
> i want to search not the first number greater than this number.

> Someone Knows ?

> Thanks

> Ernesto

 
 
 

SEARCH

Post by Wayne S. Freez » Sun, 06 Jan 2002 01:28:12


Why not search for that particular value using a binary search and then
choose the next one in the array?

      ........Wayne

"Recycling electrons into words since 1996."
Visit www.JustPC.com for details about my Visual Basic books, including
my newest: Windows Game Programming With Visual Basic and DirectX,
and the ASP.NET Database Programming Bible. Subscribe to the JustPC
Developer's Journal - a free email newsletter for Visual Basic programmers


Quote:> Well, i can't use binary search because I'm don't know what's the number
i
> want to find... the binary search need an argument that say the number
that
> i want to search not the first number greater than this number.

> Someone Knows ?

> Thanks

> Ernesto

 
 
 

SEARCH

Post by Amir Cica » Sun, 06 Jan 2002 06:17:35


Because he cant know if particular value is in the array. For example array
is 10, 20 , 30 , 40, 50, and he must find first number greater than 34.
Anyway he can still do it using binary search. Search until either find that
value or n is 0; (n which is in binary search distance from current value,
and in beginning arraylength/2, in loop n=n/2). If the value is found just
pick next number, if not (n=0) see if current value is less or greater than
that value and than go lineary up or down depending on current value,
because you are already very close to that value.

Sorry because this doesnt belong to this newsgroup.



> Why not search for that particular value using a binary search and then
> choose the next one in the array?

>       ........Wayne

> "Recycling electrons into words since 1996."
> Visit www.JustPC.com for details about my Visual Basic books, including
> my newest: Windows Game Programming With Visual Basic and DirectX,
> and the ASP.NET Database Programming Bible. Subscribe to the JustPC
> Developer's Journal - a free email newsletter for Visual Basic programmers



> > Well, i can't use binary search because I'm don't know what's the number
> i
> > want to find... the binary search need an argument that say the number
> that
> > i want to search not the first number greater than this number.

> > Someone Knows ?

> > Thanks

> > Ernesto

 
 
 

SEARCH

Post by John Donova » Tue, 08 Jan 2002 23:29:40


Quote:>-----Original Message-----

>How can you search when you don't know what you're

searching for?

That sounds like a question for
win32.programmer.philosophy to me :)

-J



>> Well, i can't use binary search because I'm don't know
what's the number i
>> want to find... the binary search need an argument that
say the number
>that
>> i want to search not the first number greater than this
number.

>> Someone Knows ?

>> Thanks

>> Ernesto

>.