1/31
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
what is a set?
a collection of unique elements with no duplicates
how do you check is an element is in a set?
set.contains(element)
can sets store duplicate values?
no
do sets support indexing like lists?
no
key operations of a set?
add, remove, contains, size, isEmpty
when should you use a set?
when you need fast lookup and no duplicates
what is a limitation of sets compared to lists?
cannot access elements by position
what is a map?
a collection that stores key-value pairs
what is the purpose of a key in a map?
to uniquely identify and retrieves its associated value
can a map have duplicate keys?
no
what happens if you call get(key) and the key does not exist?
returns null
how do you insert into a map?
map.put(key, value)
how do you check if a key exists?
map.containsKey(key)
What is more efficient: containsKey + get OR just get?
just get (avoids double lookup)
how do you remove an entry from a map?
map.remove(key)
how do you iterate over keys?
for (K key: map.keySet())
how do you iterate over key-value pairs efficiently?
for (Map.Entry<K,V> e : map.entrySet())
what does entrySet() return?
a set of key-value pairs
what does values() return?
a collection of all values in the map
what is a multimap?
a map where one key can have multiple values
does Java support multimaps directly?
no
how do you implement a multimap in Java?
use Map<K, List<V>>
what is the key pattern for adding to a multimap?
get list
if null → create list
add value
what does modifying the list affect the map?
because the list reference is stored in the map
what does the mimic program do?
generates text based on patterns from a sample document
what data structure stores sentence starters?
ArrayList<String>
what data structure stores word relationships?
Map<String, ArrayList<String>>
what does the followers map represent?
a word mapped to all words that followed it in the text
how is the next word generated?
randomly chosen from the list of followers
what happens if a word has no followers?
pick a random sentence starter
why keep punctuation and capitalization?
to make generated text look more realistic
what algorithm concept is this mimic model similar to?
a simple Markov chain