Hash Maps and Sets

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

1/6

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:29 PM on 6/8/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

7 Terms

1
New cards

Creating Hashmap

unordered_map<int, int> freq;

2
New cards

Count Numbers

unordered_map<int, int> freq;

for (int i = 0; i < n; i++) {

int x;

cin >> x;

freq[x]++;

}

3
New cards

Get Count of a Number

cout << freq[x];

4
New cards

Loop Through Hash Map

for (auto item : freq) {

cout << item.first << " " << item.second << "\n";

}

5
New cards

Most common

std::unordered_map<int, int> counts; int max_freq = 0; int most_common = -1; for (int num : vec) { counts[num]++; if (counts[num] > max_freq) { max_freq = counts[num]; most_common = num;

6
New cards

Insert Into Set

name.insert(x);

7
New cards

Check If Something Exists

if (seen.count(x))