Stacks and Queues Flashcards
does a stack operate by lifo or fifo
lifo
does a queue operate by lifo or fifo
fifo
sample of API for stacks
public class Stack()
Stack() = constructor to make an empty stack void push(int number) int pop() boolean isEmpty() int size()
where are the two locations that can the hold the top of stack
head
tail
if the top of the stack is at the head of the list, what is the running time for the push operation
big theta (1)
just change the next, prev and head pointers (all constant time)
if the top of the stack is at the head, what is the running time for push
big theta (1)
just move top of stack refernce
if the top of stack is at the bottom of the list, what is the run time of the push function
big theta (1)
if the top of the stack is at the bottom of the list, what is the run time for pop
big theta (N)
the temp pointer has to move from the beginning to the end to find the top of the stack
for maximum efficiency, where should the top of the stack be
the first element in the list
how much memory does a stack with N nodes take up
40N bytes
what does the memory for each element in a stack include
reference to node
reference to data in node
object overhead
what is loitering
holding a reference to an object that is no longer needed
when there is overflow in an array, it should be
resized
when there is underflow in an array
an exception must be thrown
why is creating a new array each time the size gets altered expenisve
array must be made
all elements must be copied over