DSA Question Bank
DSA Question Bank
1. What is the main difference between a circular linked list and a regular linked list?
A. Nodes are linked in both directions.
B. The next pointer of the last node points to the head, not null.
C. Each node stores additional information about the previous node.
D. The list automatically sorts elements during traversal.
2. Which of the following is not a basic operation of a stack.
A. Push() B.Pop() C. Peek() D. Getmin()
3. What is the time complexity of enqueue and dequeue operations in a circular queue
implemented with an array?
A. O(n) for both operations
B. O(1) for both operations
C. O(1) for enqueue and O(n) for dequeue
D. O(n) for enqueue and O(1) for dequeue
4. Which traversal would you use to search for a node in a binary search tree efficiently?
A. Pre-order
B. Post-order
C. In-order
D. Level-order
5. Which traversal method is used to convert a binary tree into its mirror image?
A. In-order
B. Pre-order
C. Post-order
D. Level-order
6. Given a circular linked list, which operation requires the most time complexity?
A) Searching for an element
B) Insertion at the head
C) Deletion at the head
D) Finding the length of the list
7. Which of the following operations on a doubly linked list is not more efficient
compared to a singly linked list?
A) Insertion at the head
B) Deletion of the tail node
C) Traversal of the list
D) Deletion of a given node
8. Which of the following data structures can be used to implement a function that
checks if an expression has balanced parentheses?
A) Stack
B) Queue
C) Array
D) Linked List
9. In a circular queue implemented with an array, what condition indicates that the queue
is full?
A) Front == Rear
B) (Rear + 1) % Size == Front
C) Rear == Size - 1
D) Front == -1
10. Write the time complexity of pushing an element onto a stack?
A) O(1)
B) O(n)
C) O(log n)
D) O(n²)
11. What is the worst-case time complexity for inserting a node into an unbalanced BST?
A. O(n log n)
B. O(log n)
C. O(n)
D. O(1)
12. How to implement a stack using queues?
A. Use a single queue and enqueue elements to the front.
B. Use two queues and make push costly by enqueueing elements to one
queue, then dequeue and enqueue all elements to the other.
C. Use a list to implement stack operations.
D. Implement the stack directly using recursion
13. How to delete a node with two children in a BST?
A. Replace it with its left child.
B. Replace it with its right child.
C. Replace it with the in-order predecessor or successor and delete that node.
D. D) Remove it and re-arrange the tree
14. In a double-ended queue (deque), which of the following operations can be
performed?
A. Insertion and deletion only from the rear end
B. Insertion only from the front end, deletion only from the rear end
C. Insertion and deletion from both front and rear ends
D. Deletion only from the front end, insertion from the rear end
15. What is the height of a tree with only a root node?
A) 0
B) 1
C) 2
D) Undefined
16. Which property is true for every node in a binary search tree (BST)?
a. All left children have values greater than the root
b. All right children have values smaller than the root
c. All left children have values smaller than the root, and all right children have values
greater than the root
d. The tree is balanced
17. What is the maximum number of nodes in a complete binary tree of height h?
a. 2h−1 b, 2h+1−1 c. 2h d. 2h−1
18. What is the time complexity of searching for a node in a balanced binary search tree
(BST) with n nodes?
a. O(n) b. O(log n) c. O(n log n) d. O(1)
19. The infix expression (A + B) * (C - D) is correctly represented in postfix as:
a. AB+CD-*
b. ABCD+-*
c. AB+CD-*
d. A+B*C-D
PART C
1. Implement singly linked list functions to manage the tasks. Perform the following
operations:
• addTaskInBeginning(task): Add a new task to the beginning of the list.
• addTaskInEnd(task): Add a new task to the end of the list.
• getTaskCount(): Return the total number of tasks in the queue.
2. Write algorithm for infix expression to postfix using stack and convert the following
infix expression to postfix:
A + (B * C - (D / E ^ F) * G) * H
3. Write a stack program using arrays that supports not only push and pop operations but
also a getMin() operation that returns the minimum element in the stack.
4. Create a binary search tree using the following data elements: 54, 45, 39, 56, 12, 32,
10, 40, 89, 67, 81,After successful creation, perform following operation and show
tree at each step.
i) Delete 32
ii) Delete 89
iii) Delete 54
5. Explain the steps involved in the following insertion operations in a singly linked list.
i. Insert the node in the start and End. (5)
ii. ii. Insert the node in the middle of the List (5
6. Explain the different types of queues with examples.
7. Write an Algorithm to convert an infix to a postfix expression for the following
expression. (a+b)*c/d+e/f .
8. Consider the binary search tree given below.
(a) Find the result of in-order, pre-order, and post-order
traversals.
(b) Show the deletion of the root node (c)
(c) Insert 11, 22, 33, 44, 55, 66, and 77 in the tree
9. You are developing a web browser application that needs to efficiently manage the
browsing history for users. The application should allow users to navigate through
their history of visited web pages, enabling them to go back and forth between pages
they've recently accessed. Additionally, the browser should allow users to remove
specific pages from their history. Implement the process.
10. You are developing a robotic arm system designed to automate the movement of disks
in a manufacturing setup where components need to be stacked and rearranged
efficiently. The robotic arm mimics the Tower of Hanoi puzzle to rearrange various
sized components (disks) on three designated pegs (stacks). The objective is to move
the disks from one peg to another while following specific rules: only one disk can be
moved at a time, a disk can only be placed on top of a larger disk, and no disk can be
placed on a peg that is not its designated target
ii. Implement a function that checks if a given string has balanced symbols
(parentheses, brackets, and braces) and check isBalanced("[(a + b) * c + (d / e)]")
11. You are developing an application for an online library management system that
needs to efficiently manage a catalog of books. Each book has a unique identifier
(ISBN), title, author, and publication year. The library wants to provide features like
searching for a book by its ISBN, adding new books, deleting books, and listing
books in a sorted order (by ISBN) for better inventory management.
12. To implement this functionality use a binary search tree, where each node in the tree
represents a book, and the keys are the ISBNs.
13. You are developing a text editor application that requires an undo feature to allow
users to revert their last actions (like typing, deleting, or formatting text).Which data
structure used to perform the action and implement the operations?