Sets and Maps

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/31

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:39 PM on 4/22/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

32 Terms

1
New cards

what is a set?

a collection of unique elements with no duplicates

2
New cards

how do you check is an element is in a set?

set.contains(element)

3
New cards

can sets store duplicate values?

no

4
New cards

do sets support indexing like lists?

no

5
New cards

key operations of a set?

add, remove, contains, size, isEmpty

6
New cards

when should you use a set?

when you need fast lookup and no duplicates

7
New cards

what is a limitation of sets compared to lists?

cannot access elements by position

8
New cards

what is a map?

a collection that stores key-value pairs

9
New cards

what is the purpose of a key in a map?

to uniquely identify and retrieves its associated value

10
New cards

can a map have duplicate keys?

no

11
New cards

what happens if you call get(key) and the key does not exist?

returns null

12
New cards

how do you insert into a map?

map.put(key, value)

13
New cards

how do you check if a key exists?

map.containsKey(key)

14
New cards

What is more efficient: containsKey + get OR just get?

just get (avoids double lookup)

15
New cards

how do you remove an entry from a map?

map.remove(key)

16
New cards

how do you iterate over keys?

for (K key: map.keySet())

17
New cards

how do you iterate over key-value pairs efficiently?

for (Map.Entry<K,V> e : map.entrySet())

18
New cards

what does entrySet() return?

a set of key-value pairs

19
New cards

what does values() return?

a collection of all values in the map

20
New cards

what is a multimap?

a map where one key can have multiple values

21
New cards

does Java support multimaps directly?

no

22
New cards

how do you implement a multimap in Java?

use Map<K, List<V>>

23
New cards

what is the key pattern for adding to a multimap?

  1. get list

  2. if null → create list

  3. add value

24
New cards

what does modifying the list affect the map?

because the list reference is stored in the map

25
New cards

what does the mimic program do?

generates text based on patterns from a sample document

26
New cards

what data structure stores sentence starters?

ArrayList<String>

27
New cards

what data structure stores word relationships?

Map<String, ArrayList<String>>

28
New cards

what does the followers map represent?

a word mapped to all words that followed it in the text

29
New cards

how is the next word generated?

randomly chosen from the list of followers

30
New cards

what happens if a word has no followers?

pick a random sentence starter

31
New cards

why keep punctuation and capitalization?

to make generated text look more realistic

32
New cards

what algorithm concept is this mimic model similar to?

a simple Markov chain