DSA Tracker

DSA Tracker

Beginner path · Python

Updated 2026-10-21

Learn DSA in Python from scratch

Python suits learners who want concise DSA code and a gentle path from idea to implementation. Its standard library is strong for contests, but you still need to understand the cost of operations hidden behind short syntax.

What you need from Python before DSA

01

Variables and types

Python names can point to values of different types, so know what each operation returns.

count = 3
label = "items"
print(label, count)

Output: items 3

02

Conditionals and loops

Most DSA code repeatedly tests a condition while scanning a structure.

total = 0
for value in [2, 4, 5]:
    if value % 2 == 0:
        total += value
print(total)

Output: 6

03

Functions

A named function keeps one algorithm's inputs, output and scope clear.

def double(value):
    return value * 2

print(double(6))

Output: 12

04

Recursion

Trees and divide-and-conquer algorithms call the same idea on smaller input.

def countdown(n):
    if n == 0:
        return
    print(n)
    countdown(n - 1)

countdown(3)

Output: 3 2 1

05

Arrays and lists

A list gives you indexed storage and is the base for many other structures.

numbers = [3, 1, 2]
numbers.append(4)
print(numbers[1], len(numbers))

Output: 1 4

06

Strings

Parsing and comparing text is common in frequency counts and two-pointer problems.

word = "level"
print(word == word[::-1])

Output: True

07

Hash maps and sets

They turn repeated membership and frequency checks into direct operations on average.

seen = {2, 4}
counts = {"a": 2}
print(4 in seen, counts["a"])

Output: True 2

08

References and copying

A list assignment shares the same object; copy deliberately when a branch must not mutate its source.

first = [1, 2]
second = first.copy()
second.append(3)
print(first, second)

Output: [1, 2] [1, 2, 3]

09

Classes or structs

Linked lists and trees need small node objects with fields such as value and next.

class Node:
    def __init__(self, value):
        self.value = value

print(Node(7).value)

Output: 7

10

Sorting with a custom comparator

Sorting by a derived key is a standard way to order intervals, pairs and records.

items = [("b", 2), ("a", 1)]
items.sort(key=lambda item: item[1])
print(items)

Output: [('a', 1), ('b', 2)]

11

Reading input

Contest and interview judges provide data through standard input, not hardcoded arrays.

import sys
values = list(map(int, sys.stdin.read().split()))
print(sum(values))

Input: 2 4

Output: 6

Python toolbox for data structures

StructurePython typeKey operations
Dynamic arraylistappend/pop at end O(1) amortized; indexing O(1)
String buildinglist + str.joinappend pieces, then join once
Hash mapdictget/set O(1) average
Hash setsetadd/lookup O(1) average
Stacklistappend and pop from the end
Queuecollections.dequeappend right, popleft O(1)
Dequecollections.dequeappend/pop at both ends O(1)
Priority queueheapqheappush/heappop min-heap
Ordered mapNo built-in ordered mapuse sorted keys or a third-party tree
Sortinglist.sort / sortedkey= comparator, stable

The order to learn DSA

Follow the SDE roadmap order. Each topic starts with two Easy problems from the curated set.

Ready to move on when you can solve both without looking at a solution.

Ready to move on when you can solve both without looking at a solution.

Ready to move on when you can solve both without looking at a solution.

Python mistakes that cost people in DSA

Using list.pop(0) as a queue

Removing the first list item shifts every remaining item and costs O(n). Use collections.deque and popleft for a queue.

Forgetting that heapq is a min-heap

heapq returns the smallest item first. Push negative priorities when you need max-heap behavior.

import heapq
heap = []
heapq.heappush(heap, -8)
print(-heapq.heappop(heap))

Output: 8

Hitting the recursion limit

Python's default recursion limit is 1000. sys.setrecursionlimit can raise it, but an iterative solution may still be safer.

Expecting integer overflow

Python integers grow as needed, so overflow is not the issue. Memory and runtime still matter for very large values.

Building strings with repeated concatenation

Strings are immutable. Build pieces in a list and call join once.

Confusing // with truncation

// is floor division, so negative operands round down rather than toward zero.

DSA in Python: questions, answered

Is Python good for learning DSA?

Yes. It keeps the algorithm visible, but learn the cost of list, dict, set and deque operations instead of treating every line as constant time.

How do I make a max-heap in Python?

heapq is a min-heap. Store negative priorities and negate the value again when you pop it.

Can Python handle recursive DSA problems?

Yes for shallow recursion. The default recursion limit is 1000, so deep trees and graphs may need an iterative traversal or a deliberately adjusted limit.