DSA Terms in Python - Full Explanation
HashMap -> dict
In Python, a dictionary (dict) is the equivalent of a HashMap. It's a key-value data structure that offers
average O(1) lookup time using hashing.
Array -> list
In most languages, arrays are fixed-size and type-specific. In Python, we use list, which is a dynamic array
that can grow or shrink and hold mixed types.
Stack -> list
A stack follows the Last In First Out (LIFO) principle. In Python, use a list with .append() to push and .pop() to
remove the top element.
Queue -> collections.deque
Queues follow the First In First Out (FIFO) principle. Python lists are inefficient for this, so use
collections.deque for fast append and popleft operations.
HashSet -> set
A set in Python is like a HashSet in other languages. It's an unordered collection of unique elements using
hashing for fast lookup and insertion.
Heap / Priority Queue -> heapq module
Python's heapq module provides a binary min-heap using a regular list. It allows fast access to the smallest
element and maintains the heap property.
Trie -> Nested dict
A Trie (prefix tree) can be made using nested dictionaries. Each key is a character, and paths represent
prefixes or complete words.
Graph -> dict of lists
In Python, graphs are usually built using a dictionary where each key is a node and its value is a list of
connected nodes (adjacency list).
Dynamic Programming -> Recursion + Memoization (dict or functools.lru_cache)
DP problems often use recursion and store subproblem results to avoid re-computation. In Python, this is
done using a memoization dict or @lru_cache.
DSA Terms in Python - Full Explanation
Set -> set
Same as HashSet. Python's set stores unique values and supports operations like union, intersection, and
difference efficiently.