7.1Binary Search Trees: Definition, Search and Insertion
Covers IGNOU MCS-208 §7.2, 7.2.1, 7.2.2
A binary search tree (BST) keeps keys in order so that a search can discard half of the remaining tree at each step, as binary search does in a sorted array. This page gives the exact definition and the basic operations.
Definition
Traversals
A BST is a binary tree, so it has the three traversals of Unit 6. For the BST of Figure 7.1 (root K; K’s children J and S; J’s left child F, whose right child is G; S’s children M and U; M’s children L and P):
preorder: K J F G S M L P U
inorder: F G J K L M P S U (always sorted for a BST)
postorder: G F J L P M U S K
Searching, minimum and maximum
Search for k: start at the root; if k equals the key, stop; if smaller, go left; if larger, go right; reaching NULL means “not found”.
Minimum: follow left links until there is no left child. Maximum: follow right links.
Each takes at most h steps, where h is the height of the tree.
Insertion
To insert k, search for it; when the search falls off the tree at a NULL link, put a new node there. A new key always becomes a leaf. For example, inserting 5 into the tree 10(7(3), 15) goes 10 → 7 → 3 → right of 3, so 5 becomes the right child of 3.
Why height matters
All these operations are O(h). A BST built from random keys has expected height O(logn), but inserting keys in sorted order produces a chain of height n, and every operation becomes O(n). The rest of this unit is about trees that prevent this.
Key takeaways
BST: left subtree < node < right subtree, for every node.
Inorder traversal of a BST lists the keys in sorted order.
Search, insert, min, max: one root-to-leaf path, O(h).
Sorted input makes a plain BST degenerate into a chain of height n.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Define a binary search tree and write a recursive algorithm to insert a key into it.
Show worked answer
A BST is a binary tree that is either empty or whose root key is larger than every key in its left subtree and smaller than every key in its right subtree, both subtrees being BSTs. Insert(t, k): if t is NULL, create a node with key k and return it; if k < t.key, set t.left = Insert(t.left, k); else if k > t.key, set t.right = Insert(t.right, k); (if k = t.key the key is already present); return t. The new key becomes a leaf; the cost is O(h).
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-208/advanced-trees/binary-search-trees-definition-search-and-insertion/ to read this page.