Data Structures 4 Flashcards
A stack s, a queue q, and a max value priority queue p each have a single 3 in them. Next s.push(4), q.push(4), and p.push(4) are executed.
What is the triple (s.pop(), q.pop(), p.pop())?
(4,3,4)
This stack reads left to right with the top to the right:
‘green’
‘yellow’
‘blue’
‘red’
What could be the stack after a push operation?
[‘red’,’blue’,’yellow’, ‘green’, ‘purple”]
Items were added sequentially onto the stack starting with ‘red’:
‘green’
‘yellow’
‘blue’
‘red’
What is the stack after a pop operation?
‘yellow’
‘blue’
‘red’
Which command helps to speed up comparisons using dictionary keys during a dictionary (d) lookup in this pseudocode clip?
h = hash(key)
for pair in d:
if h == pair[0]:
return pair[1]
hash(object)
What does the method any(b) return in Python if b is a dictionary?
Returns True if any key of the dictionary is true.
Which Java method is used to read bytes from a standard file?
Java.io.FileInputStream
Which command will retrieve an item from the top of the stack?
Pop()
Which command will insert object x at position index in a list?
Add(int index, Object x)
Which command will return true if x is in a list, otherwise return false?
Contains(Object x)
When should a dictionary be used instead of a list?
When the program uses key-value pairs as its data