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:

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

  1. 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.)
  2. Develop and thoroughly test six generic algorithms as specified below.
  3. Turn in one file rbsearch.h containing both the declaration and implementation of your algorithms using the hw3submit.sh submit script.
  4. 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

  1. 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.
  2. All of the algorithms should be in the namespace alt.
  3. 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.)
  4. Test your algorithms in each of these cases:
    1. Range from begin to end in a fsu::TVector object with default ordering.
    2. Range from begin to end in a fsu::TVector object with reverse ("greater than") ordering.
    3. Range from begin to end in a fsu::TDeque object with default ordering.
    4. Range from begin to end in a fsu::TDeque object with reverse ("greater than") ordering.
    5. Range from begin to end in an array with default ordering.
    6. Range from begin to end in an array with reverse ("greater than") ordering.
  5. Your submission will be assessed using a proprietary test harness. It is your responsibility to ensure correct behavior of your generic algorithms.

Hints