Why Hash Map Exists and What Problem It Solves
📖 Scenario: Imagine you have a big box of keys and you want to find the right key quickly to open a door. Searching one by one takes too long. A hash map is like a magic box that helps you find the right key fast.
🎯 Goal: You will create a simple program that stores and finds phone numbers by names using a hash map concept. This will show why hash maps exist and how they solve the problem of slow searching.
📋 What You'll Learn
Create an array of strings called
names with these exact entries: "Alice", "Bob", "Charlie"Create an array of integers called
phone_numbers with these exact entries: 12345, 67890, 54321Create an integer variable called
size and set it to 3Write a function called
find_phone_number that takes char* name, char* names[], int phone_numbers[], and int size and returns the phone number for the given name or -1 if not foundUse a
for loop with variable i to search through names inside find_phone_numberPrint the phone number for
"Bob" using find_phone_number💡 Why This Matters
🌍 Real World
Hash maps help apps like phonebooks, contact lists, and databases find information fast without checking every item.
💼 Career
Understanding hash maps is key for software developers to write efficient code for searching and storing data.
Progress0 / 4 steps
