Notice that there are a couple of minor changes from the algorithm discussed in class. Why is this better?
Search the array a[0,..,N-1] for the element s value.
Procedure LSearch ( array Array, int i, int M, value Search )
if ( i > M )
return not found
if ( Array[i] = Search )
return found at i
LSearch ( Array, i + 1, Search )
LSearch ( a, 0, N - 1, s value )
using namespace std;
int reclinsearch(int a, int left, int right, int target)
if (left > right)
return -1; //not found, since we iterated through the entire array recursively and incremented left
if (a[left] == target) //if found retain position
By purchasing this solution you'll be able to access the following files:
Solution.docx and Solution.zip.