DSA Final Solution
DSA Final Solution
Question 1: Built an AVL Tree by inserting in order of input arrival: [10+5 Marks] [CLO 1, CLO 2]
Insertion Sequence = {29, 95, 59, 49, 39, 42, 67, 63, 40} after inserting following values now delete below
sequence in order. Deletion Sequence = {49, 59, 63}
Here 𝑋𝑖 is ith input index starting from 0th location to nth while 𝑃𝑗 is the list of prime numbers starting
from j=0 means 1st prime number and so on. i.e., 2, 3, 5, 7, 11 …
e.g. 295 ➔ 2*2 + 9*3 + 5*5 = 56 % 7 = 0
Inorder : B D A G J E C H F I
Preorder : A B D C E G J F H I
Postorder : D B J G E H I F C A
a) Adjacency Matrix
b) Adjacency List.
Note: Black boxes are hurdles while all the other cells with alphabets are nodes. The mouse has direct links to the
“A” node and “I” likewise all the other nodes in the grid are linked via a bidirectional graph. But nodes in diagonal
direction aren’t adjacent e.g. A & C don’t have any link. Just vertical and horizontally linked nodes are connected
in our given grid scenario.
DFS:
MOUSE I J K L M N CHEESE
OR
MOUSE A B C D E F G H CHEESE
Approach 1 Approach 2
Cheese Cheese
N H
M G
L F
K E
J D
I C
Mouse B
A
Mouse
Note: You have to use the heap data structure’s concept. You have to give the complete implementation of each
function. STL is not allowed.
node = pop(&st);
sum += node->data;
node->data = sum;