CSCI 151 - Data Structures and Object-Oriented Development
Spring 2015
Lab 12: Mazes, part 1: Heaps
- For this lab, we will implement a heap for storing maze paths.
- Download the provided code.
- Create a new Java project, into which the provided code will be placed.
- The code includes the following files:
-
maze package
- PathHeap.java: Represents a heap for storing Path objects.
- This is the only file you will modify.
- Within the file, modify the following methods:
-
leftOf(), rightOf(), parentOf(): These methods should
calculate an appropriate array index, given their argument.
-
put(): Adds a Path to the heap, and then fixes
heap property violations.
-
remove(): Removes and returns the shortest-length
element of the heap, and then fixes heap property violations.
- Cell.java: Represents a grid location in a maze.
- Path.java: Represents a sequence of grid locations in a maze. These are the objects that the heap must organize.
- PathOrderer.java: Interface
for path orderings. Implemented by PathHeap; we will later add PathQueue
and PathStack.
- PathHeapTest.java: Unit
tests for PathHeap.
Grading
For a grade of A+, the code must not only work, it must also be demonstrably
O(log2 n) time for each put() and remove().
| Number of Unit Tests Passed | Grade |
| 4 | A |
| 3 | B |
| 2 | C |
| 1 | D |