Category Archives: Binary Search Tree

Binary Search Tree insert with Parent Pointer

We have discussed simple BST insert. How to insert in a tree where parent pointer needs to be maintained. Parent pointers are helpful to quickly find ancestors of a node, LCA of two nodes, successor of a node, etc. In recursive calls of simple insertion, we return pointer of root of subtree created in a… Read More »

Maximum element between two nodes of BST

Given an array of N elements and two integers A, B which belongs to the given array. Create a Binary Search Tree by inserting element from arr[0] to arr[n-1]. The task is to find the maximum element in the path from A to B. Examples: Input : arr[] = { 18, 36, 9, 6, 12,… Read More »

Print Common Nodes in Two Binary Search Trees

Given two Binary Search Trees, find common nodes in them. In other words, find intersection of two BSTs. Example: We strongly recommend you to minimize your browser and try this yourself first. Method 1 (Simple Solution) A simple way is to one by once search every node of first tree in second tree. Time complexity… Read More »