-
Notifications
You must be signed in to change notification settings - Fork 8
34. Graph Theory
Madhav Anand edited this page May 11, 2021
·
3 revisions
Vertices/Nodes - Circles
Edges/Links - Arrows
- Directed Edge - One-way edge
- Undirected Edge - Two-way edge.
Representation
- Adjacency Matrix - 2D Array, A[i][j] = 1, if there is an edge from vertex i to vertex j
- Adjacency List - Each A[i] is list of nodes Xi reachable from i.
DFS
- Go deep enough.
- Traversals - Pre, Post, In - Order
- Implemented using stack
BFS
- Go Layer by layer.
- Directed Graph - Arrows are uni or bi-directional.
- Undirected Graph - Arrows are bi-directional only.
- Adjacent Vertices - Two vertices connected directly by an edge.
- Degree - Number of edges of a vertex.
- In-Degree - Number of incoming edges of a vertex.
- Out-Degree - Number of outgoing edges of a vertex.
- Path - Number of vertices come in the path of two given vertices.
- Connected Graph - Every vertex has a path.
- Disconnected Graph - There is one vertex that doesn't have a path.
- Connected Components - Each connected graph is the disconnected graph.
- Cycle - Path from a vertex to the same vertex.
- Cyclic Graph - Graph that contains a cycle. it can be disconnected graph also
- Acyclic Graph - Graph that doesn't contain a cycle.
- Tree - The tree is a connected acyclic graph.
- DAG(Directed Acyclic Graphs) - Directed + Acyclic
- Complete Graph - Each vertex is connected to every other vertex directly by an edge. nC2 = n(n-1)/2 = Edges
- Weighted Graph - Graph with weighted edges.