-2

I was asked this question recently and got stumped.

Fill in the blanks to write a recurrence relation called RecSearch find a specific value x in a list of size n. You may assume that the list in held in an array called A. Efficiency is not a concern. You must use recursion. The function should return an index (position) of the desired item. Do not make any assumptions about the nature of the list.

RecSearch(A,n,x) = _____ if _____ = _____        

                // _____ >= 1 (indexing from 1, but can also index from zero)

RecSearch(A,n,x) = _____ // otherwise 

1 Answers1

0
RecSearch(A,n,x) = n if A:n = x        

                // n >= 1 (indexing from 1, but can also index from zero)

RecSearch(A,n,x) = RecSearch(A, n-1, x) // otherwise 
eigenharsha
  • 1,518
  • 14
  • 30