Re:Puzzle: LgN algorithm for Index == Value
by dangoldin on Saturday April 11, 2009 @11:23PM
(#558117)
Given that the list is sorted you can just modify the basic binary search to do what your want. Choose the middle and then compare the index with the value - depending on the relationship look to the left or right and repeat.
/* use 0-based indice*/ int lowerBound = 0; int upperBound = v.size() - 1;
while(1){