0% found this document useful (0 votes)
4 views2 pages

DSA_Terms_in_Python_CheatSheet

This document explains various data structures in Python and their equivalents in other programming languages. It covers dictionaries, lists, stacks, queues, sets, heaps, tries, graphs, and dynamic programming techniques. Each data structure is described with its properties and usage in Python, emphasizing efficiency and functionality.

Uploaded by

jamalmusiala588
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)
4 views2 pages

DSA_Terms_in_Python_CheatSheet

This document explains various data structures in Python and their equivalents in other programming languages. It covers dictionaries, lists, stacks, queues, sets, heaps, tries, graphs, and dynamic programming techniques. Each data structure is described with its properties and usage in Python, emphasizing efficiency and functionality.

Uploaded by

jamalmusiala588
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/ 2

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.

You might also like