60d7ea5b91
The space cost is O(n). The runtime cost of enqueue is O(1); the runtime cost of dequeue is O(n). Using the "accounting method", the cost of an item in the system is O(1). Here's why: +------------+----------------------------+------+ | enqueue | push onto lhs | O(1) | +------------+----------------------------+------+ | lhs -> rhs | pop off lhs; push onto rhs | O(1) | +------------+----------------------------+------+ | dequeue | pop off rhs | O(1) | +------------+----------------------------+------+ |
||
---|---|---|
.. | ||
bst-checker.py | ||
linked-list-cycles.py | ||
merge-sorted-arrays.py | ||
nth-fibonacci.py | ||
queue-two-stacks.py |