Tag Archives: question

Construct Binary Search Trees from keys 1 to n Problem statement to construct a Binary Search Tree(BST) from keys 1 to n. We are given a list of consecutive numbers from 1 to . Determine the number of binary trees that can be constructed from these numbers. Example for building a Binary Search Tree from keys… Read More »

Second largest element in Binary Search Tree (BST). Problem statement to find the second largest element in a Binary Search Tree (BST) Given a binary search tree, determine its second largest element. In inorder traversal, the second last element is the second largest while in reverse inorder traversal, the second element is second largest element. Example:… Read More »

Create a BST such that sum of all greater keys is added to its every key. Problem statement to construct a Binary Search Tree (BST) such that sum of all greater keys is added to its every key: Given a balanced binary search tree (BST), build a binary search tree such that all nodes in original… Read More »

Floor and Ceil in a Binary Search Tree Problem statement to find Floor and Ceil in a Binary Search Tree (BST). In mathematics and computer science, the floor and ceiling functions map a real number to the largest previous or the smallest following integer, respectively. More precisely, floor(x) = is the largest integer not greater than… Read More »

Fix binary search tree with 2 swapped nodes Problem statement to fix binary search tree (BST) with two swapped nodes. We are given a binary search tree (BST) where exactly two nodes are swapped. The aim is to output the corrected BST. Example for a binary search tree where two nodes are interchanged: Input: 7… Read More »

Triplets in a Binary Search Tree that sum to zero. Problem statement to find three numbers in a binary search tree that sum to zero: Given a balanced binary search tree (BST), determine if there exist three numbers that add up to zero.If they exist, output YES. Example for testing if 3 numbers in a BST… Read More »