How many permutations of a given array result in BST's of height 2?

后端 未结 3 1503
旧巷少年郎
旧巷少年郎 2021-02-06 11:48

A BST is generated (by successive insertion of nodes) from each permutation of keys from the set {1,2,3,4,5,6,7}. How many permutations determine trees of height two?

I

3条回答
  •  星月不相逢
    2021-02-06 12:14

    I've created a table for the number of permutations possible with 1 - 12 elements, with heights up to 12, and included the per-root break down for anybody trying to check that their manual process (described in other answers) is matching with the actual values.

    http://www.asmatteringofit.com/blog/2014/6/14/permutations-of-a-binary-search-tree-of-height-x

提交回复
热议问题