You are on page 1of 6

C:\Users\RAHUL\Documents\graph.

txt

Tuesday, January 18, 2011 7:16 PM

A graph is regular if every vertex has the same degree.


A path is a route that you travel along edges and through vertices in a graph.
All of the vertices and edges in a path are connected to one another.
A cycle is a path which begins and ends on the same vertex. A cycle is sometimes called a
circuit.
The number of edges in a path or a cycle is called the length of the path.
A hamiltonian path in a graph is a path that passes through every vertex in the graph exactly
once.
A hamiltonain path does not necessarily pass through all the edges of the graph, however.
A hamiltonian path which ends in the same place in which it began is called a hamiltonian
circuit or a hamiltonain cycle.
An eulerian path in a graph is a path that travels along every edge of the graph exactly once.
An eulerian path might pass through individual vertices of the graph more than once.
An eulerian path which begins and ends in the same place is called an eulerian circuit or an
eulerian cycle
A planar graph is a graph that can be drawn so that the edges
meet at vertices.

only touch each other where they

A planar graph is a graph that can be drawn so that the edges


meet at vertices.

only touch each other where they

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

Tuesday, January 18, 2011 7:16 PM

Four Color Theorem


Every planar graph can be colored using no more than four colors.
digraph [GRAPH]
A digraph (or a directed graph) is a graph in which the edges are directed
The in-degree of a vertex v is the number of edges with v as their terminal vertex.
isolated
A vertex of degree zero (with no edges connected) is isolated.
Two graphs are isomorphic if you can re-draw one of them so that it looks exactly like the
other.
The diameter of a graph is the longest distance you can find between two vertices.
Distance matrix
A symmetric n by n matrix D whose element dx,y is the length of a shortest path between x
and y; if there is no such path dx,y = infinity. It can be derived from powers of A
Adjacency matrix
This is an n by n matrix A, where n is the number of vertices in the graph. If there is an edge
from a vertex x to a vertex y, then the element ax,y is 1 (or in general the number of xy
edges), otherwise it is 0. In computing, this matrix makes it easy to find subgraphs, and to
reverse a directed graph.
Adjacency list
Much like the incidence list, each vertex has a list of which vertices it is adjacent to.
This causes redundancy in an undirected graph: for example, if vertices A and B are adjacent,
A's adjacency list contains B, while B's list contains A. Adjacency queries are faster, at the
cost of extra storage space.
[edit] Matrix structures
Incidence matrix
The graph is represented by a matrix of size |V | (number of vertices) by |E| (number of
edges) where the entry [vertex, edge] contains the edge's endpoint data (simplest case: 1 incident, 0 - not incident).
A minimum vertex cover is a vertex cover of smallest possible size. The vertex cover number
t is the size of a minimum vertex cover.
a vertex cover of a graph is a set of vertices such that each edge of the graph is incident
to at least one vertex of the set. The problem of finding a minimum vertex cover is a classical
optimization problem in computer science and is a typical example of an NP-hard optimization
problem that has an approximation algorithm. Its decision version, the vertex cover problem
A strongly connected graph is one in which for all pairs of vertices, both vertices are
reachable from
the other. A strongly connected graph is a directed graph that has a path from each vertex
to every other
vertex. In other words formally a strongly connected graph can be defined as a directed graph
D=(V, E)
such that for all pairs of vertices u, v V, there is a path from u to v and from v to u.

-2-

C:\Users\RAHUL\Documents\graph.txt

Tuesday, January 18, 2011 7:16 PM

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

Tuesday, January 18, 2011 7:16 PM

Call this the link-distance.


Breadth-?rst-search is an algorithmfor ?nding shortest (link-distance) paths from a single source vertex to all other vertices.
BFS processes vertices in increasing order of their
distance from the root vertex.
BFS has running time (V+E)
Construct the shortest path tree edge by edge; at
each step adding one new edge, corresponding
to construction of shortest path to the current new
vertex.
a) A tree with n nodes has n-1 edges
b) Dijkstra does not work if some weights are negative
c) BSF finds whether a graph is connected
Depth first search of a graph is
i.recursive
45. Given a graph G with n nodes, you want to find the node that has maximum degree.
What would be the complexity using an adjacency matrix?
a) O(1) b) O(log n) c) O(n) d) O(n log n) e) O(n2)
Ans. e
46. Given a graph G with n nodes and m edges, you want to find all the nodes with
degree 5. What would be the complexity using an adjacency list (where the degree of
each node is not stored)?
a) O(n) b) O(log m) c) O(log n) d) O(m) e) O(n logn )
Ans. d

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

Tuesday, January 18, 2011 7:16 PM

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

Tuesday, January 18, 2011 7:16 PM

-6-

You might also like