QS Bank Dsa
QS Bank Dsa
GROUP – A
Module 2
(i) Which of the following operations is not possible directly on a stack?
(a) Push
(b) Pop
(c) Peek
(d) Search
(ii) What is the time complexity of push and pop operations in a stack implemented using an array?
(a) O(1)
(b) O(n)
(c) O(log n)
(d) O(n2)
(iii) Which data structure is used in the undo mechanism of a text editor?
(a) Queue
(b) Stack
(c) Linked List
(d) Tree
(iv) In a queue, where is the new element inserted?
(a) Front
(b) Rear
(c) Middle
(d) None of the above
(v) Which of the following is not a type of queue?
(a) Simple queue
(b) Circular queue
(c) Priority queue
(d) Random queue
(vi) What is the primary difference between a stack and a queue?
(a) Stack is FIFO, Queue is LIFO
(b) Stack is LIFO, Queue is FIFO
(c) Stack allows access from both ends, Queue does not
(d) Stack is linear, Queue is non-linear
(vii) In a circular queue, if front = rear + 1, the queue is:
(a) Empty
(b) Full
(c) Half full
(d) None of the above
(viii) Which of the following operations is most efficient on a doubly linked list compared to a singly
linked list?
(a) Insertion at the end
(b) Deletion at the front
(c) Deletion in the middle
(d) Traversal
Module 3
(i) What is the worst case time complexity of the Breadth First Search algorithm on a graph having
V vertices & E edges?
(a) O(V+E)
(b) O(V2)
(c) O(V*E)
(d) O(E2)
(ii) What is the best case time complexity of searching a key in a binary search tree having ‘n’ nodes?
(a) O(n)
(b) O(log2n)
(c) O(n2)
(d) O(1)
(iii) What is the worst case time complexity of the Depth First Search algorithm on a graph having V
vertices & E edges?
(a) O(V+E)
(b) O(V2)
(c) O(V*E)
(d) O(E2)
(iv) What is the worst case time complexity of searching a key in a binary search tree having ‘n’ nodes?
(a) O(n)
(b) O(log2n)
(c) O(n2)
(d) O(1)
(v) Which of the following cannot be the value of the balance factor of a node in an AVL tree?
(a) 0
(b) -1
(c) 1
(d) 2
(vi) What is the worst case time complexity of the most optimized code which gives the height of a
binary search tree having ‘n’ nodes?
(a) O(n)
(b) O(log2n)
(c) O(n2)
(d) O(1)
(vii) What is the worst case time complexity of inserting a node in a binary tree having ‘n’ nodes?
(a) O(n)
(b) O(n2)
(c) O(1)
(d) O(log2n)
(viii) What is the worst case time complexity of deleting a node in an AVL tree having ‘n’ nodes?
(a) O(n)
(b) O(n2)
(c) O(log2n)
(d) O(1)
Module 4
(i) Quick sort uses which of the following methods to implement sorting?
(a) partitioning
(b) selection
(c) exchanging
(d) merging
(ii) What is the time complexity of finding the maximum number in an unsorted array ?
(a) O(n)
(b) O(lg n)
(c) O(n2)
(d) O(n*lg n)
(iii) A hash function f is defined as f(key)= key mod 7, with a linear probing insert the keys 37, 38, 72,
48, 98, 11, 56, into a table indexed from 0, in which location the key 11 will be stored ( Count table
index 0 as 0th location)?
(a) 1
(b) 2
(c) 5
(d) 6
(iv) What is the best time complexity of Linear search ?
(a) O(1)
(b) O(n)
(c) O(lg n)
(d) O(n2)
(v) Which of the following algorithms use recursion for sorting an array of numbers?
(a) Bubble Sort and Insertion Sort
(b) Quick Sort and Merge Sort
(c) Bubble Sort and Merge Sort
(d) Bubble Sort and Quick Sort
(vi) Which sorting algorithm is known for having a time complexity of O(n^2) in both its worst and
average cases but is stable and works well with small or nearly sorted arrays?
(a) Selection Sort
(b) Bubble Sort
(c) Insertion Sort
(d) Heap Sort
(vii) Which of the following is true about binary search?
(a) It can be applied to any list, sorted or unsorted.
(b) It has a worst-case time complexity of O(n).
(c) It requires the list to be sorted before the search is performed.
(d) It works faster than linear search on all types of lists.
(viii) Which of the following sorting algorithms is not based on the divide-and-conquer principle?
(a) Quick Sort
(b) Merge Sort
(c) Heap Sort
(d) Bubble Sort
GROUP – B
M=
(d) What is the time complexity to access an element from the triplet format of a sparse matrix?
4. (a) Consider a List using an array. What is the time complexity of the following operations?
(i) Insert a beginning
(ii) Delete from beginning
(iii) Append
(iv) Delete from end
(v) Insert a position
(vi) Delete from position
(b) What are the demerits of implementing a List using an array?
(c) Consider the following loop and calculate its time complexity.
for(i=1;i<=n; i++)
{
printf(“Hello world\n”);
for(j=1;j<=i; j++)
printf(“Hello world of C\n”);
}
5. (a) Consider a two-dimensional integer array of M with 4 rows and 3 columns. Assume 5000 is the
starting address of 2D array M. Now evaluate M[2][2] address using column-major formula.
(b) Consider the following loop and calculate its time complexity.
for(i=1;i<=n; i++)
{
printf(“Hello world\n”);
for(j=1;j<=i; j++)
for(k=1;k<=i; k++)
printf(“Hello world of C\n”);
}
7. (a) Consider M[][]as a two-dimensional array of integers starting at 1000. The number of rows and
columns are 10 and 5. Now calculate the address of M[6][3] using row-major and column-major-
addressing policy.
(b) Consider a Circular linked list with the tail pointer. Now write pseudo code/ C function for the
following operations.
(i) Delete the first element.
(ii)Insert a node at the first position.
GROUP – C
10. (a) Write the pseudo code of stack operations (PUSH, POP, PEEK) using an array.
(b) How stack can be used to check the validity of parentheses in any algebraic expression.
(c) How reversing a list can be done using stack.
11. (a) Describe the working of a queue using a linked list with pseudocode.
(b) Differentiate between a simple queue, circular queue, and deque with appropriate examples.
12. (a) Write the algorithm for implementing a circular queue using an array.
(b) Discuss the benefits of using a circular queue over a simple queue.
(c) Write the pseudocode for the operations in an Input Restricted Deque..
13. (a) Convert the following infix to postfix notation using STACK: K+L-M*N+(O^P)*W/U/V*T+Q.
(b) Explain how your algorithm handles operator precedence and parentheses.
(c) What is an abstract data type? Explain with examples.
14. (a) Discuss the pros and cons of implementing a stack using an array vs. a linked list.
(b) Provide pseudocode for both implementations.
15. (a) Illustrate the concept of double ended circular queue (i.e. Deque). Provide an example of a real
application.
(b) For a Deque implemented using an array, give algorithms for (i) IsDQEmpty- returns true if deque is
empty. (ii) IsDQFull- return true if deque is full (iii) InsertFront- insert an element in the front of deque.
(c) Consider two different polynomials X1 = 3x1+5x2+7x3 and X2= 7x0+3x1+4x2. The degree of X1 is
3 and the degree of X2 is 2. Show the steps to add the polynomials using an array.
16. (a) Explain what Infix, Prefix and Postfix expressions are. Why do we need Prefix and Postfix
expressions?
(b) Write the algorithm for evaluation of postfix expression.
(c) Evaluate the following:
a b c * + d e f ^ / - where a=2, b=3, c=4, d=16, e=2, f=3.
18. (a) Explain the Tower of Hanoi problem with the algorithm. How it can be solved using recursion ()
[trace for 3 discs].
(b) Explain how the problem of finding factorial can be solved using a recursive function (using both
direct and indirect recursion).
GROUP – D
(c) Given a binary heap of height ‘h’, obtain the minimum & maximum number of nodes in terms of
‘h’ with proper justification.
21. (a) Obtain the adjacency matrix & adjacency list of the following graph.
(b) Create a binary search tree with the input:- 98, 2, 48, 12, 56, 32, 4, 67, 23, 87, 21, 55, 46.
Thereafter, delete the values 23, 56 and 2. Show all steps.
22. (a) The structure of a node of a binary search tree is defined in C as follows:
typedef struct Tree { int val; struct Tree *left, *right; } node;
Write a function that takes the root of a binary search tree and an integer value as arguments
and returns true if the integer value occurs as a node value in the tree, else returns false.
Comment on the time complexity of the function you have written.
(b) What are the possible values of the balance factor of an AVL tree? Compare with proper
justification between a binary search tree and an AVL tree on the basis of the worst case time
complexities of the following operations:-
i) Insertion of a node ii) Searching of a node value iii) Deletion of a node
23. (a) Write the pseudo-code for Breadth First Search traversal & show all steps of running your code
on the given input graph taking G as the source node:-
(b) (i) Write the pseudo-code for Depth First Search traversal & mention the time complexity of the
algorithm.
(ii) Show the Depth First Search Traversal Sequence of the following graph starting from the
source vertex numbered 1, along with the discovery & finishing time of each vertex of the graph.
24. (a) Consider the following sequence of keys: 40, 15, 65, 35, 55, 45, 75, 95, 85 ,5, 30
Show all steps of inserting the keys in the given sequence in each of the following data structures
both of which are initially empty:- i) Binary Search Tree ii) AVL Tree
(b) After creating the Binary Search Tree in the previous question show all steps of obtaining the
modified BST after deleting the node 65
25. (a) Write the pseudo-code for inserting a node having integer key value into a binary search tree.
Mention the best case & worst case time complexities of the code you have written.
(b) Write the pseudo-code for deleting a node in a binary search tree. Your code should work for any
internal node as well as a leaf node. Mention the time complexity of your code.
26. (a) Write down the differences between a binary search tree and an AVL tree using appropriate
points of differences.
(b) Create an AVL tree with the input sequence: 96, 3, 43
(i) Now insert 27 and 35 into the created tree.
(ii) Delete the value 35
GROUP – E
27. (a) Write a binary search function for an element in a sorted array. What is the time complexity of
the Binary search function?
(b) Consider the following data sequence in the array.
10,100,85,65,95, 150,75,80.
Apply the Quick Sort algorithm to sort the array. Discuss all the passes with relevant figures.
28. (a) Given a hash table of 100 locations (0 to 99), calculate the hash value using the folding method
for keys 500098, 351899, and 777709.
(b) Explain why double hashing is preferred over linear probing and quadratic probing with multiple
examples.
29. (a) Explain the methodology of Heap sort with examples. What is the time complexity of the Heap
sort methodology?
(b) Explain the methodology of Merge sort with examples. What is the time complexity of the Merge
sort algorithm?
30. (a) Explain the working of Quick Sort and Merge Sort.
(b) Provide examples of each technique and analyse their advantages and disadvantages.
31. (a) Discuss the different collision resolution techniques used in hashing, focusing on open addressing
and chaining.
(b) What are the parameters that characterize the basic functions of a computer network?
34. (a) Given the following sequence of elements insert these into a hash table of size 7 & use linear
probing to resolve collisions (if any):
73, 93, 40, 47, 10, 55, 63
Use the hash function (h(k) + i) mod 7, h(k)= k mod 7, i Є {0,1,2,...,6}.
(b) Write a recursive function to implement binary search for an integer element ‘x’ in an integer
array of size ‘n’
(c) Analyze the time complexity of the binary search algorithm using recurrence relation.