0% found this document useful (0 votes)
15 views1 page

BIL212 Fall 2020 HW3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

BIL212 Fall 2020 HW3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

BIL212 Data Structures

HW - 3
Assigned: 02.12.2020
Due: 10.12.2020
Submission: Will be announced on piazza.
Regulations: Late submissions are not allowed. Plagiarism is strictly forbidden, all that take part will be punished
according to the regulations of the university.

In this assignment you are going to implement breadth-first and depth-first traversals on graphs. You will use two different
representations for a graph: adjacency list and adjacency matrix. For these two representations you have to compute
the time it takes to traverse a given graph in breadth-first and depth-first order. As the output, you have to print the
traversals in addition to the duration of them. Other implementation details are up to you.
You will read the graph from a file in the following format. The file will include all the edges for a graph.

A - B
C - D
A - C
B - E
D - F
G - F
H - I

The labels of the nodes will be Strings and the edges given in each line of the file will always be in following format:

<node1><space>-<space><node2>

The filename and starting node of the traversals should be taken as a command line argument. Note that the given graph
does not have to be connected, therefore depending on the start node you may not be able to traverse all the nodes.
Child nodes should be traversed by alphabetical order.
An execution is given below for the above given file (graph.txt). The given durations are only given to specify the output
format. Their unit is up to you, as long as you output all in terms of the same unit (for example all can be milliseconds).
The runtime command will follow the following format. Your main class should be in a file called ”Traverse.java”.
java Traverse -txt file- -starting node- -BF (or -DF) -AL (or -AM)

--Input--
java Traverse graph.txt A -BF -AL

--Output--
Breadth-first : A - B - C - E - D - F - G
Time : 0.01

--Input--
java Traverse graph.txt A -BF -AM

--Output--
Breadth-first : A - B - C - E - D - F - G
Time : 0.03

--Input--
java Traverse graph.txt A -DF -AM

--Output--
Depth-first : A - B - E - C - D - F - G
Time : 0.03

--Input--
java Traverse graph.txt A -DF -AL

--Output--
Depth-first : A - B - E - C - D - F - G
Time : 0.05

You might also like