Practice: Graph traversal

This exercise is for your own practice, not to be turned in. This is recommended for your study to test yourself that you are able to reconstruct the solution to graph traversal algorithms from class and the book

1. Introduction

The goal of this project is to understand how graph traversal works: iterative breadth first, iterative depth first, and recursive depth first. For each of these, we package the algorithm both as an iterator (or "external iterator" to use the terminology in the Design Patterns book) and as a stand-alone algorithm (or "internal iterator").

2. Set up

Find the code at

/homes/tvandrun/Public/cs345/graph-practice

The code contains packages adt, alg, impl and test. The classes you will be completing are in alg.

The classes BreadthFirstTraversal, DepthFirstTraversal, and DepthFirstTraveralRecursive all implement the Traversal interface. It has three signatures:

Breadth first traversal

Finish the methods internal() and external() in alg.BreadthFirstTraversal. Some code to initialize structures is given for you. Test using BFTALTest and BFTAMTest, which test BFT on adjacency-list and adjacency-matrix implementations.

Depth first traversal, iterative

Do similarly for alg.DepthFirstTraversal. Test using DFTALTest and DFTAMTest. Unfortunately, these also test the recursive version, so ignore those unit tests for now.

Depth first traversal, recursive

Do similarly for alg.DepthFirstTraversalRecursive, but only for internal(), and, more specifically, you need only to write the helper method internalR(), which does the actual recursion. The method internal() sets things up and starts the recursive process going by making the initial call to internalR(). Test using the remaining unit tests in DFTALTest and DFTAMTest. (Sorry the test cases aren't organized conveniently.)

There is nothing to be turned in.


Thomas VanDrunen
Last modified: Mon Feb 5 10:23:25 CST 2018