



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




For programming assignment 4 you should write a program that identifies the strong com- ponents in a directed graph. The input to the program will be the adjacency matrix of a directed graph whose vertices are the integers 0, 1 ,... , n − 1. The program’s output should be the strong components of the input graph. The file containing the adjacency matrix will contain the number of vertices n on a line by itself, and for each vertex, a line with a list of n 0’s and 1’s. The ith value is 1 if there is an edge from the vertex to vertex i, and the value is 0 otherwise. For example, suppose we wanted to find the strong components for the graph show in figure 1. Then the input file should contain
4 0 1 0 0 0 0 1 0 1 0 0 0 1 0 1 0
0 1
3 2
Figure 1: G
0 1
3 2
Figure 2: Gr
The 4 is the number of vertices. The line “0 1 0 0” shows the edges from vertex 0. The line “0 0 1 0” shows the edges from vertex 1, etc. The format of the output can vary. One approach is to just list the vertices belonging to each strong component on a separate line. For the example above, the output might be something like
The strong components are 0 1 2 3
The order of the components and the order of the vertices within a component are unimpor- tant. So equivalent, correct output might be
The strong components are 3 2 1 0
2 Algorithm
The following algorithm can be used to find the strong components of a directed graph.
0, 1, 2 3
Figure 3: Reduced Graph
6 Extra Credit
In order to receive full credit your program only needs to print the vertex set for each strong component in the input graph. You can receive 10 points extra credit if your program also prints the reduced graph. Recollect that the vertices of the reduced graph are the strong components of the graph G, and there’s an edge joining the component W to the component U if there’s a cross-component edge from at least one vertex of W to a vertex of U. For example, the reduced graph of the graph shown in figure 1 is shown in figure 2. Your output of the reduced graph can either be an adjacency list or an adjacency matrix. However, it must be clear from your output what the vertices of the reduced graph are, i.e., which strong component of G corresponds to which vertex of the reduced graph.
7 Submitting your program
In order to submit your program you should copy all of your source files into a program subdirectory of your submit directory.
8 Due Date
In order to receive full credit, your program must be submitted electronically by 3:00 pm on Wednesday, May 4th, and you must turn in printouts of your source files by 6 pm on the 4th. You can receive half credit if you submit your program and turn in a print out after 3: pm Wednesday but before 3:00 pm Thursday. Programs submitted and printouts turned in later than 3:00 pm Thursday will receive no credit.
9 Grading
Correctness will be 70% of your grade. Does your program correctly implement the strong components algorithm using adjacency lists for internal storage? If your program uses adja- cency matrices instead of adjacency lists, your maximum possible score on correctness will be 55%. The following static features will be graded.
10 Collaboration
It is OK for you to discuss solutions to this program with your classmates. However, no collaboration should ever involve looking at one of your classmate’s source programs! It is usually extremely easy to determine that someone has copied a program, even when the individual doing the copying has changed identifiers and comments. If we discover that someone has copied a program, the authors of both programs will receive an F on the assignment. Repeat offenders will receive an F in the course and be referred to the dean for additional disciplinary action.