Category Archives: Trees

Construct all possible BSTs for keys 1 to N

In this article, first count of possible BST (Binary Search Trees)s is discussed, then construction of all possible BSTs. How many structurally unique BSTs for keys from 1..N? For example, for N = 3, there are 2 unique BSTs 1 2 \ / 2 1 For N = 3, there are 5 possible BSTs 1… Read More »

Diagonal Sum of a Binary Tree

Consider lines of slope -1 passing between nodes (dotted lines in below diagram). Diagonal sum in a binary tree is sum of all node’s data lying between these lines.