0% found this document useful (0 votes)
37 views4 pages

CS5200 Homework 3: Graph Algorithms

Uploaded by

giduthurimanu124
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)
37 views4 pages

CS5200 Homework 3: Graph Algorithms

Uploaded by

giduthurimanu124
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

CS5200 Homework – 3

(Deadline: 11-10-2023 11:59pm)


Instructor: Huiyuan Yang

q Theory questions [50%] :


Q1.[10%] Design an algorithm to automatically indicate whether or not a graph 𝐺 contain a cycle. Using
the following graph as example to show how your algorithm will run in the graph.

Q2. [10%] Apply Depth-First-Search (DFS) algorithm to the following graph. Show the graph after the
{Forward edge (F), Cross edge (C) and Back edge (B)} are labeled at the first time, and also the discovery
time and finishing time in graphs. (Note that you don’t need to show the graph when Tree edges (T) are
labeled at the first time. Assume starting from node-1 and go to node-2 first).
Q3: [15%] Run Kruskal’s algorithm and Prim’s algorithm to the following graph, and show the edges by
their adding orders. (Note that, assume a is the root for Prim’s algorithm)

Q4.[15%] We can model a maze by having a vertex for a starting point, a finishing point, dead ends and
all the points in the maze where more than one path can be taken, and then connecting the vertices
according to the paths in the maze.

§ Construct such a graph for the following maze.


§ Which traversal (DFS vs. BFS) is better to find a path from the starting point to the finishing point
and why?
q Programming [45%]

I. Strongly Connected Components [20%]


§ Given a directed graph, implementing the algorithm we discussed during class
to find out the strongly connected components.
§ Print out the number of strongly connected components and the vertices in
each component.

II. Dijkstra Algorithm [25%]


Implementing the Dijkstra algorithm with two types of queues.

§ Use an array to implement the Q;


§ Use a binary heap to implement the Q
§ Output the corresponding paths and running time.

Note that, the graph is given by using adjacency-matrix representation, where 0: no edge; ≥ 1: weight
for the edge. For example:

(one example of the provided input file)

q Bonus: [Extra 20%]

[Bonus-1] A bipartite graph 𝐺(𝑉, 𝐸) is an undirected graph whose vertices can be partitioned into two
disjoint sets 𝑉! and 𝑉" , and 𝑉! ∪ 𝑉" = 𝑉. A bipartite graph has the properties:

§ for any two vertices 𝑣! 𝑎𝑛𝑑 𝑣" ∈ 𝑉# 𝑖 = {1, 2}, there is no direct edge connecting them.
§ For any edge 𝑒(𝑢, 𝑣) ∈ 𝐸, 𝑢, 𝑣 are in different partition. For example, we have either 𝑢 ∈
𝑉! 𝑎𝑛𝑑 𝑣 ∈ 𝑉" or 𝑢 ∈ 𝑉" 𝑎𝑛𝑑 𝑣 ∈ 𝑉! .

Is the following graph G a bipartite graph? Write your algorithm to determine whether the graph 𝐺 is
bipartite and the two disjoint sets 𝑉! and 𝑉" if it is a bipartite graph.[12%]
[Bonus-2] The square of a directed graph 𝐺(𝑉, 𝐸) is the graph 𝐺 " = (𝑉, 𝐸 " ) such that:

§ (𝑢, 𝑤) ∈ 𝐸 " if and only if for some 𝑢, 𝑣, 𝑤 ∈ 𝑉, both (𝑢, 𝑣) ∈ 𝐸 𝑎𝑛𝑑 (𝑣, 𝑤) ∈ 𝐸.

That is, 𝐺 " contains an edge between 𝑢 and 𝑤 whenever 𝐺 contains a path with exactly two edges
between 𝑢 and 𝑤.

Describe an efficient algorithm for computing 𝐺 " from 𝐺 for the adjacency-matrix representation of G.
Given the running time of your algorithm. [8%]

q Submission requirements: [5%]

Put the theory part and code into a folder with the name: [YourStudentID-YourName-HW*].zip
§ Following all the submission requirements [5%]
§ Theory part:
o You solution should be clear, concise but also contain enough details.
o Only PDF format is allowed.
o Please make sure the scanned PDF file is high-resolution and easily readable if you wrote
your solution on paper.
§ Programming part:
o A sanity check to test the correctness of your algorithm.
o Your program will read an input file and write an output file.
o Your program will be called like this: prompt>./hw* ./[Link]. ./[Link]
o Your code should be complied by calling the makefile.

You might also like