Re: element location in a vector ?



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
.



Relevant Pages

  • element location in a vector ?
    ... locating the position of an element in a vector? ... Something akin to the ... The only intrinsic functions i found - that ... Prev by Date: ...
    (comp.lang.fortran)
  • Re: element location in a vector ?
    ... | locating the position of an element in a vector? ... The only intrinsic functions i found - that ... Please reply to the newsgroup. ... You can find my real e-mail on my home page above. ...
    (comp.lang.fortran)
  • Re: element location in a vector ?
    ... > locating the position of an element in a vector? ... The only intrinsic functions i found - that ... Mike Metcalf ... Prev by Date: ...
    (comp.lang.fortran)