Data Structures 4 Flashcards

1
Q

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())?

A

(4,3,4)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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?

A

[‘red’,’blue’,’yellow’, ‘green’, ‘purple”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Items were added sequentially onto the stack starting with ‘red’:
‘green’
‘yellow’
‘blue’
‘red’

What is the stack after a pop operation?

A

‘yellow’
‘blue’
‘red’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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]

A

hash(object)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the method any(b) return in Python if b is a dictionary?

A

Returns True if any key of the dictionary is true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which Java method is used to read bytes from a standard file?

A

Java.io.FileInputStream

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which command will retrieve an item from the top of the stack?

A

Pop()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which command will insert object x at position index in a list?

A

Add(int index, Object x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which command will return true if x is in a list, otherwise return false?

A

Contains(Object x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When should a dictionary be used instead of a list?

A

When the program uses key-value pairs as its data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly