Professional Documents
Culture Documents
2. Considering the following graph represented by an adjacency matrix,
0 1
a b c d e f g h
B a 0 1 0 0 1 1 0 1 C
B C
B b 1 0 1 0 0 0 0 0 C
B C
B c 0 1 0 1 0 0 0 0 C
B C
B d 0 0 1 0 0 1 0 0 C
B C
B e 1 0 0 0 0 0 0 0 C
B C
B f 1 0 0 1 0 0 0 0 C
B C
@ g 0 0 0 0 0 0 0 1 A
h 1 0 0 0 0 0 1 0
a) Draw the graph
b) Traverse the graph using DFS (if ties, follow the alphabetical order)
c) Provide the time stamps for each node.
Node a b c d e f g h
Discovery
Time
Finish
Time
d) Traverse the graph using BFS (if ties, follow the alphabetical order)
e) Comparing between DFS and BFS, which is a faster algorithm? What is its
running time expressed in terms of G=(V,E)?
3a). Considering the following graph, show the topological order using topological
sort (if ties, follow the alphabetical order)
b) What is the running time for this operation expressed in terms of G=(V,E)?
4. Considering the following graph, use the Kruskal algorithm to
a) Construct the minimum spanning tree
b) Compute its minimum weight
c) Draw the disjoint-set at every step
(if ties, follow the alphabetical order)
5. Considering the following algorithm,
a) Identify the following running time and express it in terms of G=(V,E). Make
the bound as tight as possible.
Statements Running Time
1
2 3
4
5 - 8
9
b) Given a graph G=(V,E) where |V| > |E|, what is the running time of the above
algorithm. Justify your answer.
6a) Perform one iteration of heap sort using max-heap ordering.
b) What is the running time for the heap-sort algorithm given n elements?
7a). Show that the HEAPIFY procedure can be written as
2n
T (n) = T ( ) + (1)
3
b) Show that the running time of the Build_HEAP procedure can be characterized as
(n)
8a) Perform a union operation on the following binomial heaps
Heap A:
Heap B:
b) What is the running time for this operation given n nodes?
9a) Perform a delete min operation on the following binomial heaps.
b) What is the running time for this operation given n nodes?