Re: ArrayList BinarySearch vs Contains
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Fri, 10 Nov 2006 16:35:29 -0800
"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:%23QBKHbSBHHA.1196@xxxxxxxxxxxxxxxxxxxxxxx
e.g., if you have 10 items in the list then the worst case in a linear
search would be O(n). This means that the worst case scenario would be
examining every item in the list (10 operations). The worst-case in a
binary search would be O(lg(n)).
Note:
"Order" stated by itself is almost always for *average* performance, not
worst-case. One would normally specify explicitly if describing the
worst-case order for an algorithm.
For example, it is NOT true that "the worst-case in a binary search would be
O(log(n))" for all implementations of a binary search. If you have a sorted
array, it's true that the worst case is O(log(n)). However, if you have a
binary tree, a search on that tree could be as bad as O(n).
Pete
.
- Follow-Ups:
- Re: ArrayList BinarySearch vs Contains
- From: Bill Butler
- Re: ArrayList BinarySearch vs Contains
- From: Dave Sexton
- Re: ArrayList BinarySearch vs Contains
- References:
- ArrayList BinarySearch vs Contains
- From: tshad
- Re: ArrayList BinarySearch vs Contains
- From: Carl Daniel [VC++ MVP]
- Re: ArrayList BinarySearch vs Contains
- From: tshad
- Re: ArrayList BinarySearch vs Contains
- From: Dave Sexton
- ArrayList BinarySearch vs Contains
- Prev by Date: Re: ArrayList BinarySearch vs Contains
- Next by Date: Re: ArrayList BinarySearch vs Contains
- Previous by thread: Re: ArrayList BinarySearch vs Contains
- Next by thread: Re: ArrayList BinarySearch vs Contains
- Index(es):
Relevant Pages
|