Manipulate
1008. Construct Binary Search Tree from Preorder Traversal
Medium·
1
Iterative Insertion
O(n²)
O(n)
FIG. CONSTRUCT BST FROM PREORDER● INTERACTIVE
visualization loads as you reach it
- Time
- O(n²)
putIntoTreeis called once for each of then - 1remaining values, and each call walks fromrootdown to a leaf - up toO(n)steps for a skewed BST (e.g. a strictly ascending or descendingpreorder) - givingO(n²)overall.- Space
- O(n)
- The constructed tree holds all
nnodes (rootplus onenew_nodeper value).
897. Increasing Order Search Tree
Easy·
2 Approachesclick to switch
1
Recursive (Create new tree)
O(n)
O(n)
2
Recursive (In-place)
O(n)
O(h)
FIG. INCREASING ORDER SEARCH TREE● INTERACTIVE
visualization loads as you reach it
- Time
- O(n)
recursionperforms an in-order visit of every one of thennodes exactly once.- Space
- O(n)
- A brand-new
TreeNode(node.val)is allocated for each of thenvalues, on top of a recursion call stack of up tohframes (h <= n).