0% found this document useful (0 votes)
48 views9 pages

QS Bank Dsa

DSA questions

Uploaded by

susmitakhan005
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)
48 views9 pages

QS Bank Dsa

DSA questions

Uploaded by

susmitakhan005
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
You are on page 1/ 9

PAPER NAME: Data Structure and Basic Algorithm

PAPER CODE: CSE2004

GROUP – A

MCQ (Choose the Correct Alternative)


Module 1
(i) What is a data structure?
(a) A programming language
(b) A collection of algorithms
(c) A way to store and organize data
(d) A type of computer hardware
(ii) What are the disadvantages of arrays?
(a) Index value of an array can be negative
(b) Elements are sequentially accessed
(c) Data structure like queue or stack cannot be implemented
(d) There are chances of wastage of memory space if elements inserted in an array are lesser than
the allocated size
(iii) Which of the following can be done with LinkedList?
(a) Stack
(b) Queue
(c) Binary Search tree
(d) All of the above
(iv) What is the space complexity needed to store a linked list of n nodes?
(a) O(1)
(b) O(n)
(c) O(n2)
(d) None of the above
(v) What is the time complexity of a program to reverse a linked list?
(a) O(1)
(b) O(n)
(c) O(n2)
(d) None of the above
(vi) What is the time complexity to insert an element to the front of a LinkedList(head pointer given)?
(a) O(1)
(b) O(n)
(c) O(n2)
(d) None of the above
(vii) What is the time complexity to insert an element to the rear of a LinkedList(head pointer given)?
(a) O(1)
(b) O(n)
(c) O(n2)
(d) None of the above
(viii) What does the following function do for a given Linked List with the first node as head?
void fun1(struct node* head)
{
if(head == NULL)
return;
fun1(head→next);
printf(“%d”, head→data);
}
(a) Print all nodes in the list
(b) Print all nodes in reverse order
(c) Prints alternate nodes of Linked List
(d) Prints alternate nodes in reverse order
(ix) Assuming int is of 4 bytes, what is the size of int arr[15];?
(a) 15
(b) 19
(c) 11
(d) 60

(x) In general, the index of the first element in an array is __________


(a) 0
(b) -1
(c) 2
(d) 1
(xi) Elements in an array are accessed _____________
(a) randomly
(b) sequentially
(c) exponentially
(d) logarithmically

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

FILL IN THE GAPS


1. After creating a linked list’s head pointer, you should make sure it points to ______________ before using it in
any operations.
2. The ____________ points to the first node in a linked list.
3. In a/an _________________ list, the last node has a pointer to the first node.
4. In a/an __________________ list, each node has a pointer to the one before it and the one after it.
5. Sparse matrix ____________ format is used to save the memory space of sparse matrix.
6. A __________ queue allows the queue to wrap around when the rear end is reached.
7. The two ends of a deque are called __________ and __________.
8. In a queue, elements are inserted at the __________ and removed from the __________.
9. A stack can be implemented using an array or a __________.
10. The minimum number of nodes in a binary heap of height ‘h’ is __________.
11. A full binary tree of ‘n’ nodes has __________ leaf nodes.
12. The height of a skewed binary tree having ‘n’ nodes is __________.
13. In _______________ the key is separated into different groups to generate the hash value.
14. If the next empty location is found in a squared number sequence, then it is called _______________.
15. The lower limit is modified when the key is _________ the middle element in the array in a binary search
method.
16. The total number of comparisons performed in the best case of the Selection Sort algorithm on an array of
‘n’ elements is __________.
17. In __________, the sorted portion of the array is built up one element at a time by repeatedly picking the smallest
(or largest) element from the unsorted portion.
18. The maximum number of nodes in a binary heap of height ‘h’ is __________.

GROUP – B

2. (a) What is Big-Oh notation?


(b) Prove that the following function f(n) is the O(n3 ).
f(n)= 7n3 + 2n2 +5
(c) What is Data structure?
(d) What are the basic properties of an algorithm?

3. (a) What is the time complexity to access an element from a 2D array?


(b) What is a triplet representation of a sparse matrix? What is the precondition to convert a matrix
to a triplet representation of a sparse matrix?
(c) Consider the following sparse matrix M and convert to triplet format

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”);
}

(c) Calculate the time complexity of the following loop.


while(n!=1)
{
n=n/2;
printf(“Data structure\n”);
}

6. (a) Prove that T(n)= 10n3+100n2 is O(n3).


(b) Consider a doubly linked list with head and tail pointer. Now write pseudo code/ C function for
the following operations.
(i) Insert a node at a particular position.
(ii) Delete the last element of the list.

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.

8. (a) Prove that T(n)= 10n3+20n2+5 is O(n3).


(b) Consider a single linked list with only a head pointer.
Write pseudo codes for the following points
(i) Reverse the linked list.
(ii) Delete a node from a given position.
(iii) Delete a node from the last position.

9. (a) Prove that T(n)= 20n3+n2+9 is O(n3).


(b) Consider a doubly linked list with head and tail pointer both.
Write pseudo codes for the following points:-
(i) Print the linked list in reverse order.
(ii) Append an element to the list.
(iii) Delete the last element.

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.

17. (a) Differentiate between iteration and recursion.


(b) Explain with code examples: direct, indirect, and tail recursion.

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

19. (a) The structure of a node of a binary tree is defined in C as follows:-


typedef struct Node { int val; struct Node *left, *right; } tree;
Given the pointer to the root of such a binary tree of ‘n’ nodes write functions for the following
traversals which take the root pointer as argument & mention the time complexity of each of the
algorithms:- i) Inorder ii)Preorder iii)Postorder
(b) Obtain the preorder, inorder and postorder traversals of the following binary search tree.

20. (a) The structure of a node of a binary tree is defined in C as follows:-


typedef struct Node { int val; struct Node *left, *right; } tree;
Given the pointer to the root of such a binary tree write the definitions of the following
functions:-
(i) int countLeafNodes( tree *root) {
// Return the number of Leaf nodes in the binary tree
}

(ii) int countTotalNumberOfNodes(tree *root) {


// Return the total number of nodes in the binary tree
}
(b) Given a full binary tree of ‘n’ nodes, find the number of internal nodes & leaf nodes in terms of ‘n’.

(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?

32. (a) Describe the process of binary search.


(b) Compare the time complexities of linear search and binary search, and discuss the conditions
under which binary search can be applied.

33. (a) Illustrate the working of Heap Sort.


(b) Explain how a heap data structure can implement a priority queue.
(c) Compare Heap Sort with other sorting algorithms in terms of time complexity.

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy