ET210x: Data Structures & Algorithms
Đào Trung Kiên @ MICA Institute & Dept. of Comm. Eng., SEEE, Hanoi Univ. of Science and Technology
Weeks 11+12: Maps
& Hash Functions
Map (dictionary) data structure
Hash functions
Probing
1
ET210x: Data Structures & Algorithms
Đào Trung Kiên @ MICA Institute & Dept. of Comm. Eng., SEEE, Hanoi Univ. of Science and Technology
Overview
Arrays are integer indexed
How to generalize with different index types?
Pairs of <𝑘𝑒𝑦, 𝑣𝑎𝑙𝑢𝑒> where 𝑘𝑒𝑦 and 𝑣𝑎𝑙𝑢𝑒 can be of
any types
2
KEYS VALUES
Jan
327.2
Feb
368.2
Mar
197.6
Apr
178.6
May
100.0
Jun
69.9
Jul
32.3
Aug
37.3
Sep
19.0
Oct
37.0
Nov
73.2
Dec
110.9
Aug 37.3
ET210x: Data Structures & Algorithms
Đào Trung Kiên @ MICA Institute & Dept. of Comm. Eng., SEEE, Hanoi Univ. of Science and Technology
Terminology
These terms may share the same similarities in
different programming languages or libraries:
Map (C++, Java, Matlab)
Dictionary (C#, Python)
Associative array (JavaScript, PHP)
Lookup table (C#, Lua)
Hash table (Ruby)
Maps are generally single valued (one key one
value)
Multi-valued maps can be considered as exercise
3
ET210x: Data Structures & Algorithms
Đào Trung Kiên @ MICA Institute & Dept. of Comm. Eng., SEEE, Hanoi Univ. of Science and Technology
String-key dictionary
4
ET210x: Data Structures & Algorithms
Đào Trung Kiên @ MICA Institute & Dept. of Comm. Eng., SEEE, Hanoi Univ. of Science and Technology
Introduction
A special type but frequently used map data structure
Mapping from string keys to other value types
Main operations:
Insert elements
Remove elements
Find elements with their keys
Applications:
Address book
Dictionary
Data lookup
5