DS Unit 1 and II Q Bank
DS Unit 1 and II Q Bank
MCQs
Two-Marks Questions
Five-Marks Questions
Ten-Marks Questions
1. Write a program to implement stack operations (push, pop, and display) using arrays.
2. Explain in detail the differences between stacks and queues.
3. Write an algorithm to evaluate a postfix expression. Explain with an example.
4. Discuss the implementation and applications of a circular queue.
5. Explain polynomial addition using an example.
6. Write a C program to implement stack operations (push, pop, and display) using arrays.
7. Explain the implementation of a queue using linked lists, along with algorithms for
enqueue and dequeue.
8. Discuss in detail how polynomial addition is performed using a singly linked list, with a
step-by-step example.
9. Explain how multiple stacks can be implemented in a single array. Provide an algorithm
for the same.
10. Write a program to implement infix to postfix conversion and evaluate the postfix
expression using stacks.
UNIT II: Trees and Graphs
1. Which traversal method visits nodes in the a) Node iii is connected to node jjj
order: left, root, right? b) Node iii has a self-loop
a) Pre-order b) In-order c) Node iii and node jjj are not connected
c) Post-order d) Level-order d) None of the above (Correct answer:
(Correct answer: b) a)
2. What is the maximum number of nodes in a 14. The depth of a node in a tree is:
binary tree of height hhh? a) The number of edges from the root to the
a) 2h−12^h - 12h−1 b) 2h2^h2h node
c) h2h^2h2 d) h+1h + 1h+1 b) The number of edges from the node to the
(Correct answer: a) leaf
3. Which algorithm is used to find the shortest c) The height of the subtree rooted at the node
path in a graph? d) None of the above
a) Dijkstra’s b) Prim’s (Correct answer: a)
c) Kruskal’s d) Floyd-Warshall 15. What is the time complexity of DFS on a graph
(Correct answer: a) with VVV vertices and EEE edges?
4. What is the height of a tree with only one a) O(V + E) b) O(V * E) c) O(V^2)
node? d) O(E^2) (Correct answer: a)
a) 0 b) 1 c) -1 d) Undefined 16. Which traversal method is best for finding the
(Correct answer: b) shortest path in an unweighted graph?
5. In a binary tree, which traversal method uses a a) BFS b) DFS c) In-order
stack internally? traversal
a) In-order traversal d) Pre-order traversal (Correct answer:
b) Pre-order traversal a)
c) Post-order traversal 17. What is a spanning tree?
d) Level-order traversal a) A graph with all nodes connected
(Correct answer: b) b) A subgraph containing all nodes with no
6. Which of the following algorithms is used for cycles
finding the minimum spanning tree? c) A graph with cycles
a) Prim’s Algorithm b) Kruskal’s Algorithm d) A tree with weights (Correct answer:
c) Both a and b d) Dijkstra’s Algorithm b)
(Correct answer: c) 18. Dijkstra's algorithm does NOT work on graphs
7. A complete binary tree of depth ddd has how with:
many nodes? a) Weighted edges b) Negative edges
a) 2d−12^d - 12d−1 b) 2d2^d2d c) Cyclic edges d) Directed edges
c) 2d+1−12^{d+1} - 12d+1−1 (Correct answer: b)
d) d2−1d^2 - 1d2−1 (Correct answer: 19. A threaded binary tree allows traversal without
c) using:
8. Which data structure is used in breadth-first a) A queue b) A stack
traversal of a graph? c) Both a and b d) None of the above
a) Stack b) Queue c) Linked List (Correct answer: b)
d) Array (Correct answer: b) 20. In a tree, which traversal ensures visiting all
9. What is the height of an empty tree? nodes at the same depth before moving
a) -1 b) 0 c) 1 d) Undefined deeper?
(Correct answer: a) a) Pre-order b) In-order
10. In a binary tree, the number of leaf nodes is c) BFS d) DFS (Correct answer: c)
always: 21. Which algorithm is used for finding all-pairs
a) n/2n/2n/2 b) n−1n - 1n−1 shortest paths?
c) n+1n + 1n+1d) Greater than n/2n/2n/2 a) Prim’s algorithm b) Dijkstra’s algorithm
(Correct answer: d) c) Floyd-Warshall algorithm
11. What is a graph with no cycles called? d) Kruskal’s algorithm (Correct answer: c)
a) Connected graph b) Weighted graph 22. Which traversal method visits nodes in the
c) Acyclic graph d) Null graph order: root, left subtree, right subtree?
(Correct answer: c) a) Pre-order b) In-order c) Post-order
12. Which traversal technique is used for d) Level-order (Correct answer: a)
topological sorting? 23. What does a self-loop in a graph indicate?
a) BFS b) DFS c) In-order traversal a) The vertex is isolated.
d) Post-order traversal (Correct answer: b) b) The vertex is connected to itself.
13. In an adjacency matrix representation of a c) The graph is acyclic.
graph, what does a value of 1 at position (i,j) d) The graph has a spanning tree.
(i, j)(i,j) indicate? (Correct answer: b)
24. How many minimum spanning trees can a b) The number of edges originating from the
graph have? node
a) Always 1 b) At most 1 c) At least 1 c) The total degree of the node
d) Cannot be determined (Correct answer: d) The number of connected components
c) (Correct answer: a)
25. The binary representation of a graph using 30. Which algorithm is used to calculate transitive
adjacency lists requires: closure?
a) O(V) space b) O(V^2) space a) Floyd-Warshall algorithm
c) O(E + V) space d) O(V * E) space b) Dijkstra’s algorithm
(Correct answer: c) c) Kruskal’s algorithm
26. In Kruskal’s algorithm, the edges are sorted d) Bellman-Ford algorithm (Correct answer:
based on: a)
a) Number of vertices b) Weights of 31. A graph is considered strongly connected if:
edges a) There is a path between every pair of
c) Degree of nodes d) Topological order vertices.
(Correct answer: b) b) Every node has the same degree.
27. Which traversal algorithm is used to determine c) It has no cycles.
connected components of a graph? d) It contains at least one spanning tree.
a) BFS or DFS b) Topological sorting (Correct answer: a)
c) Spanning tree d) Shortest path 32. The shortest path from a source node to all
algorithms other nodes can be computed using:
(Correct answer: a) a) Dijkstra’s algorithm
28. What does the critical path in an activity b) Floyd-Warshall algorithm
network represent? c) Prim’s algorithm
a) The shortest time to complete the project d) Kruskal’s algorithm (Correct answer: a)
b) The longest path of activities in the network 33. A graph where every vertex is directly
c) The total cost of the project connected to every other vertex is called:
d) The maximum number of nodes in the graph a) Complete graph b) Directed graph
(Correct answer: b) c) Weighted graph d) Acyclic graph
29. In a directed graph, the in-degree of a node is: (Correct answer: a)
a) The number of edges pointing to the node
Two-Marks Questions
Five-Marks Questions
Ten-Marks Questions