0% found this document useful (0 votes)
50 views4 pages

Final Exam Question 222 CSE2217

The document outlines exam instructions and contains seven questions related to graph theory, data structures, algorithms, and hashing. It includes tasks such as finding shortest paths, explaining algorithms, and providing pseudocode. Each question requires detailed answers and may involve figures for clarity.

Uploaded by

nurrafi9999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views4 pages

Final Exam Question 222 CSE2217

The document outlines exam instructions and contains seven questions related to graph theory, data structures, algorithms, and hashing. It includes tasks such as finding shortest paths, explaining algorithms, and providing pseudocode. Each question requires detailed answers and may involve figures for clarity.

Uploaded by

nurrafi9999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Any examinee found adopting unfair means will be expelled from the trimester / program as per

UIU disciplinary rules.

There are SEVEN questions. Answer all of them. Show full simulation or solved graph figures
wherever necessary. Figures in the right-hand margin indicate full marks.

1. (a) Fig. 1(a) is a graph where nodes A, B, C and D contain values 1, 2, 4 and 0 [2]
respectively. The BFS and DFS trees of the graph are in Fig. 1(b) and Fig. 1(c)
respectively. So the paths of the BFS tree form the numbers 120 and 14 while the paths of
the DFS tree form the number 1204.
Given this formulation, what will be the graph if the BFS tree forms the numbers 1246,
1247 and 13 and the DFS tree forms the numbers 12467 and 13? You can assume that
each node will have a unique value within 0 to 9 and the graph will contain no more than
10 nodes.

Fig. 1(a)
Fig. 1(b)

Fig. 1(c)

(b) Can you find the shortest path from A to C in the following graph (Fig. 2) using BFS? [1]
Explain your answer briefly.

Fig. 2. A directed graph

(c) “Breadth First Search” can create a minimum spanning tree for unweighted graphs. [2]
Explain why this statement is true.

1
2 (a) What is union-by-rank in the Disjoint-Set Union data structure? Why do we need this [2]
heuristic? Justify your answer.
(b) Write the pseudocode of Union Sets and Find Sets operation of Disjoint-Set Union [3]
data structure, assuming the path-compression and union-by-rank heuristics.
(c) Show the status of Fig. 3 after each of the following operations: find_set(3), [2]
find_set(6), find_set(5), find_set(3). Note that the operations are executed sequentially,
and you must use the path-compression heuristic.

Fig. 3. Disjoint set rooted tree


3 (a) What will be the runtime of Kruskal’s algorithm assuming edges are sorted using [1]
2
bubble sort? Note that bubble sort takes O(𝑛 ) time to sort n elements.
(b) Apply Prim’s algorithm to find the MST from the graph in Fig. 4 , assuming vertex D [4]
as the root. Show details and clearly draw the MST you have found.

Fig. 4. An undirected graph


(c) “Kruskal's algorithm grows a forest of trees and eventually forms the MST.” - Explain [2]
this statement with an example.

4 (a) A graph contains the vertices {A, B, C, D, E, F, G} and the shortest path from A to B [2]
is A→E→C→D→F→G→B. Is it possible to find the shortest path from E to F from
given data? Justify your answer.

2
(b) Find the Shortest path tree for the given graph in Fig. 5, where the source is vertex z. [3+2]
Show the details of your calculation. Justify how the shortest path tree satisfies optimal
substructure property.

Fig. 5: A directed graph G(V,E)

5 (a) What are the benefits of a good Hash Function? [1]


(b) Which data structure is best suited for implementing Chaining in a HashTable: Binary [3]
Search Tree or Linked List? Explain with time complexity comparisons between the both
for operations such as Insertion, Search and Deletion.

6 (a) Explain the working of the Rolling Hash Function in the Rabin-Karp algorithm using a [3]
suitable numerical example.
(d) Given a test string: fcdabdea and a pattern: dac, use Rabin-Karp’s algorithm to find [2]
whether the pattern exists in the string or not. You must show the Hash values and
calculations for all the substrings. The values of each character are given below.
char a b c d e f

value 1 2 3 4 5 6

7. (a) Write the definitions of the following terms: [3]


i. NP-Complete
ii. P
iii. NP-hard
(b) What does the following diagram (Fig. 6) represent? Explain. [2]

Fig. 6: Question 7(b)

3
4

You might also like