about summary refs log tree commit diff
path: root/go
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-11-21T16·15+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-11-21T16·15+0000
commit60d7ea5b91c8f6bc8005af82be623fc0a3e0144d (patch)
tree564fa4009c182fe160fd3e645d0967cbec278013 /go
parent417d3b5fffc081e650ecf16b7f1f14f4fa7c70dd (diff)
Implement a queue using two stacks
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) |
+------------+----------------------------+------+
Diffstat (limited to 'go')
0 files changed, 0 insertions, 0 deletions