I know that a SortedSet in C# is a Red-Black tree. My problem involves adding an element to the SortedSet and getting the lowest element greater than the one just inserted. This should take time O(log n). Yet, I couldn't figure out a way to do it without using the method GetViewBetween, which is linear.
How to find the least element greater than a given value on a C# SortedSet?
394 Views Asked by Seno At
2
Would be good if you'd have provided your approach with
GetViewBetween. Why it didn't work? It should, even if i'm not sure complexity:Note that the
GetViewBetweenreturns aSortedSetbut without copying all elements. It just uses the original set as reference, stores the min- and max-values and determines the current root element(so the one you search).Edit: It should be O(log n) now.