HW 7

1 Theory

  1. 5.20 (from text)
  2. Consider an undirected graph G = (V,E) with n = |V| and m = |E|. The degree of a vertex is the number of edges incident on that vertex. Let di be the degree of vertex vi, Show that
    SUM[1..n]( di ) = 2m
  3. In a directed graph, we can talk about in-degree and out-degree, the number of edges, respectively, arriving and leaving a given vertex. Show that the sum of the in-degrees of a graph is equal to the sum of the out-degrees.
  4. 6.1 (from text).

2 Implementation

  1. (Makefile target: prob1) Implement a disjoint set system using a tree representation (use references, or a parent array). In particular, you should implement an Initialize() function that creates n one-element sets given an array of n things, as well as the functions Find() and Merge(). Implement the better version of disjoint sets (where smaller sets parent to larger sets and finds implement path compression).

    You are to provide the file set.py. The program to run is provided, test-set.py.

    Advance warning: You might be asked to use your disjoint set system in your homework two weeks from now.

  2. (Extra Credit – 20%) (Makefile target: prob2) Implement BFS and DFS.

    Provide some nice graph, 7-10 nodes, fairly dense. We gotta show you guys DOT one of these days. Anyway, just output the transitions, or the adjacency list. Then show us each of the spanning trees.

    Provide another target called prob2-view that displays your source code in a pager (like less) on stdout.