EndSem Key
EndSem Key
5 7 * 3 + 9 3 / 6 7 - * +
Ans: 35
5 7 + 3 * 9 3 / 6 4 + * -
7 7 + 3 * 9 3 / 4 5 + * -
Ans: 15
7 7 * 3 + 9 3 / 4 5 - * +
[Note#1: A B + considered as A+B]
[Note#2: Push the values into the stack from left to right and perform the operations]
[Note#3: Detailed solution gets an additional 0.5 Mark for this question]
Ans: 49
int data;
struct node *next;
};
[Note#1: Please consider that the following elements are already inserted in the Linked List.]
[1 Mark]
int data;
struct node *next;
}
[Note#1: Please consider that the following elements are already inserted in the Linked List.]
[1 Mark]
Ans: 119, 99
int data;
struct node *next;
}
[Note#1: Please consider that the following elements are already inserted in the Linked List.]
[1 Mark]
Ans: 119, 15
Q3) After performing the following operations on Queue and Stack data structure [queue size is set to 5
and stack size is set to 3].
[1 Mark]
Write down the elements in the Queue from Left to Right in the box
[Note#1: Please consider that the queue operations is following the real queue implementation, which
means that tail pointer is reducing after dequeuing an element]
[Note#3: Detailed solution gets an additional 1 Mark for this question]
Q3) After performing the following operations on Queue and Stack data structure [queue size is set to 7
and stack size is set to 3].
[1 Mark]
(1) Enqueue () to the queue even numbers between 11 to 25.
(2) On getting the Queue exception by inserting the value, Dequeue() 2 values (i.e., Dequeue(),
Dequeue ())
(3) Push() each value to stack that are Dequeued in Step (2)
(4) Pop() all pushed values from the stack
(5) Enqueue() each value in the same order that is popped from Step (4)
Write down the elements in the Queue from Left to Right in the box.
[Note#1: Please consider that the queue operations is following the real queue implementation, which
means that tail pointer is reducing after dequeuing an element]
[Note#3: Detailed solution gets an additional 1 Mark for this question]
Q3) After performing the following operations on Queue and Stack data structure [queue size is set to 7
and stack size is set to 3].
[1 Mark]
[Note#1: Please consider that the queue operations is following the real queue implementation, which
means that tail pointer is reducing after dequeuing an element]
[Note#3: Detailed solution gets an additional 1 Mark for this question]
Write down the Inorder and Preorder traversal for the above?
ANS:
Write down the Inorder and Preorder traversal for the above?
ANS:
Write down the Inorder and Preorder traversal for the above?
ANS:
[Note#1: Please write down the numbers from left to right in the below boxes]
[Note#2: Detailed solution gets an additional 1 Mark for this question]
Q5) What will be the output at the end of the seventh iteration of selection sort while sorting the
following numbers in ascending order?
[Note#1: Please write down the numbers from left to right in the below boxes]
[Note#2: Detailed solution gets an additional 1 Mark for this question]
Q5) What will be the output at the end of the fifth iteration of bubble sort while sorting the following
numbers in ascending order?
[Note#1: Please write down the numbers from left to right in the below boxes]
[Note#2: Detailed solution gets an additional 1 Mark for this question]
Q5) What will be the output at the end of the seventh iteration of bubble sort while sorting the following
numbers in ascending order?
[Note#1: Please write down the numbers from left to right in the below boxes]
[Note#2: Detailed solution gets an additional 1 Mark for this question]
Ans: [5, 9, 11, 16, 22, 28, 34, 35]
Q6) Consider the following key values that are inserted into the hash table in the order given using the
hash function H (k) and the hash table is set to 20 from 0 to 19.
96, 48, 63, 29, 87, 77, 48, 65, 69, 94, 61 [1 Mark]
int H(int k) {
a = floor(a/16);
a = a+k;
a = a%20;
return a;
Write down hash index of an element 87, if the hash table uses quadratic probing to hash the given
elements _____
Answer: 0
Q6) Consider the following key values that are inserted into the hash table in the order given using the
hash function H (k) and the hash table is set to 20 from 0 to 19.
96, 48, 63, 29, 87, 77, 48, 65, 69, 94, 61 [1 Mark]
int H(int k) {
a = floor(a/16);
a = a+k;
a = a%20;
return a;
}
Write down hash index of an element 94, if the hash table uses quadratic probing to hash the given
elements _____
Ans: 12
Q6) Consider the following key values that are inserted into the hash table in the order given using the
hash function H (k) and the hash table is set to 20 from 0 to 19.
96, 48, 63, 29, 87, 77, 48, 65, 69, 94, 61 [1 Mark]
int H(int k) {
a = floor(a/16);
a = a+k;
a = a%20;
return a;
Write down hash index of an element 65, if the hash table uses quadratic probing to hash the given
elements _____
Ans: 13
Q6) Consider the following key values that are inserted into the hash table in the order given using the
hash function H (k) and the hash table is set to 20 from 0 to 19.
96, 48, 63, 29, 87, 77, 48, 65, 69, 94, 61 [1 Mark]
int H(int k) {
a = floor(a/16);
a = a+k;
a = a%20;
return a;
Write down hash index of an element 69, if the hash table uses quadratic probing to hash the given
elements _____
Ans: 11
Q7) Consider an array containing ‘n’ elements. The elements present in an array are in arithmetic
progression, but one element is missing in that order. What is the time complexity to find the position of
the missing element using divide and conquer approach?
A. 𝑂(𝑛)
2
B. 𝑂(𝑛 )
C. 𝑂(𝑙𝑜𝑔 𝑛)
D. 𝑂(𝑛 𝑙𝑜𝑔𝑛)
Ans: C
Q7) Consider an array ‘A’ containing ‘n’ distinct elements and those elements are in non-decreasing
order. What is the time complexity to find the element in which A[i] = i using divide-and-conquer
approach?
2
A. 𝑂(𝑛 )
B. 𝑂(𝑛 𝑙𝑜𝑔 𝑛)
C. 𝑂(𝑙𝑜𝑔 𝑛)
D. 𝑂(𝑛)
[Note#1: Detailed solution gets an additional 1 Mark for this question]
Ans: C
Q7) Consider an array consisting of 0’s and 1’s in which all 1’s are followed by all 0’s . What is the time
complexity to count the number of 1’s in an array using divide and conquer?
2
A. 𝑂(𝑛 )
B. 𝑂(𝑛 𝑙𝑜𝑔 𝑛)
C. 𝑂(𝑙𝑜𝑔 𝑛)
D. 𝑂(𝑛)
Ans: C
Insert 43, 18, and 2 elements to the above Min Heap tree. Write the Pre-order of the final Min Heap
tree?
[Note#1: No partial marking for the question, hence please kindly carefully enter the node values]
[Note#2: Detailed solution gets an additional 1 Mark for this question]
Ans: Pre-order: 2, 23, 32, 87, 50, 43, 90, 53, 4, 14, 63, 18, 40
Insert 43, 18, and 2 elements to the above Min Heap tree. Write the Post-order of the final Min
Heap tree?
[Note#1: No partial marking for the question, hence please kindly carefully enter the node values]
[Note#2: Detailed solution gets an additional 1 Mark for this question]
Ans: Post-order: 87, 50, 32, 90, 53, 43, 23, 63, 18, 14, 40, 4, 2
Insert 43, 18, and 2 elements to the above Min Heap tree. Write the In-order of the final Min Heap
tree?
[Note#1: No partial marking for the question, hence please kindly carefully enter the node values]
[Note#2: Detailed solution gets an additional 1 Mark for this question]
Ans: In-order: 87, 32, 50, 23, 90, 43, 53, 2, 63, 14, 18, 4, 40
3, 6, 7, 5, 4, 1, 0, 9, 8, 10 [1 Mark]
[Note#1: When double rotation is required in order to construct the AVL such as Left-Right (LR) or
Right-Left (RL), should be considered a single rotation]
[Note#2: Detailed solution gets an additional 1 Mark for this question]
How many rotations are required to construct an AVL tree using the above elements? ____
Ans: 6
3, 7, 6, 5, 4, 0, 1, 8, 9, 10 [1 Mark]
[Note#1: When double rotation is required in order to construct the AVL such as Left-Right (LR) or
Right-Left (RL), should be considered a single rotation]
[Note#2: Detailed solution gets an additional 1 Mark for this question]
How many rotations are required to construct an AVL tree using the above elements? ____
Ans: 6
Q9) Consider the following elements
3, 7, 6, 4, 5, 0, 1, 10, 8, 9 [1 Mark]
[Note#1: When double rotation is required in order to construct the AVL such as Left-Right (LR) or
Right-Left (RL), should be considered a single rotation]
[Note#2: Detailed solution gets an additional 1 Mark for this question]
How many rotations are required to construct an AVL tree using the above elements? ____
Ans: 6
Q10) Find the total weight of a minimal spanning tree containing the edges {D, H}, {L, H}, {L, P} in the
given weighted graph by following the kruskal's algorithm.
Ans: 73
Q10) Find the total weight of minimal spanning tree containing the edges {B, F}, {F, J}, {J, K}, {K, G}, {C,G}
in the given weighted graph by following the kruskal's algorithm.
Ans: 73
Q10) Find the total weight of a minimal spanning tree containing the edges {A, E}, {E, I}, {I, M} in the
given weighted graph by following the kruskal's algorithm.
Ans: 73
Q10) Find the total weight of a minimal spanning tree containing the edges {M, N}, {N, O}, {O, P} in the
given weighted graph by following the kruskal's algorithm.
Ans: 73
Q11) Consider the following digraph starting at vertex 0 (starting discovery time is zero) and apply
Dijkstra’s single source shortest path algorithm on it. Select the correct order from the following in which
vertices are removed from the Priority Queue?
[1 Mark]
Ans: C
Q11) Consider the following digraph starting at vertex 1 (starting discovery time is zero) and apply
Dijkstra’s single source shortest path algorithm on it. Select the correct order from the following in which
vertices are removed from the Priority Queue?
[1 Mark]
Ans: A
Q11) Consider the following digraph starting at vertex 2 (starting discovery time is zero) and apply
Dijkstra’s single source shortest path algorithm on it. Select the correct order from the following in which
vertices are removed from the Priority Queue?
[1 Mark]
Ans: B
Q12) The running time of an algorithm is given by the recurrence relation. Solve the recurrence and
select the correct answer! [1 Mark]
Ans: C
Q12) The running time of an algorithm is given by the recurrence relation. Solve the recurrence and
select the correct answer! [1 Mark]
2
A. 𝑂(𝑛 )
B. 𝑂(𝑛 𝑙𝑜𝑔 𝑛)
C. 𝑂(𝑛)
D. 𝑂(𝑛 𝑙𝑜𝑔 𝑙𝑜𝑔𝑛)
Ans: D
Q12) The running time of an algorithm is given by the recurrence relation. Solve the recurrence and
select the correct answer! [1 Mark]
𝑇(𝑛) = 𝑛 𝑇( 𝑛 ); T(0)=T(1)=1
2
A. 𝑂(𝑛 )
B. 𝑂(𝑙𝑜𝑔 𝑙𝑜𝑔 𝑛)
C. 𝑂(𝑛)
D. 𝑂(𝑛 𝑙𝑜𝑔 𝑙𝑜𝑔𝑛)
Ans: B
Q12) The running time of an algorithm is given by the recurrence relation. Solve the recurrence and
select the correct answer! [1 Mark]
𝑇(𝑛) = 𝑇( 𝑛) + 1; T(0)=T(1)=1
2
A. 𝑂(𝑛 )
B. 𝑂(𝑙𝑜𝑔 𝑛)
C. 𝑂(𝑛)
D. 𝑂(𝑙𝑜𝑔 𝑙𝑜𝑔𝑛)
Ans: D
Q13) Consider the following program which sorts distinct elements in increasing order
[1 Mark]
max = i;
for(j = i-1; CONDITION2; j--) {
if (CONDITION3)
max = j;
swap(A[i] , A[max]);
Which of the following will represent the correct value of CONDITION1, CONDITION2, and
CONDITION3 in the above code?
Ans: A
Q13) Consider the following insertion sort algorithm?
[1 Mark]
Key = A[j];
i = j – 1;
while(i > - 1 && CONDITION1) {
STATEMENT1
i = i – 1;
A[i + 1] = Key;
Ans: B