Reputation: 3
Lets say we have a OrderedList with int years in it.I have to find the years between year i and year n, but im having trouble finding the nearest element bigger than year i.I need something faster than linear algorithm complexity (O(n)).
Upvotes: 0
Views: 18
Reputation: 6276
(Guessing you mean sorted list by ordered list, since ordered list wouldn't make much sense here. Otherwise sort that list before searching.)
Try binary search. What you do is the following:
Upvotes: 1