| | | | | |

Runtime Complexity of Iterator Operations

Definition. An Iterator-Defined Traversal of the data structure b is the following loop:

for (Iterator i = b.Begin(); i != b.End(); ++i) { /* whatever */ }

Theorem 1. Using Navigator-Based Iterators, the Iterator-Defined traversal loop makes exactly 2*size edge steps.

Corollary. Navigator-based Iterator operations have amortized constant runtime.

Theorem 2. Each Thread-Based Iterator operation has runtime bounded above by the runtime of the corresponding Navigator-Based Iterator operation.

Corollary. Thread-based Iterator operations have amortized constant runtime.

Theorem 3. Using ADT-Based Iterators, the Iterator-Defined traversal loop makes exactly 2*size Push/Pop operations.

Corollary. ADT-Based Iterator operations have amortized constant runtime, with the exception of destructors and copy operations, which are required to traverse the data structure [stack or queue] owned by the iterator object.

Theorem 4. Navigator- and Thread-Based Iterators require +Θ(1) space. Stack-Based Iterators require +Θ(h) space, and Queue-Based Iterators require +Θ(w) space, where h is the tree height and w is the tree width.


| | Top of Page | 14. BST Iterators - 40 of 41