HW6

Due Date: Mar 18, before midnight (11:59:59PM)

This assignment comprises both written questions and implementation-based lab.

HW6

Answer the following questions from the DPV book i) Q3.4 ii) Q3.6, iii) Q3.9., iv) Q3.11.

Lab6: Strongly Connected Components

Implement the strongly connected components algorithm described on page 94 in the book. You'll have to increase the recursion limit to make this work for the graphs below. You are only allowed to use basic python data structures (e.g., dict, set, list), and should not use any graph packages (e.g., networkx, igraph, etc.).

You should run your code on these two graphs: graph1 and graph2. These files list out all the directed edges, one per line.

Your code must print the SCCs in decreasing order of length. Also, for two SCCs with the same number of nodes, the one with a lower id vertex (i.e., lexicographically smaller) should come first. These SCCs must therefore be numbered from 0 to M-1 (which will denote the SCC_IDs), where M is the number of SCCs. Print them out in the following format:

SCC_ID LEN SET_OF_NODES_IN_SCC(in sorted order)


Once you have printed the SCCs, you must also print the edges that comprise the DAG structure over the SCCs. The edges must be printed in sorted order (in increasing order). The edges will use the SCC_IDs from above to denote the DAG nodes. Use the following format:

NUM_DAG_NODES NUM_DAG_EDGES
EDGES (one per line in sorted order of source)


Bonus: Implement a non-recursive version of dfs method to handle large graphs, and test it on graph3

Submit the output on the bonus graph. However, given the large size of the graph, just print the SCCs lengths in decreasing order, and the DAG number of nodes and edges.