0% found this document useful (0 votes)
26 views

E0 251: Programming Assignment 2: Due Date: Wednesday, November 16th

1. Implement depth first search using a stack to find the connected components of an undirected graph. The input file contains the adjacency list representation of the graph and the output file lists the vertices in each connected component. 2. Implement breadth first search using a queue to find the shortest path lengths from vertex 1 to all other vertices in an undirected graph. The input and output file formats are the same as for the connected components problem.

Uploaded by

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

E0 251: Programming Assignment 2: Due Date: Wednesday, November 16th

1. Implement depth first search using a stack to find the connected components of an undirected graph. The input file contains the adjacency list representation of the graph and the output file lists the vertices in each connected component. 2. Implement breadth first search using a queue to find the shortest path lengths from vertex 1 to all other vertices in an undirected graph. The input and output file formats are the same as for the connected components problem.

Uploaded by

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

E0 251: Programming Assignment 2

Due Date: Wednesday, November 16th

You are expected to solve the assignment on your own.

1. Given an undirected graph G, find the connected components of G using


depth first search.
Note: You must implement depth first search as a iterative program using
a stack. Recursive depth first search is not allowed.
Implement the stack as a linked list.
2. Given an undirected graph G, find the shortest path length from vertex
numbered 1 to all other vertices in G using breadth first search.
Note: You must implement breadth first search using queue. Implement
the queue as a linked list.

NOTE:

Program can be in C, C++ or Java


No standard libraries (eg. STL in C++) can be used except for reading
input and writing output.
Your program must take the input from a file input and output the
solution to a file output.
The input file gives the undirected graph G in the following format (Ad-
jacency list): The first line gives the number of vertices n of G. Let the
vertices of G be numbered as 1, 2, . . . , n. The following lines of input file
gives the list of vertices adjacent to each vertex. For example, the second
line has a list of numbers separated by space that indicates the vertices
that have edges to vertex numbered 1. The third line has vertices that
have edges to vertex numbered 2 and so on.
For the connected component problem, the output file has the format:
The list of vertices (separated by space) in component 1 in first line, list
of vertices in component 2 in second line and so on.
For the shortest path problem, the output file has the format: The list of
vertices (separated by space) that has shortest path length 1 from vertex
numbered 1 in first line, list of vertices that has shortest path length 2
from vertex numbered 1 in second line and so on.

You might also like