Resistant dichotomic search P33412


Statement
 

pdf   zip   main.cc

Write an efficient function

    bool resistant_search(double x, const vector<double>& v);

that tells if @x@ belongs to the vector @v@ or not.

Precondition

The vector @v@ is “almost sorted” in nondecreasing order, in the sense that there may be at most a pair of indices ii and jj such that 0i<j<n0 \le i < j < n and @V@[ii] >> @V@[jj].

Observation

You only need to submit the required procedure; your main program will be ignored.

Information
Author
Salvador Roura
Language
English
Official solutions
C++
User solutions
C++