Iterative/ recursive help

I need to write the iterative and recursive versions of a function that takes in two vectors a and b, both are vector<int>, and returns whether a is a sub-vector of b a is a sub-vector of b if we can find an exact copy of a in some contiguous block of elements of b. For example, [1 -2 5 3] is a sub-vector of [10 -2 1 -2 5 3 4 6 8], but it is not a sub-vector of [10 -2 1 -2 5 4 3 6 8].


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 / the iterative solution
bool iterative_sub_vector(vector<int>& a, vector<int> b)
{
    // your code goes here
}

/** 
 * the recurive solution, you CAN NOT call erase NOR copy many elements of 
 * b into a separate vector. The function prototyp is already a hint
 * the initial call is recursive_sub_vector(a, b, 0)
 */
bool recursive_sub_vector(vector<int>& a, vector<int> b, size_t k)
{
    // your code goes here
}
Topic archived. No new replies allowed.