Chapter Review Questions#
LIFO.
What does LIFO stand for?
Which data structure follows LIFO order?
FIFO.
What does FIFO stand for?
Which data structure follows FIFO order?
Why is
collections.dequepreferred over a plain Python list for implementing a queue?Stacks with Python lists.
When using a Python list as a stack, which end is the “top” — index 0 or the last index?
Which list methods correspond to push and pop?
Write code to push the values 1, 2, 3 onto a stack, then pop and print each value. What order do they print in?
What does
Nonerepresent in a singly linked list?Trace what happens to the
headpointer when you callprependon an empty linked list, then call it again on the resulting one-element list.Index access performance.
What is the time complexity of index access (
lst[i]) for a Python list?What is it for a linked list?
Why do they differ?
Given the linked list
5 -> 10 -> 20 -> None, show the state after callingremove(10).Trade-offs between linked lists and Python lists.
Name one situation where a linked list has a performance advantage.
Name one situation where a Python list is faster.