Вы находитесь на странице: 1из 3

Name: Khanh Huynh

Student ID: 0761882


Date: 20/10/2013
2IL65 Algorithms
Assignment 7

Exercise 1:
a) An undirected graph G with n vertices can have at most

edges. This happens


when every vertex is connected to the rest of the vertices (n 1).
b) A directed graph G with n vertices can have at most n
2
edges. This happens when
every vertex is connected to the rest of the vertices and also to itself.
c) An undirected graph G with n vertices and contains k vertices of degree 1 can have at
most

+ k edges. This happens when every vertex in n k vertices that does


not have degree 1 is connected to the rest of the vertices (n k 1).
d) An undirected graph G with n vertices and is d-regular can have at most

edges.
e) An undirected graph G consists of k disjoint trees can have at most n k edges.
Proof: Call the number of nodes in k trees are: i
1
, i
2
, , i
k
.
i
1
+ i
2
+ + i
k
= n
Every tree with i nodes has exactly i 1 edges. Thus the total number of edges in graph G
is:
(i
1
1) + (i
2
1) + + (i
k
1) = n k (edges)

Exercise 2:













Exercise 3:
An edge always connects between 2 vertices in an undirected graph. Degree of a vertex is
the number of edges incident to it. Thus, every edge accounts for 2 in the sum of the
degrees. It follows that the sum of the degrees is double the amount of edges in an
undirected graph (handshaking lemma).
Assume the number of nodes with uneven degree in an undirected graph is odd. It follows
that the sum of the degrees in such a graph is odd. This contradicts with the handshaking
lemma. Thus the number of nodes with uneven degree in an undirected graph should
always be even.

Exercise 4:
a) A DFS tree of a complete graph will look like an acyclic path connecting all vertices in
the graph. This is because if DFS has not visited all the vertices in the graph, there will
always be at least a vertex of white color that is connected to the current vertex being
visited as all the vertices are connected.
b) A BFS tree of a complete graph will look like a tree with root at the source vertex and
all the rest of the vertices are direct children of the root vertex. This is because no matter
where the source vertex is, it is always connected to all other vertices with distance 1.

Exercise 5:
Assume there is no cycle in a connected undirected graph G = (V, E) with |E| |V|.
This means G is a tree. Every tree with |V| vertices has exactly |V| - 1 edges. It follows
that |E| < |V|, contradicts with assumption that |E| |V|.
Thus A connected undirected graph G = (V, E) with |E| |V| must contains a cycle.

Exercise 6:
BFS and DFS use adjacency lists and not an adjacency matrix because both algorithms
need to list all the vertices that are adjacent to a particular vertex. Using adjacency matrix,
this will takes (V) time regardless of the type of graph. While using adjacency lists, this
will takes only (degree(u)) which is ranging from (1) to (V). This means on certain
type of graphs when degree(u) is not of order |V|, using adjacency lists can perform much
faster than an adjacency matrix.

Exercise 7:
a) A topological ordering for graph 1 is:










b) Graph 2 does not have a topological order as there is more than a cycle in the graph.
Proof: If graph 2 has a topological order: (c, d), (d, f), (f, g), (g, h) E thus f[c] > f[d] >
f[f] > f[g] > f[h]. However, (h,c) E thus f[h] > f[c], contradicts with f[c] > f[h] from the
previous statement.
Thus a topological order for graph 2 does not exist.





c a b d e h f g k

Вам также может понравиться