Homework 3: Generic Recursive Binary Search
Binary search with a generic algorithm interface and a recursive implementation
Educational Objectives:
After completing this assignment, the student should be able to accomplish the
following:
-
Define the concept generic algorithm in terms of the algorithm interface.
-
Define the concepts of recursive implementation and iterative
implementation of (generic) algorithms.
- Define a generic algorithm interface for a given specific algorithm.
- Define the concept of divide and conquer algorithm.
- Provide a recursive implementation of a generic divide and conquer algorithm.
-
Define the concepts function class, predicate class,
function object, and predicate object.
- Use various function objects and predicate objects in client programs
- Use various function objects and predicate objects as arguments in generic algorithms
Operational Objectives:
Create generic algorithm interfaces for g_lower_bound, g_upper_bound, and
g_binary_search that operate on ranges determined by random access
iterators and an optional order predicate. Implement the first two as recursive
implementations and the third with a call to the first. Put these
algorithms in the alt namespace. Test all of your generic
algorithms using fsu::TVector, fsu::TDeque, and ordinary arrays, with and
without an order predicate.
Deliverables: One file rbsearch.h.
Procedural Requirements
- The official development/testing/assessment environment is
gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)
on the linprog machines. (Enter
"g++ -v" to see complete details of this environment.)
- Develop and thoroughly test six generic algorithms as specified below.
-
Turn in one file rbsearch.h containing both the declaration and
implementation of your algorithms using the hw3submit.sh submit script.
Warning: Submit scripts do not work on the program and
linprog servers. Use shell.cs.fsu.edu to submit this
assignment.
If you do not receive the second confirmation with the contents of your project, there has
been a malfunction.
Technical Requirements and Specifications
-
g_lower_bound, g_upper_bound, and
g_binary_search should each have a generic algorithm interface taking
three arguments: two iterators that specify a search range and a search value. A
fourth optional argument for each of these is a predicate object that specifies the
order in the search range.
-
All of the algorithms should be in the namespace alt.
-
All of the algorithms should be implemented either recursively or with a direct call
to another of the algorithms in your set. No loops should be used in any of the
implementations. (The 4-parameter versions of g_lower_bound and
g_upper_bound can be implemented recursively, and all others can be
implemented by making calls to one of these.)
- Test your algorithms in each of these cases:
- Range from begin to end in a fsu::TVector object with default
ordering.
- Range from begin to end in a fsu::TVector object with reverse
("greater than") ordering.
- Range from begin to end in a fsu::TDeque object with default
ordering.
- Range from begin to end in a fsu::TDeque object with reverse
("greater than") ordering.
- Range from begin to end in an array with default ordering.
- Range from begin to end in an array with reverse ("greater than") ordering.
-
Your submission will be assessed using a proprietary test harness.
It is your responsibility to ensure correct behavior of your generic algorithms.
Hints
-
A sample executable of a test harness is posted as LIB/area51/fgss.x.
- The various generic heap algorithms are located in
LIB/tcpp/gheap.h. These are useful models for the generic algorithm
interfaces in particular.
- One sample test source code is given in LIB/hw3/vtest.cpp.
This code calls generic heap sort, which makes data input more convenient, and
also illustrates a correct call to generic lower bound. You should modify this
code so that it tests on deques and arrays, as well as vectors, and also test
with the predicate object GT. (When you compile vtest as is, you will
get a warning that GT is unused.)
- Your submission will be assessed using a proprietary test harness that is
an elaboration of vtest.cpp.