CUET PG 2025 — Computer PYQ
CUET PG | Computer | 2025In case of Binary search tree which of the following procedure's running time is distinct among all
Choose the correct answer:
- A.
TREE-SUCCESSOR (finds successor of the given node)
- B.
TREE-MAXIMUM (finds the node with maximum value)
- C.
INORDER-WALK (prints all elements of a tree in inorder manner)
(Correct Answer) - D.
TREE-MINIMUM (finds the node with minimum value)
INORDER-WALK (prints all elements of a tree in inorder manner)
Explanation
Understanding BST Procedure Running Times
In a Binary Search Tree (BST), different operations have varying time complexities based on the tree's structure and the nature of the operation. The question asks us to identify which procedure among the given options has a distinct running time. Let's analyze the time complexity of each procedure.
Analyzing Running Times of BST Operations
We need to consider the typical time complexities for these operations in a Binary Search Tree. Let 'nn' be the number of nodes in the tree and 'hh' be the height of the tree.
- TREE-SUCCESSOR: This procedure finds the node with the smallest key greater than a given node's key. This typically involves moving up the tree or down the right subtree. Its time complexity is proportional to the height of the tree, which is O(h)O(h) in the worst case.
- TREE-MAXIMUM: This procedure finds the node with the largest key in the subtree rooted at a given node. It involves traversing down the right child pointers until a node with no right child is found. The time complexity is also proportional to the height of the tree, O(h)O(h) in the worst case.
- TREE-MINIMUM: Similar to `TREE-MAXIMUM`, this procedure finds the node with the smallest key in the subtree rooted at a given node. It involves traversing down the left child pointers. The time complexity is also proportional to the height of the tree, O(h)O(h) in the worst case.
- INORDER- WALK: This procedure prints all elements of the tree in inorder manner, which means printing them in ascending sorted order. To achieve this, every node in the tree must be visited exactly once. Therefore, its time complexity is directly proportional to the number of nodes in the tree, which is O(n)O(n).
Comparing BST Operation Complexities
Now, let's compare the complexities:
In a balanced BST, the height 'hh' is approximately lognlogn, so the first three operations run in O(logn)O(logn) time on average. However, in the worst case (a completely skewed tree), the height 'hh' can be equal to 'nn', making the complexity O(n)O(n).
The INORDER- WALK procedure has a time complexity of O(n)O(n) because it must visit every single node in the tree to perform the inorder traversal. This complexity is independent of the tree's height and depends solely on the total number of nodes. This makes INORDER- WALK distinct from the other operations, whose complexities are dependent on the tree's height (O(h)O(h)), which can vary significantly.

