Collections Big O Flashcards

1
Q

Which ArrayList methods are guaranteed to run in constant time and which methods are guranteed to run in amortized constant time?

  1. get
  2. set
  3. add
  4. remove
A

Constant time:
1. get
2. set

Amortized constant time:
1. add
2. remove

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

Is ArrayDeque likely to be faster than Stack when used as a stack and faster than LinkedList when used as a queue?

A

Yes

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

Which methods are not guaranteed to run in amortized constant time for an ArrayDeque?

A

remove(obj), contains(obj), and the like, which run in linear time

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

Which HashSet<E> methods guarantee constant time performance assuming the hash function disperses the elements properly among the buckets?

A
  1. add()
  2. remove()
  3. contains()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which TreeSet<E> methods guarantee log(n) time performance?

A
  1. add()
  2. remove()
  3. contains()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which HashMap<K, V> methods are guaranteed constant time performance assuming the hash function disperses the elements properly among the buckets?

A
  1. get
  2. containsKey
  3. put
  4. replace
  5. remove
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which TreeMap<K, V> methods guarantee log(n) time performance?

A
  1. get
  2. put
  3. containsKey
  4. remove
  5. replace
How well did you know this?
1
Not at all
2
3
4
5
Perfectly