| | | | | |

Ordered Set/Map Runtime

Worst Case Runtimes for Ordered Set Operations

Operation     OList     OVector     BST*     Balanced BST**    
Insert(t) O(n) O(n) O(n) O(log n)
Includes(t) O(n) Θ(log n) O(n) O(log n)
Retrieve(&t) O(n) Θ(log n) O(n) O(log n)
Put(t) O(n) O(n) O(n) O(log n)
Get(t) O(n) O(n) O(n) O(log n)
LowerBound(t)     O(n)Θ(log n) O(n)O(log n)
UpperBound(t) O(n)Θ(log n) O(n)O(log n)
Remove(t) O(n) O(n)    
Erase(t) O(n) Θ(log n) O(n) O(log n)
Rehash()   O(n2) O(n2) O(n log n)
Traversal Θ(n) Θ(n) Θ(n) Θ(n)

(n = size of set)
 
Worst Case Runtimes for Ordered Table Operations

Operation     OList     OVector     BST*     Balanced BST**    
Insert(k,d) O(n) O(n) O(n) O(log n)
Includes(k) O(n) Θ(log n) O(n) O(log n)
Retrieve(k,&d) O(n) Θ(log n) O(n) O(log n)
Put(k,d) O(n) O(n) O(n) O(log n)
Get(k) O(n) O(n) O(n) O(log n)
LowerBound(k)     O(n)Θ(log n) O(n)O(log n)
UpperBound(k) O(n)Θ(log n) O(n)O(log n)
Remove(k) O(n) O(n)    
Erase(k) O(n) Θ(log n) O(n) O(log n)
Rehash()   O(n2) O(n2) O(n log n)
Traversal Θ(n) Θ(n) Θ(n) Θ(n)

(n = size of table)

Notes

  1. *If BST inserts data in random order, search times are reduced to O(log n).
  2. **Left-Leaning Red-Black Tree | Red-Black Tree | AVL Tree.
  3. OList - no reason ever to use
  4. OVector - respectable when most operations are searches!
  5. To get guaranteed logarithmic insert time, full power of balanced tree insert is required.
  6. Rehash() constructs a new tree without tombstones.
  7. Traversal = Θ(n) implies Iterator operations = amortized Θ(1)

| | Top of Page | 4. Data Structure Algorithms - 3 of 6