What is the difference between a map and a dictionary?

A map and a dictionary are the same abstract data type. Both hold key-value pairs, where each key appears once and is used to find its value. The word changes with the language. Python calls it dict, C# calls it Dictionary, and Java and C++ call it a map. JavaScript has both a Map class and plain objects that behave like one. What differs in practice is the implementation underneath, not the name. A hash table gives average O(1) lookup with no key order. A balanced tree gives O(log n) lookup with keys kept sorted. Two languages that share a word can differ on those points, and one language can offer both.

Aspect"Map""Dictionary"
MeaningKey-value collection with unique keysThe same
Languages that use the wordJava, C++, JavaScript, Go, Rust, Scala, KotlinPython, C#, Swift, Objective-C, Visual Basic
Typical backing structureHash table or balanced tree, depending on the classHash table
Lookup costO(1) average for hash-based, O(log n) for tree-basedO(1) average
Key orderDepends on the classInsertion order in Python, unspecified in C#

The Name in Each Language

The table below lists the usual type in each language.

LanguageTypeBacked byKey orderAverage lookup
PythondictHash tableInsertion orderO(1)
JavaHashMap (implements Map)Hash tableNoneO(1)
JavaTreeMap (implements Map)Red-black treeSortedO(log n)
JavaLinkedHashMapHash table plus linked listInsertion orderO(1)
C#Dictionary<TKey, TValue>Hash tableUnspecifiedO(1)
C#SortedDictionary<TKey, TValue>Red-black treeSortedO(log n)
C++std::mapRed-black treeSortedO(log n)
C++std::unordered_mapHash tableNoneO(1)
JavaScriptMapHash tableInsertion orderO(1)
JavaScriptplain object {}Engine-specific; string and symbol keysInteger-like keys first, then insertion orderO(1)
Gomap[K]VHash tableNone, randomizedO(1)
SwiftDictionary<Key, Value>Hash tableNoneO(1)

Python: dict Versus map() and Mapping

In Python, dict is the data structure, map() is a function, and Mapping is an interface. The three words are often confused in search queries, and they name three different things. dict stores key-value pairs in a hash table and, since Python 3.7, keeps insertion order. map(function, iterable) applies a function to every item of an iterable and returns a lazy iterator. It stores nothing and has no keys. collections.abc.Mapping is the abstract base class that dict implements. A type hint reads Mapping[str, int] when any read-only dictionary-like object is acceptable.

from collections.abc import Mapping prices = {"apple": 3, "pear": 2} # dict: the data structure doubled = list(map(lambda p: p * 2, prices.values())) # map(): a function, gives [6, 4] print(isinstance(prices, Mapping)) # True: dict is a Mapping

Java: Map, HashMap, and the Old Dictionary Class

In Java, Map is the interface and HashMap is the usual implementation. Map declares put, get, containsKey, and remove. HashMap implements them with a hash table and allows one null key. TreeMap keeps keys sorted and is the choice when you need the smallest key or a range. Java also has a class literally named java.util.Dictionary, with its subclass Hashtable. Both date from the first release of Java, are marked obsolete in the documentation, and should not be used in new code. When a Java question mentions a dictionary, the answer is a Map.

C++: std::map Versus std::unordered_map

C++ has no type called dictionary; it has two maps with different guarantees. std::map is a red-black tree, so iteration visits keys in sorted order and every operation costs O(log n). std::unordered_map is a hash table, so operations average O(1) and iteration order carries no meaning. A C++ interviewer who asks for a dictionary expects std::unordered_map unless sorted keys are needed.

HashMap Versus Dictionary

Java's HashMap and C#'s Dictionary are the same structure with different rules for missing and null keys. Both are hash tables with average O(1) insert, lookup, and delete, and both slow toward O(n) when many keys collide. HashMap.get returns null for a missing key, while the C# indexer dict[key] throws KeyNotFoundException, and TryGetValue is the safe form. HashMap accepts one null key; Dictionary throws on a null key. Neither guarantees iteration order, even though the C# version often appears ordered until a removal happens.

Which Word to Use in an Interview

Use the word of the language you are coding in. State the complexity of the operations you rely on. Say "I will use a hash map for O(1) lookups by id" in Java or C++, and "a dict" in Python. If the problem needs sorted keys, name the tree-based type and its O(log n) cost. The interviewer is checking that you know what backs the structure, not which word you chose.

How to Prepare

TAGS
Coding Interview
CONTRIBUTOR
Arslan Ahmad
Arslan Ahmad
ex-FAANG engineering manager and author or Grokking series.

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
Where to position the camera for Zoom?
What Is the Instacart Interview Process Like? (Round by Round)
Instacart's reported stages: a recruiter screen, a technical phone screen, and a virtual onsite of four to five rounds, in about two to four weeks.
What Is the Modal Interview Process Like? (Round by Round)
What candidates report about the Modal interview, an 11 day average timeline, algorithm and code reading questions, and the likely round order.
What Is the Block Interview Process Like? (Round by Round)
The Block (Square) software engineer interview: recruiter screen, a one-hour practical coding screen, and a virtual onsite of four to five rounds.
What is the format of a technical interview?
How to understand pub-sub messaging for system design interviews?
Related Courses
New
Grokking the AI System Design Interview course cover
Grokking the AI System Design Interview
Learn to design AI systems the way interviewers expect: classic ML products, LLM and RAG architectures, and agentic systems, all through the lens of the system design interview.
4.6
(3,192 learners)
Discounted price for Your Region

$99

Grokking the Coding Interview: Patterns for Coding Questions course cover
Grokking the Coding Interview: Patterns for Coding Questions
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
4.6
Discounted price for Your Region

$197

Grokking Modern AI Fundamentals course cover
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
4.1
Discounted price for Your Region

$72

Design Gurus logo
One-Stop Portal For Tech Interviews.
Copyright © 2026 Design Gurus, LLC. All rights reserved.