为了生成这个二叉搜索树,Farmer John 从一个 的排列 开始,然后以参数 和 开始运行如下的伪代码:
generate(l,r):
if l > r, return empty subtree;
x = argmin_{l <= i <= r} a_i; // index of min a_i in {a_l,...,a_r}
return a BST with x as the root,
generate(l,x-1) as the left subtree,
generate(x+1,r) as the right subtree;