Computer Science I / Trees and Hierarchical Storage
Practice question · True or false

Inserting 1, 2, 3, 4, 5, 6, 7, 8 into an empty binary search tree in that order produces a tree of height 8 that behaves like a linked list.

Hints
  1. Each new value is larger than everything already in the tree.
  2. Where does a larger value always go?
Show the answer

True

Why

True. Every insertion goes right, so the tree degenerates into a right spine, search becomes O(n), the exact cost a BST exists to avoid. Sorted input is the worst case, and it is a common one. Self-balancing trees (AVL, red-black) exist precisely to rotate this back to O(log n).

Read the lesson: Trees and Hierarchical Storage →

Practise Trees and Hierarchical Storage

The app has 5 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.

More questions on Trees and Hierarchical Storage