Instructions
Practice Problems
Problem 1: Binary Search
Problem 2: Dequeue for Strings
Problem 3: Parametrized Dequeue
Version: 5.3.0.10

Assignment 8

Goals: Practice working paramtrized types and using the ArrayList

Instructions

The names of the projects and some of the project files must be exactly the same as specified in the assignment. Failure to do so makes it impossible for the graders to run your submission and results in immediate loss of at least 50% of the homework credit.

Make sure you follow the style guidelines for code indentation.

You will submit this assignment by the deadline using the Web-CAT submission system.

With each homework you will also submit your log file named pairxxx.txt where you replace xxx with your pair number.

On top of every file you submit you will have the names of both partners, and the pair number.

The .txt file will be the log of your work on this assignment. Each log entry will have data and time, who was present (one or both of the partners) and a short comment decribing what you were working on.

Submission Details:

Due Date: Friday, March 15th, 10:00 pm.

Practice Problems

Work out these problems on your own. Save them in an electronic portfolio, so you can show them to your instructor, review them before the exam, use them as a reference when working on the homework assignments.

Problem 1: Binary Search

Start with a new project HW08Problem1 and create two files: Algorithms.java and ExamplesAlgorithms.java.

Problem 2: Dequeue for Strings

Create a project with the name HW08Problem2.

We would like to build a list in such a way that we can start either at the front, or at the back, and move through the list in either direction. In order to do so, we have decided on the structure to represent the following scenarios:

            +-------+

            | Deque |

            +-------+

            | node  |--+

            +-------+  |

                +------+

                |

                v

          +----------+

          | Sentinel |

          +----------+

          | ""       |

      +---| next     |

      |   | prev     |-----------------------------+

      |   +----------+                             |

      |                                            |

      v                                            v

+----------+   +----------+   +----------+   +----------+

| Node     |   | Node     |   | Node     |   | Node     |

+----------+   +----------+   +----------+   +----------+

| "abc"    |   | "bcd"    |   | "cde"    |   | "def"    |

| bcdnode  |-->| cdenode  |-->| defnode  |-->| sentinel |

| sentinel |<--| abcnode  |<--| bcdnode  |<--| cdenode  |

+----------+   +----------+   +----------+   +----------+

Every list has a header that consists of the Sentinel node. This node does not change, only its fields that provide the links to the first and the last item in the list can change.

Each node has two links, one to the next item in the list and one to the previous node in the list.

The Sentinel node is always present. It does not contain any useful data, i.e. the data field may be either null, or for the list of Strings the empty String. Its role is to provide the link to the head of the list and to the tail of the list.

The empty list has just one node, the Sentinel that contains no useful data, and its links to the first and to the last item just reference the Sentinel node itself.

The Deque is a wrapper class that contains one field, the Sentinel node for this list. So an empty list would have the following class diagram:

     +-------+

     | Deque |

     +-------+

     | node  |--+

     +-------+  |

+----+   +------+

|    |   |  +----+

|    |   |  |    |

|    v   v  v    |

|  +----------+  |

|  | Sentinel |  |

|  +----------+  |

|  | ""       |  |

+--| next     |  |

   | prev     |--+

   +----------+

Problem 3: Parametrized Dequeue

The data structure you have built in the previous problem is very useful, except for the fact that the data in the list can only be of the type String.

Create a project with the name HW08Problem3.

Import into it your solution to Problem 2.