Q. What is the time complexity of deleting an element from a binary search tree (BST) in the average case?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Solution
In the average case, deleting an element from a balanced binary search tree takes O(log n) time, as it requires finding the element and then restructuring the tree.
Q. What is the time complexity of finding the shortest path in an unweighted graph using BFS?
A.
O(n)
B.
O(n^2)
C.
O(m + n)
D.
O(log n)
Solution
Breadth-first search (BFS) explores all vertices and edges, resulting in a time complexity of O(m + n), where m is the number of edges and n is the number of vertices.