Homework 2

Due Friday, September 29
5 points.


You can submit this assignment electronically through WebDrop. To do this, save a copy of the source for this web page and edit it. Comments in the source indicate how to make the editing changes.

  1. (2 points) Trace a minimal spanning tree search on the following graph, starting at vertex "A".

    Entries in the "Visited Vertex" column should have the form name. Entries in the "Added Edges" column should have the form name:edge-length. Circle edges that are visited and cross out edges that are discarded.

    Visited Vertex Added Edges
    A AB:4 AC:3 AD:6
  2. (2 points) Trace a single source shortest paths search on the following graph, starting at vertex "A".

    Entries in the "Visited Vertex" column should have the form name:shortest-path-distance. Entries in the "Added Edges" column should have the form name:edge-length:to-vertex-distance. Circle edges that are visited and cross out edges that are discarded.

    Visited Vertex Added Edges
    A:0 AB:4:4 AC:3:3 AD:6:6
  3. (1 point) Consider the following search loop:

        do whatever you need to do with v
        record that v has been visited
        put the edges leaving v into the dispenser
        while the dispenser is not empty
            retrieve and remove edge e from the dispenser
            let w be the head of e
            if w has not been visited
                do whatever you need to do with e
                do whatever you need to do with w
                record that w has been visited
                put the edges leaving w into the dispenser
            endif
        endwhile
            

    Fill in the dispenser types and run times in the following table. Assume that "do whatever you need to do with …" is constant time for either vertices or edges and recording that a vertex has been visited is also constant time.

    Graph Search Type Dispenser Type Run Time
    Breadth-First Search
    Depth-First Search
    Minimal Spanning Tree
    Single Source Shortest Paths