I am working in C# 4.0 and I have the following problem:
given a finite set S of real numbers and a parameter k (NOT NECESSARILY IN THE SET), find the smallest number in S greater than or equal to k.
Obviously, I could use a balanced binary tree to do so. However, there is no implementation of such data structure in C# that could help me. What are the options of algorithms and possible implementations in C#?
Edit:
since most of people are more interested in criticizing than really helping, I will explain more:
it is for an algorithm that divides a real function in millions of pieces (or bins, like an histogram), and I need to find the piece that contains k in and efficient way to apply some computation in it. The pieces are real intervals of the form [a; b) and do not overlap.
The method I am designing needs to take the piece, given k, and is performance critical since it should be called thousands of times per second. Therefore, an O(n) search is unacceptable.
The time wasted on building the data structure of S is not important and not critical, since the set will be built only once and will never change (it is an immutable set).
I know I could use a red black tree, which has O(log n) search complexity. However, I’d like to investigate other algorithm options (and possibly with existing implementations in C#).
Simplest way would be (
O(N)) :if your list is already sorted then the cost is
O(LogN)