0% found this document useful (0 votes)
45 views6 pages

DSA Question Bank

The document consists of multiple-choice questions and programming tasks related to data structures, including linked lists, stacks, queues, trees, and algorithms. It covers topics such as time complexity, traversal methods, and practical applications of data structures in real-world scenarios. Additionally, it includes programming exercises for implementing various data structures and algorithms.

Uploaded by

anshyprabha2005
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)
45 views6 pages

DSA Question Bank

The document consists of multiple-choice questions and programming tasks related to data structures, including linked lists, stacks, queues, trees, and algorithms. It covers topics such as time complexity, traversal methods, and practical applications of data structures in real-world scenarios. Additionally, it includes programming exercises for implementing various data structures and algorithms.

Uploaded by

anshyprabha2005
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/ 6

PART-A

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

20. Evaluating a postfix expression requires:


B) Stack
C) Queue
D) Linked List
E) Array

21. The height of a binary tree with n nodes is at least:


F) log₂(n)
G) n
H) n-1
I) ⌊log₂(n)⌋
22. The number of leaf nodes in a full binary tree of height h is:
J) h
K) 2^h
L) 2^(h-1)
M) 2^h - 1
23. In a binary search tree (BST), the left subtree of a node contains nodes that are:
N) Greater than the node
O) Less than or equal to the node
P) Equal to the node
Q) Greater than or equal to the node
24. What is the time complexity of a program to reverse a linked list?
a.O(n) b.O(1) c.O(n2 ) d. None of the above
25. Which matrix has most of the elements (not all) as Zero?
a.Identity Matrix b. Unit Matrix c. Sparse Matrix d. Zero Matrix
26. In a doubly linked list the number of pointers affected for an insertion operation will
be
a. 4 b. 0 c. 1 d.Depends on the nodes of doubly linked list
27. If the initial stack contains [1, 2, 3] (where 1 is at the bottom and 3 is at the top), what
will the stack look like after the following sequence of operations? Push(4), Pop(),
Push(5), Push(6)
b. [1, 2, 3, 5, 6] b. [1, 2, 5, 6] c. [1, 3, 5, 6] d. [1, 2, 6]
28. Consider a circular queue of size 5. Initially, front = rear = -1. The following
operations are performed: Enqueue(1), Enqueue(2), Enqueue(3), Dequeue(),
Enqueue(4), Enqueue(5), Dequeue(), Enqueue(6). What is the front and rear index
after these operations?
a. Front = 2, Rear = 0 b. Front = 1, Rear = 4
c. Front = 0, Rear = 3 d. Front = 2, Rear = 4
29. What is the result of evaluating the postfix expression
6 2 3 + - 3 8 2 / + *?
a) 36 b) 30 c) 42 d) 48
30. A function call stack is used in programming languages to:
c. Store function parameters and local variables
d. Track function calls and return values
e. Implement recursion
f. All of the above
PART-B
1. Given an array, implement a function to reverse the elements using a stack.
2. Write a program to implement a queue using an array.
3. Perform all the tree traversal in the following tree.
4. Illustrate how a linked list can be used to represent a polynomial.
5. Why are sentinel nodes (dummy nodes) used in linked lists? Mention its
disadvantage.
6. Write an algorithm to search a particular element in a Binary search tree.
7. Explain the benefits of using a doubly linked list for A web browser that maintains the
history of visits and how it enables users to move both forward and backwards in their
browsing history.
8. Write an algorithm to insert a new node before first node in singly linked list.
9. Consider size of stack as 5 and apply following operation on stack and show the status
of stack and top pointer after each operation.
10. i ) push a , b, c ii) pop iii) push e,f iv) pop v) push g h
vi)push m vii)
11. A supermarket checkout system uses a queue to manage customers waiting to pay for
their groceries. Customers arrive at different times, and the cashier processes each
customer one by one. Occasionally, a customer may leave the queue if they find the
wait too long.
Think and write the following questions.
Describe how a queue can be implemented to handle the customers effectively.
(ii) how the system can accommodate a customer leaving the queue and ensure
that the next customer is served promptly.
12. A mobile application uses a complete binary tree to store user profiles for a gaming
platform. Each node represents a user, with the root node being the admin. Users can
invite friends, and these friendships are represented as left and right children in the
tree. The application needs to maintain the tree structure while allowing for efficient
access to user profiles and invitations.
13. Read and answer the following questions
(i) Explain how a complete binary tree can be utilized to store and manage
user profiles and friendships effectively.
(ii) Describe the process of adding a new user to the tree and how this addition
maintains the complete binary tree properties, ensuring the balance of the
structure.
14. Discuss with respect to the following tree:
(a) List the siblings for node E
(b) Compute each node height and height of the tree.
15. In Josephus problem, explain the purpose of using a circular linked list. How does this
data structure facilitate the elimination process, and what are the advantages of using
a circular linked list over a regular linear linked list or an array? Provide examples to
illustrate your explanation.
16. Convert the following infix expression to postfix notation:
Infix Expression: (A + B) * (C - D / E) + F * G
17. Imagine you are designing a task scheduling system for a multi-threaded application.
Each task has a priority level associated with it, where a higher number indicates a
higher priority. The system needs to ensure that tasks are executed in order of priority,
with the ability to handle new tasks being added dynamically while managing the
existing task queue. Discuss how you would implement a priority queue for this task
scheduling system
18. Make a binary search tree for the following sequence of numbers: 45, 36, 76,
23,89,115,98,39,41,56,69,48 Traverse the tree in Preorder, Inorder and Postorder
19. Write the algorithms for the following in single linked list :
i Delete a node with specified value from the list.
ii. Reverse the links of the list i.e. the first node becomes last
node
20. What is the real life implementation of Queue? Implement insert and delete operations
using array on simple queue.

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?

You might also like