Week 3 Flashcards
How does the resize() method work?
It allocates a new array B, with size 2n and copies the original elements into the first n positions in b
How long does resize() take?
O(n)
How does adding elements trigger a resize()?
If the array is full and we want to add another element
How does removing elements trigger a resize()?
We remove an element and the array becomes 2/3 empty
How many add or remove operations does there at least have to be before a resize can happen?
at least n/2 add or remove operations since the preceding resize
Why is ArrayStack not a good choice of implementation for a FIFO queue?
ArrayStack would require frequent shifting
What does ArrayDeque efficiently do?
Allows for addition and removal at both ends