Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

Assignment - Graph

Uploaded by

kireetiv2005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Assignment - Graph

Uploaded by

kireetiv2005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Graph Algorithms

Problems for Practice


To be submitted as an assignment on 20th January 2025

Instructions:
a. Assignment Deadline: 20th January 2025, 10:30AM. Assignments will NOT be
accepted after the mentioned time.
b. Assignment to be handwritten on A4 sheets and stapled together with a front sheet having
the name and complete roll number of the student.
c. Class representatives to collect & submit the assignment at the desk of the corresponding
faculty by 20th January 2025, 10:40AM. Assignments will NOT be accepted after the
mentioned time.
d. Students must submit the assignments to the respective class representatives before the
deadline. The representatives will NOT wait for the students to submit beyond the
deadline.
e. Every sheet of the assignment should have a margin on the top and left side.
f. The question numbers should be to the left of the margin (i.e. outside) and the answers
should be inside the margin (i.e. the right side)

Questions:
1. Find all the biconnected components of this graph using DFS method.

2. Give an O(V + E) time algorithm that, given a directed graph G = (V, E) constructs
another graph G’ = (V, E’) such that G and G’ have the same strongly connected
components, G’ has the same component graph as G , and |E’ | is as small as possible.
3. Imagine a city with various intersections (vertices) connected by roads (edges). You are
tasked with determining how many different routes (simple paths) exist from a starting
intersection (source A) to a destination intersection P, where a simple path is defined as a
path that does not revisit any intersection. The city’s road map is represented using an
adjacency matrix where each cell indicates whether two intersections are directly
connected by a road. Provide the correctness and analyze the time complexity of the
algorithm.

4. Let G be a directed graph represented by the adjacency matrix A. In directed graphs: A(u,
v) = 1 if (u → v) exists and A(u, v) = 0 otherwise. A tournament is a directed graph such
that for any pair u ̸= v exactly one of (u → v) or (v → u) exists. An acyclic tournament is
a tournament with no cycles. A source is a vertex whose in-degree is zero. A destination
is a vertex whose out-degree is zero. Describe an algorithm that checks if a directed graph
G is a tournament. What is the complexity of your algorithm? Explain.

5. How can the number of strongly connected components of a graph change if a new edge
is added? Justify your answer.

6. Let P be the shortest path from vertex s to some other vertex t in the graph. If the weight
of each edge in the graph is increased by one, does P remain the shortest path from s to t?
Justify your answer.

7. Let G be an undirected graph with n vertices and m edges. Describe an O(n + m)-time
algorithm to determine whether G contains at least two cycles.

8. Give a linear-time algorithm that takes as input a directed acyclic graph and two vertices
u and v, and returns the number of paths from u to v in the DAG. (Note that your
algorithm needs to count the paths, not list them.)

9. Write an algorithm to find a minimum spanning tree in O(n) time for a connected, weighted
graph with n vertices and exactly n edges.

10. Calculate the shortest path from source A to all the other vertices of the following graphs.
Also identify which algorithm would be most suited for each of the graphs. Justify your
answer appropriately for each of the graphs.
a.

b.

c.
11. The following matrix represents a directed graph over vertices a,b,c,d,e,f,g,h,i,j,k,ℓ. Rows
and columns represent the source and destination of edges, respectively.

a. Draw the graph and the DFS numbering of the vertexes using the DFS algorithm.
Every iteration through vertexes or adjacent edges is performed in alphabetic order.

b. Sort the vertices in a topological order using the depth-first search algorithm. Justify
your answer by showing the relevant data maintained by the depth-first search
algorithm, and by explaining how that can be used to produce a topological order.

12. Consider the following undirected, weighted graph, and Step through a* and Dijkstra’s
algorithm to calculate the shortest paths from A to every other vertex. Also compare the
working of both algorithms with appropriate complexity analyses.
13. Communication between various relief centers and hospitals is disrupted in a disaster-
struck city. The city’s road network is represented as an undirected graph, where nodes
represent locations and edges represent roads. Some locations are disconnected due to
damaged roads.
(i) Design an efficient algorithm to determine the smallest number of new roads
(edges) required to reconnect the network to reach all locations.
(ii) Analyze the running time of your algorithm step-by-step, and compute the worst-
case time complexity.
(iii) Proof the correctness of the algorithm by demonstrating that the solution guarantees
minimal new edges while reconnecting all components.

14. Adapt Dijkstra's algorithm to achieve the following objectives:


(i) For a directed graph, develop a modified version of Dijkstra's algorithm to compute the
shortest directed paths from a given source vertex to all other vertices in the graph.
(ii) Extend the modified Dijkstra's algorithm to not only compute the shortest distances
from the source vertex v to each vertex in the graph G but also construct a tree T rooted
at v. The tree T should ensure that the path from v to any vertex u in T corresponds to
the shortest path in G from v to u.

15. Consider an undirected graph G with n vertices and m edges. Prove the following
properties:
(i) If G is connected, then m ≥ n-1
(ii) If G is a tree, then m = n-1

16. As a reward for your heroic act in saving the Kingdom of Bigfunnia from the evil
monster, "Exponential Asymptotic," the king offers you an opportunity to earn a
significant prize. Behind the castle, there is a maze, with gold bags placed along its
corridors. The amount of gold in each bag varies, and your task is to navigate the maze,
collecting the bags of gold. You may enter the maze through the "ENTER" door and exit
through the "EXIT" door. However, you can only proceed along corridors in the direction
indicated by arrows, and you cannot retrace your steps. The maze contains no loops,
ensuring that you cannot revisit any corridor once traversed.
You will be provided with a map that details the gold in each bag and the direction of each
corridor. Your objective is to design an efficient algorithm to maximize the amount of
gold you collect as you navigate from the entrance to the exit. Also calculate the
asymptotic time complexity required by your algorithm and justify that it is indeed efficient.

You might also like