Graphs Flashcards
What is Bipartite graph ?
Whose vertices can be split into two independent groups U,V such that every edge connects between U and V
What is complete graph?
Where there is a unique edge between every pair of nodes.
Three ways of representing the graph?
- Adjacency Matrix
- Adjacency List
- Edge List
Which graph representation type is space efficient for
representing dense graphs?
Adjacency Matrix
Bridges in the graph?
A bridge/cut edge is any edge in a graph whose removal increases the number of connected components.
Articulation points in graph?
Articulation points/cut vertex is any node in the graph whose removal increases the number of connected components.
Time complexity of DFS on graph?
O(V+E) where V is number of vertices and E is the number of edges
Pseudo code for DFS on graphs?
# Global or class scope variables n=number of nodes in the graph g=adjacency list representation of graph visited=[false,.....false]# size n
function dfs(at): if visited[at]: return; visited[at]=true; neighbors=graph[at] for next in neighbors: dfs(next)
# start DFS at node zero start_node=0; dfs(start_node)
What is the time complexity of BFS on graph?
O(V+E)
V is number of vertices
E is the number of edges
Algorithm to find shortest path on unweighted directed/undirected graphs?
BFS(Breadth first search)
Pseudo code for BFS on graphs?
function BFS(s) q=queue data structure with enqueue and dequeue q.enqueue(s)
visited=[false,.....,false] # size n visited[s]=true; while !q.IsEmpty(): node=q.dequeue(); neighbors=g.get(node)
for(next: neighbors):
if !visited[next]:
q.Enqueue(next)
visited[next]=true;
What are Directed Acyclic Graphs?
DAGs are directed graphs with no cycles.
Which graph representation is space efficient for representing sparse graphs ?
Adjacency List
Pseudo-code for DFS on graph
# Global or class scope variables n = number of nodes in the graph g = adjacency list representing graph visited = [false, …, false] # size n function dfs(at): if visited[at]: return visited[at] = true neighbours = graph[at] for next in neighbours: dfs(next) # Start DFS at node zero start_node = 0 dfs(start_node)
What is spanning tree?
https://www.ics.uci.edu/~eppstein/161/960206.html
A spanning tree of a graph is just a subgraph that contains all the vertices and is a tree. A graph may have many spanning trees; for instance the complete graph on four vertices