Re: element location in a vector ?
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 22 Dec 2005 18:07:19 +0000 (UTC)
AM <wiredashu@xxxxxxxxx> wrote:
> Hello all...
> I was wondering if anyone else might have discovered a quick way of
> locating the position of an element in a vector ? Something akin to the
> "find' function in MATLAB. The only intrinsic functions i found - that
> had to do with location in a vector were:
> MAXLOC/MINLOC.
> SO just checking.
If you only need to do it once, there is no faster way than
linear search through all the elements, or all up until you find
the one you want.
If you need to do it more than once, sort the vector, O(n log n)
and use binary search, O(log n) each time.
If you know in advance that you need to find elements by content
and don't need to access them by position a hash table is commonly
used.
-- glen
.
- References:
- element location in a vector ?
- From: AM
- element location in a vector ?
- Prev by Date: Re: Is there an array shorthand for this?
- Next by Date: Re: (OT) Demise of Jan van Oosterwijk
- Previous by thread: Re: element location in a vector ?
- Next by thread: Re: element location in a vector ?
- Index(es):
Relevant Pages
|