CSSE 220: Recursion in search
In this exercise, you will learn about recursion by writing several
recursive search methods, and by comparing and contrasting them to
iterative search methods.
- Download the RecursiveSearch
project.
- Write an iterative method called linearSearchIteratively
which iterates through the array passed to it in a linear
fashion. This method returns the index of the element in the array or
-1 if the element does not appear in the array.
- Write a recursive method called linearSearchRecursively
which uses recursion to linearly search through the array passed to
it. This method returns the index of the element in the array or -1 if
the element does not appear in the array. In your code, identify the
base case, the recursive case, and where in the code you make progress
towards the base case.
- Write an iterative method called
binarySearchIteratively which iterates through the array passed
to it in a binary fashion. This method returns the index of the
element in the array or -1 if the element does not appear in the
array.
- Write a recursive method called binarySearchRecursively
which uses recursion to implement binary search on the array passed to
it. This method returns the index of the element in the array or -1 if
the element does not appear in the array. In your code, identify the
base case, the recursive case, and where in the code you make progress
towards the base case.