0% found this document useful (0 votes)
19 views9 pages

Map Adt

DSA

Uploaded by

perewa7600
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views9 pages

Map Adt

DSA

Uploaded by

perewa7600
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

MAP ADT

Dr. CHANDRALEKHA M
ASSISTANT PROFESSOR
DEPT. OF CSE (CYS)
AMRITA SCHOOL OF COMPUTING, CHENNAI CAMPUS
Mob. No: +91 9442414745
• The map is an abstract data type that contains a collection of records.
• It is an interface, that states what all operations can be performed, but not
their implementation.
• Every record of a map contains a key and a value.
• The property of the map is such that every value can be accessed or
retrieved with the help of a key.
• This means that every key is associated with a value. It is very important to
note that every key in the map has to be unique.
• Values can be duplicated but the keys have to be unique every time.
• In various programming languages, maps have different names for
their implementation.
Look at the example below:
✓C++:unordered_map, multimap, hash_map,etc. are the implementations.
✓Python: dictionaries.
✓Java: HashMaps, HashTables.
Operations of Map
Let us now get acquainted with some of the useful operations that one can
perform using a map:
put(key, value): A new key-value pair is added to the map. In case, if the
key already exists in the map then the old value is replaced by the new.
get(key): A key is passed here and with the help of the key we can retrieve
the value which is associated with the given key.
len(): This operation returns the length of the map i.e. the number of key-
value pairs.
del: This operation is used to delete a specific key-value pair from the map.
This is how it is done: del map[key]. The particular key and its associated
value get deleted from the map.
in: This operation returns a boolean value. It returns true if the given key
exists in the map, else returns false.
Uses of Map
In the following situations, a map abstract data type is ideal to use:
• Marks of a student by his/her student id.
• Tax data by social security number.
• Salary of an employee by his/her staff id.
• Motorbike owner by owner’s license plate.
• Maps are highly used to count frequency as well.
For example:
• Count the duplicate numbers in an array.
• Here a map can be used where the key would be the index of the
number and value would be its frequency.
The following table depicts an example of a key-value pair:
In the below table, Roll No. is the key and Name is the value.
So you can see that the value ‘John’ has occurred twice but since their
keys i.e. the Roll No. are different, they can be stored and identified by
the map.
So from the above example, it is clear that we only need the key to
access or remove any value.
An important fact about the map to be known is that it is not mandatory
to have the key and value of the same data type.
The map allows us to use different data types for key and value
respectively.
THANK YOU ☺

You might also like