~
Educational Objectives: Understand and experience the implementation of the Stack ADT and its application in the depth first search algorithm. Analyze algorithm complexity.
Statement of Work:
Requirements:
This project contains two parts. In the first part, you will implement a Stack class template as an adaptor class. You have the freedom to use any C++/STL containers except the STL stack container. Note also that, you must not use the Vector class template you have implemented in Project 2: if you need to use the vector class, use the one provided in C++ STL. In the second part of this project, you will implement the depth first search algorithm. More specifically, you will design and implement a simulation that receives as input a rectangular 2-dimensional maze along with start and goal locations (as (row, col) coordinates) in the maze, and that produces a path (when one exists) through the maze from start to goal using depth-first search.
Task 1: Implement Stack as a generic adaptor class template
Stack interface (T is the template parameter, i.e., data type)
Analyzing the worst-case run-time complexity of the member function pop(). Give the complexity in the form of Big-O. Your analysis must be clearly understandable by others. Name the file containing the complexity analysis as "analysis.txt".
Task 2: Design and implement a simulation that simulates a rat pack finding food in a maze.
numrows numcols (first row of codes) (second row of codes) .... (last row of codes) start_row start_col goal_row goal_colFile data numrows and numcols are the number of rows and columns in the mazes, respectivelye. Hence, the maze contains numrows * numcols cells. After that, there are numrows rows of codes describing the maze. Each row contains numcols codes; each code entry is an integer code in the range [0 - 15]. The code is interpreted as giving the "walls" of the cell by looking at the binary representation, with 1's bit = North wall, 2's bit = East wall, 4's bit = South wall, and 8's bit = West wall. (Interpret "up" as North.) For example, code 13 means a cell with North, South, and West walls but no East wall, because 13 = 8 + 4 + 1 = 1101(bin) (no 2's bit). start_row, start_col, goal_row, and goal_col give the starting and ending cell coordinates. Cell coordinates are numbered consecutively from left to right and top to bottom. For example, the left-top corner of the maze is cell (0, 0), and the right-bottom corner is cell (numrows-1, numcols-1). See the example maze files given in the project release for more details. An example maze description and the corresponding maze is as follows.
4 5 9 1 1 1 3 8 0 0 0 2 8 0 0 0 2 12 4 4 4 6 _ _ _ _ _ | | | | | | |_ _ _ _ _|
Downloads:
Click here to download the provided tar file, which contains test_stack.cpp, sample executables test_stack.x, maze.x and maze_extra.x and some pre-made mazes files (maze0, maze1, etc). The sample executables were compiled on a linprog machine.
To run test_stack.x, do './test_stack.x'. To run maze.x, do './maze.x < maze0'.
Deliverables:
For Part 1, turn in all your source program files (Stack.h and Stack.hpp), makefile (to produce executable test_stack.x) and analysis.txt in a tar file via the Canvas system. It is due October 20, 11.59pm.
For part 2, turn in all your source program files (Stack.h, Stack.hpp, and proj3.cpp) and makefile (to produce executable proj3.x) in a tar file via the Canvas system. It is due October 27, 11:59pm.
Grading:
Part 1 (50 points):