public static BinaryTreeNode buildBST(int[] keys){
Arrays.sort(keys);return sortedBuildBST(keys,0,keys.length-1);}public static BinaryTreeNode sortedBuildBST(int[] keys, int start, int end){if(start > end){return null;}int mid = (start+end)/2;BinaryTreeNode node = new BinaryTreeNode(keys[mid]);node.left = sortedBuildBST(keys,start,mid-1);node.right = sortedBuildBST(keys,mid+1, end);return node;}
Analyze the run time and prove that the constructed BST is no deeper than 1+log2n levels.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here