You are on page 1of 2

DSA - Assignment 2

Simple Graph

Creating a default graph which is represented by adjacency matrix (Code is provided in


DemoGraph.java which is sent with this document). Then, complete the following tasks:

Task 1 (3 marks): Do breadth first search to traverse through all vertices.


With the given data (Graph_01), the output must be as follows.
A, B, C, D, E, F
Task 2 (3 marks): Do depth first search to traverse through all vertices
With the given data (Graph_01), the output must be as follows.
A, B, D, E, C, F
Task 3 (1 mark): Cycle detection
With the given data (Graph_01), the output must be as follows.
Having cycle
With the given data (Graph_02), the output must be as follows.
No cycle
Task 4 (1 mark): Check for connectivity
With the given data (Graph_01), the output must be as follows.
Connected graph
With the given data (Graph_02), the output must be as follows.
Unconnected graph
Task 5 (1 mark): Determine the Minimum Spanning Tree and display all of its edges by Kruskal
algorithm.
With the given data (Graph_03), the output must contain all following edges.
(A,B) (A,C) (C,F) (F,D) (F,G) (G,E)
Task 6 (1 mark): Determine the shortest path from A to each of the others vertices.
With the given data (Graph_03), the output should be something as follows.
A-B 6: A, B
A-C 5: A, C
A-D 21: A, C, D
A-E 19: A, B, E
A-F 17: A, C, F
A-G 20: A, C, F, G

Notes: The sample graphs are provided in the next page.


Sample graphs
A
A F
F B
B
E
E C
C
D
D

Graph_01 Graph_02

Graph_03

Submission Requirements
Create the directory with a name like <class>-<name><roll number>-ASS1, e.g.
SE0508-QuangTV00456-AS1 (1)
The (1) directory contains the following files:

1. The run.bat file to run your program.


2. Your source code files.
3. Your input test files.

The statements in run.bat file may be:


javac *.java
java Main
pause
Compress the folder (1) to .zip (or .rar) file (with the same name) and upload to cms.

Assignment assessment
You will be asked to modify immediately and to explain your assignment in lab room to be sure
that you are really the author of the assignment you submitted.

You might also like