Skip to content

Implementation of Depth First Search algorithm for a Directed Acyclic Graph, Connected Components and Topological Orderings using rbk/Graph.java.

License

Notifications You must be signed in to change notification settings

rahul1947/SP08-Depth-First-Search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Short Project SP08: Depth First Search

  1. Implementation of Depth First Search algorithm for a Graph, using rbk/Graph.java.
  2. Implementation of Connected Components for a DAG and it's vertices.
  3. Implementation of Topological Orderings using two methods DFS and inDegree Ordering.

Author

Date

  • October 28, 2018

Problems:

A. Team Task:

Problem 1. Implement topologicalOrdering1(). This is the DFS-based algorithm for finding the topological ordering of a directed acyclic graph.

Solution: DFS.java

B. Individual Tasks (optional):

Problem 2. Implement topologicalOrdering2(g). In this algorithm discussed in class, we keep removing nodes with no incoming edges.

Solution: DFS.java

Problem 3. Implement connectedComponents(). In this algorithm, use DFS to find the number of connected components of a given undirected graph. Each node gets a cno (component number). All nodes in the same connected component receive the same cno.

Solution: DFS.java

Sample Output: 
# SP08 - CONNECTED COMPONENTS AND TOPOLOGICAL ORDERINGS: 
____________________________________________________________
Graph: n: 10, m: 12, directed: true, Edge weights: false
1 :  (1,3) (1,8)
2 :  (2,4)
3 :  (3,2)
4 :  (4,7)
5 :  (5,10) (5,4)
6 :  (6,8) (6,10)
7 : 
8 :  (8,2) (8,5)
9 : 
10 :  (10,9)
____________________________________________________________
Number of connected components: 2
u	cno
1	1
2	1
3	1
4	1
5	1
6	2
7	1
8	1
9	1
10	1

Topological Ordering 1: 
6 1 8 5 10 9 3 2 4 7 

Topological Ordering 2: 
1 6 3 8 2 5 10 4 9 7 

About

Implementation of Depth First Search algorithm for a Directed Acyclic Graph, Connected Components and Topological Orderings using rbk/Graph.java.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages