FAQ: Hash Maps: Conceptual - Basic Hash Maps

This community-built FAQ covers the “Basic Hash Maps” exercise from the lesson “Hash Maps: Conceptual”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science

Complex Data Structures

FAQs on the exercise Basic Hash Maps

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

What will we do if for different keys we have same hash value ?

3 Likes

Can someone explain how they go from 8 -->0 , 2–>2 , 3–>3 and 5 -->1 in the text example?

                             Hash         Hash mod 4	     Release Year
People's Instinctive ...     	8	         0              	1990
The Low End Theory	            2	         2	                1991
Midnight Marauders	            3	         3	                1993
Beats, Rhymes and Life	        5	         1	                1996

Nevermind…

I guess I didn’t know that if there wasn’t enough to divide into a number, it would return the number.

2 /4 = 0 with remainder 2. I get it.

If we want to store keys and values. Can’t we just use dictionaries instead of Hash tables? I mean even dictionaries can store one value for one key and it is easier to setup.

8%4 = 0, 2%4 = 2, 3%4 = 3, 5%4 = 1. Hash mod 4, that’s why I think need operation % 4

Yes, the hash must be taken mod (number of bins.)

If you mean Python dictionaries, they are implemented using hash tables already- it’s just that you don’t have to do all that bit because Python did it for you :slight_smile:

I think a mistake was made in this exercise. Following the hashing function of adding up the 'a’s and the 'e’s in the album title, shouldn’t the second album listed," The Low End Theory," give a hash value of 3, not 2?

The Low End Theory

As I was typing my question, I realized the answer. However, I wanted to post it anyway with this reply to help anyone else out that was confused by this. The hash function is literally only counting 'a’s and 'e’s. It is not counting any capital letter 'A’s and 'E’s.

7 Likes

What would happen if two keys generate different hash values but the modulus of their hash value (hash bucket) come out to be the same?

My bad… its covered in the next exercise.

1 Like

@bmw999 @patrickd314
this is the first exercise that I don’t understand the intructions really well. Even the question and answer is already made, concerning , I qoute : Can someone explain how they go from 8 -->0 , 2–>2 , 3–>3 and 5 –
I can figure out : Midnight Marauders 3 - 3 - 1993

I don’t get the Hash mod 3, when dividing 3/4 ? And how can I calculate 3%4 on a calculator? How to get ouput 3? I can not make a simple math out of it. May sound a bit…well anyway appreciate it to get my head simple around it…Thanks!

I get it, I think so ?

Midnight Marauders 3 3 1993
Beats, Rhymes and Life 5 1 1996

4/3= 1,3333’’’ = Rest 3
5/4= 1,25 = 1

% is used as modulo operation, and not the standard division operator. See Modulo operation - Wikipedia for details