## SEARCH

### SEARCH

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

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

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

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

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

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

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

>.

To Graphics-search the most search engines
in the shortest time, use the internet's newest
search engine - Search Spaniel at:
http://www.searchspaniel.com/