tags:

views:

306

answers:

4

Without using extensions methods (LINQ). I am restricted to .NET 2.0 unfortunately. (Yeah, it sucks)

Looking for something close to O(log(n)).

Thanks for your help.

A: 

Since it's sorted, loop through and use Compare.

Update: Of course, that's assuming it's a list of Strings. If not, compare whatever it is that makes the current item less or greater than the search term and act accordingly.

Michael Todd
do you mean O(log(n))?
Kevin
Thanks for you input, but I am interested in something close to O(log(n)). Typo before.
Newbie
+1  A: 

Binary search it for an O(n log n) lookup.

dss539
See http://en.wikipedia.org/wiki/Binary_search for explanation, though I can't imagine you need it.
Brian
Binary search is O(log(n)) if item access is O(1).
Daniel Brückner
+3  A: 

To find the first key that is greater than a given key you could use the list of keys SortedList<T>.Keys and perform a Binary Search or Interpolation Search on the keys. This will yield O(log(n)) (MSDN states that a key look up is O(1)).

Daniel Brückner
Yes! First Key that greater than the search key or even First key that is less than the search key. Thanks for you time.
Newbie
A: 

search where things are in oder O(log n) binary search

search for where things are not in order O(n) linear. Can't do better if things are not in order.

The idea of making the values in order by order takes O(n * log(n)) unless you are going to be doing this over and over and caching the result why bother? just use your linear search.

(note thought you were interested in searching the value not the key)

AndrewB