Skip to content

Category Archives: Binary Search Tree

Given preorder traversal of a binary search tree, construct the BST. For example, if the given traversal is {10, 5, 1, 7, 40, 50}, then… Read More
Two of the nodes of a Binary Search Tree (BST) are swapped. Fix (or correct) the BST.  Input Tree: 10 / \ 5 8 /… Read More
Given Preorder traversal of a BST, check if each non-leaf node has only one child. Assume that the BST contains unique entries. Examples   Input: pre[]… Read More
Given a Binary Tree, convert it to a Binary Search Tree. The conversion must be done in such a way that keeps the original structure… Read More
Given two Binary Search Trees(BST), print the elements of both BSTs in sorted form. The expected time complexity is O(m+n) where m is the number… Read More
You are given two balanced binary search trees e.g., AVL or Red-Black Tree. Write a function that merges the two given balanced BSTs into a… Read More
AVL tree is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be more than one for… Read More
Given a Binary Tree, write a function that returns the size of the largest subtree which is also a Binary Search Tree (BST). If the… Read More
Given a sorted array. Write a function that creates a Balanced Binary Search Tree using array elements.Examples:   Input: Array {1, 2, 3} Output: A Balanced… Read More
Given a Singly Linked List which has data members sorted in ascending order. Construct a Balanced Binary Search Tree which has same data members as… Read More
Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Print all the keys of the… Read More
Given the root of a binary search tree and K as input, find Kth smallest element in BST. For example, in the following BST, if k… Read More
In Binary Tree, Inorder successor of a node is the next node in Inorder traversal of the Binary Tree. Inorder Successor is NULL for the… Read More
Given an array that stores a complete Binary Search Tree, write a function that efficiently prints the given array in ascending order. For example, given an… Read More
Total number of possible Binary Search Trees with n different keys (countBST(n)) = Catalan number Cn = (2n)! / ((n + 1)! * n!) For n… Read More

Start Your Coding Journey Now!