This earlier question asked how many ways there were to insert the values 1 - 7 into a binary search tree that would result in the following tree:
4
This is an interesting question. I implemented this idea in python and this recursion plus memorization has pretty good performance. The "seq" is the input list of unique integers
def answer(seq):
from math import factorial
BStore = dict() # store binomsial coefficient
Store = dict() # store the recusion step
def TreeGenerator(a,L): # for a given number a and a list L, this functions returns the left tree (a list) and the right tree (a list)
LT = []
RT = []
for i in L:
if i