GATE Exam  >  GATE Notes  >  Binary Search Tree (BST)

Binary Search Tree (BST) - GATE PDF Download

A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the following sequence of keys.

I. 81, 537, 102, 439, 285, 376, 305
II. 52, 97, 121, 195, 242, 381, 472
III. 142, 248, 520, 386, 345, 270, 307
IV. 550, 149, 507, 395, 463, 402, 270
Q.Suppose the BST has been unsuccessfully searched for key 273. Which all of the above sequences list nodes in the order in which we could have encountered them in the search?
a)II and III only
b)I and III only
c)III and IV only
d)III only
Correct answer is option 'D'. Can you explain this answer?

Ref: https://edurev.in/question/499405/A-Binary-Search-Tree-BST-stores-values-in-the-range37-to-573-Consider-the-following-sequence-of-k

Key to be searched 273:

  • I) 81, 537, 102, 439, 285, 376, 305 is not correct
    We cannot go to 376 from 285 as 273 is smaller than 285.
  • II) 52, 97, 121, 195, 242, 381, 472 is not correct.
    We cannot go to 472 from 381 as 273 is smaller than 381.
  • III) 142, 248, 520, 386, 345, 270, 307 is correct
    2008_71_sol
  • 550, 149, 507, 395, 463, 402, 270 is not correct.
    We cannot go to 463 from 395 in search of 273
The document Binary Search Tree (BST) - GATE is a part of GATE category.
All you need of GATE at this link: GATE

FAQs on Binary Search Tree (BST) - GATE

1. What is a Binary Search Tree (BST)?
Ans. A Binary Search Tree (BST) is a type of binary tree data structure in which each node has a key greater than the keys in its left subtree and less than the keys in its right subtree. It allows efficient searching, insertion, and deletion operations with an average time complexity of O(log n), where n is the number of nodes in the tree.
2. How does the search operation work in a Binary Search Tree (BST)?
Ans. To search for a specific key in a Binary Search Tree (BST), we start from the root node and compare the key with the current node's key. If the key is equal to the current node's key, we have found the desired element. If the key is less than the current node's key, we move to its left subtree. If the key is greater, we move to its right subtree. We repeat this process until we find the desired key or reach a leaf node (null), indicating that the key is not present in the tree.
3. How are elements inserted into a Binary Search Tree (BST)?
Ans. To insert an element into a Binary Search Tree (BST), we compare the key of the new element with the keys of existing nodes starting from the root. If the key is less than the current node's key, we move to its left subtree. If the key is greater, we move to its right subtree. We repeat this process until we reach a leaf node (null). At this point, we create a new node with the given key and attach it as a child to the appropriate position in the tree.
4. What is the time complexity of the insertion operation in a Binary Search Tree (BST)?
Ans. The time complexity of the insertion operation in a Binary Search Tree (BST) depends on the height of the tree. In the average case, when the tree is balanced, the time complexity is O(log n), where n is the number of nodes in the tree. However, in the worst case scenario, when the tree is skewed (all nodes have only left or right children), the time complexity can be O(n), where n is the number of nodes.
5. How can we delete a node from a Binary Search Tree (BST)?
Ans. To delete a node from a Binary Search Tree (BST), we first search for the node to be deleted. Once the node is found, there are three possible cases: 1. If the node has no children, we simply remove it by updating its parent's reference to null. 2. If the node has one child, we replace the node with its child by updating the appropriate reference in its parent. 3. If the node has two children, we find the node with the minimum key in its right subtree (or the maximum key in its left subtree), swap the keys of the two nodes, and then delete the node with the minimum (or maximum) key from the right (or left) subtree, which reduces the problem to one of the previous two cases. The time complexity of the deletion operation in a Binary Search Tree (BST) is also dependent on the tree's height and can be O(log n) in the average case and O(n) in the worst case.
Download as PDF
Explore Courses for GATE exam
Related Searches

Viva Questions

,

Free

,

Objective type Questions

,

study material

,

Binary Search Tree (BST) - GATE

,

Sample Paper

,

MCQs

,

video lectures

,

Extra Questions

,

shortcuts and tricks

,

Previous Year Questions with Solutions

,

practice quizzes

,

Important questions

,

mock tests for examination

,

Binary Search Tree (BST) - GATE

,

ppt

,

Summary

,

pdf

,

past year papers

,

Semester Notes

,

Exam

,

Binary Search Tree (BST) - GATE

;