Professional Documents
Culture Documents
txt
graph is bipartite if its vertices can be partitioned into two disjoint subsets U and V such
that each edge connects a vertex from U to one from V. A bipartite graph is a complete
bipartite graph if every vertex in U is connected to every vertex in V. If U has n elements and
V has m, then we denote the resulting complete bipartite graph by Kn,m.
A complete graph with n vertices (denoted Kn) is a graph with n vertices in which each vertex
is connected to each of the others (with one edge between each pair of vertices). Here are the
first five
A circuit is a path which ends at the vertex it begins
A graph is connected if there is a path connecting every pair of vertices. A graph that is not
connected can be divided into connected components
A cut vertex is a vertex that if removed (along with all edges incident with it) produces a
graph with more connected components than the original graph
degree [graph]
The degree (or valence) of a vertex is the number of edge ends at that vertex. For example,
in this graph all of the vertices have degree three.
In a digraph (directed graph) the degree is usually divided into the in-degree and the
out-degree (whose sum is the degree of the vertex in the underlying undirected graph).
-1-
C:\Users\RAHUL\Documents\graph.txt
-2-
C:\Users\RAHUL\Documents\graph.txt
A weakly
connected graph is where the direction of the graph is ignored and the connectedness is defined
as if
the graph was undirected.
13.3.1 DFS Algorithm
Step 1: Initialization
a) Initialize Stack to empty
b) Mark all nodes as not visited
c) Push node 0 onto the stack and mark it as visited
Step 2: While (stack is not empty)
{
a) Pop value from stack
b) Push all nodes adjacent to popped node and which have not been visited as
yet onto the stack
c) Mark all pushed nodes as visited
}
13.3.2 BFS Algorithm
Step 1: Initialization
a) Initialize Queue to empty
d) Mark all nodes as not visited
e) Enque node 0 and mark it as visited
Step 2: While (queue is not empty)
{
Deque element from queue
d) Enque nodes adjacent to deque node and which have not been visited as yet onto
the queue
e) Mark all enqued nodes as visited
}
add distance vector for each node to find distance
add parent vector for each nod efor back travking to the parent
Topological Sort
Definition:
Ordering the vertices of a given directed acyclic graph (DAG), such that if there is a
path from v to u in G, then v appears before u in the ordering.
(Topological sort may result in more than one ordering)
Algorithm:
1. Call DFS to compute f[v]
2. As each vertex is finished, insert it into the front of a linked list
3. Return the linked list of the vertices
Time Complexity: O(V+E)
A digraph g is acyclic if and only if any DFS
forest of G yields no back edges.
becomes back edge detection by
Lemma 3!
The shortest path between two vertices is a path
with the shortest length (least number of edges).
-3-
C:\Users\RAHUL\Documents\graph.txt
41. A technique that picks the next adjacent unvisited vertex until reaching a vertex that has
no unvisited adjacent vertices is ________
a. Breadth-first search
b. Depth-first search
c. Adjacency matrix
d. Adjacency list
Ans. b
42. Consider the graph represented by the following adjacency list:
1: 236
2: 513
3: 21756
4: 57
5: 2436
6: 351
7: 34
Perform a Breadth First Search in the graph starting from node 1 and processing the
edges adjacent to a node in the order they appear in the adjacency list.
What is the order in which the nodes are visited?
-4-
C:\Users\RAHUL\Documents\graph.txt
a) 1,2,3,6,4,7,5
b) 1,2,3,6,7,5,4
c) 1,2,3,6,5,4,7
d) 1,2,3,6,5,7,4
e) 1,2,3,6,7,4,5
Ans. d
44. If you perform a Depth First Search in a binary tree, what traversal will you obtain?
a) pre-order
b) in-order
c) post-order
d) Eulerian
Ans. a
36. A structure for representing a graph in which the presence of arcs between nodes is is
indicated by an entry in a matrix is ________
a. Breadth-first search
b. Depth-first search
c. Adjacency matrix
d. Adjacency list
Ans. c
37. A structure for representing a graph in which the arcs are stored as lists of connections
between nodes is ________
a. Breadth-first search
b. Depth-first search
c. Adjacency matrix
d. Adjacency list
Ans. d
38. The amount of space required to store an adjacency-matrix is ____ where V is a vertex set
whose elements are vertices.
a. O(V)
b. O(V+E)
c. O(V)
d. O(V*E)
Ans. c
39. Any edge in an adjacency matrix representation can be accessed,added or removed in ______
time.
a. O(V)
b. O(1)
c. O(E)
d. O(V)
Ans. b
40. For sparse graphs,the amount of memory required to store an adjacency list is ______
a. O(V)
b. O(V)
c. O(V+E)
d. O(V*E)
Ans. c
-5-
C:\Users\RAHUL\Documents\graph.txt
-6-