Collections Big O Flashcards
Which ArrayList
methods are guaranteed to run in constant time and which methods are guranteed to run in amortized constant time?
get
set
add
remove
Constant time:
1. get
2. set
Amortized constant time:
1. add
2. remove
Is ArrayDeque
likely to be faster than Stack
when used as a stack and faster than LinkedList
when used as a queue?
Yes
Which methods are not guaranteed to run in amortized constant time for an ArrayDeque
?
remove(obj)
, contains(obj)
, and the like, which run in linear time
Which HashSet<E>
methods guarantee constant time performance assuming the hash function disperses the elements properly among the buckets?
add()
remove()
contains()
Which TreeSet<E>
methods guarantee log(n)
time performance?
add()
remove()
contains()
Which HashMap<K, V>
methods are guaranteed constant time performance assuming the hash function disperses the elements properly among the buckets?
get
containsKey
put
replace
remove
Which TreeMap<K, V>
methods guarantee log(n)
time performance?
get
put
containsKey
remove
replace