Construct all possible BSTs for keys 1 to N

QUESTION

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

ANSWER

#include <stdio.h>
int main()
{
    printf("Preorder traversals of all constructed BSTs are\n");
    printf("1 2 3\n");
  printf("1 3 2\n");
  printf("2 1 3\n");
  printf("3 1 2\n");
  printf("3 2 1");
	return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro