Algorithms and Data Structures · Junior · Question 51 of 75

What happens if you insert the values 1, 2, 3, 4, 5 in order into a simple (non-balancing) BST?

Explanation

Each new value is larger than all previous ones and goes to the right, so the tree turns into a linked list. Self-balancing trees (AVL, red-black) rotate nodes to keep the height O(log n).

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 51

Test yourself

Take the Algorithms and Data Structures · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz