AlgoFrames

Insert a sequence

Warm-up · Trace the algorithm · about 6 min

The keys 5, 8, 3, 7, 1, 9, 4 are inserted into an empty binary search tree in that order. Answer each question before the step plays.

Example 1

Input:

[[5,8,3,7,1,9,4]]

Output:

[5,3,8,1,4,7,9]

The final tree in level order.

Constraints

  • Each key goes to the end of its search path
  • No rebalancing happens

Learn the idea first: BST: search, insert, min and max, a visual lesson.

More BST: search, insert, min and max problems