Trading Space for Time: List to Tree
Given:
- Data: N = {i : i < k}, k is known & fixed
- Required procedures: sorted insert, delete, search
Linked list: all procedures O(n), space O(n), where n = |N|.
Balanced tree with additional invariants {values in left subtree < root, right subtree > root): procedures are O(logn), space is O(n).
NOTE: space is still O(n) but tree requires twice as much space for pointers; on a fixed size medium, can represent about half as much data (in practical terms, the constants can matter).