Cheat sheet · Foundations
DSA and problem solving cheat sheet (Python)
Opens with creditsA quick-revision companion to the DSA roadmap in its Python edition: complexity, core data structures with list, dict, deque and heapq, recursion, trees, graphs, coding patterns, dynamic programming and timed practice. Skim a chapter before a project, an exam or a coding round, and follow the links for depth.
Chapters
9 chapters · 76 concepts
1Complexity and Big-OHow to say what code costs in time and memory before running it. Every later chapter trades one of these costs for another.7 concepts
- 1Big-O notationBig-O describes how the running time or memory of an algorithm grows as the input size n grows, keeping only the fastest-growing term and dropping constants.
- 2Common growth ratesFrom fastest to slowest: O(1) constant, O(log n) repeated halving, O(n) one pass, O(n log n) sorting, O(n^2) all pairs, O(2^n) all subsets, O(n!) all orderings.
- 3Counting operations in loopsMultiply the costs of nested loops and add the costs of loops in sequence.
- 4Best, worst and average caseWorst case is the most work on any input of size n, best case the least, and average case the expected work over typical or random inputs.
- 5Space complexity and the call stackThe extra memory an algorithm uses beyond its input, as a function of n.
- 6Amortised costThe average cost per operation over any long sequence of operations, even if a few single operations are expensive.
- 7Reading constraintsThe input limits in a problem hint at the expected complexity.
7 in this chapterOpen this chapter2Arrays, strings and hashingContiguous sequences and hash-based lookup, the structures most problems are built on, and exactly what your language gives you for each.8 concepts
- 1Arrays and dynamic arraysAn array stores items side by side in memory, so reading or writing index i is O(1).
- 2StringsA string is a sequence of characters.
- 3Hash mapsA hash map stores key-value pairs in buckets chosen by a hash of the key, giving O(1) average insert, lookup and delete.
- 4Hash setsA hash set stores unique keys without values, with O(1) average add, remove and membership check.
- 5Composite and custom keysWhen a key is made of several values, like a grid cell or a sorted word, it must be hashable and compare by value.
- 6Prefix sumsA prefix sum array stores running totals, so
prefix[i]is the sum of the first i items. - 7Integer limits and overflowJava and C++
intholds up to about 2.1 billion (2^31 - 1); past that Java wraps around and C++ has undefined behaviour. - 8Python built-in collections
listis a dynamic array,dictandsetare hash tables (a dict keeps insertion order),collections.dequegives O(1) at both ends,heapqturns a list…
8 in this chapterOpen this chapter- Linked lists, stacks and queuesPointer-based lists and the structures that control the order work is done in: last in first out, first in first out, and both ends.7 conceptsOpens with credits
- Recursion, sorting and searchingTrusting recursion, the classic sorts and what they cost, and binary search with its boundary variants, including searching over the answer.10 conceptsOpens with credits
- Trees and heapsHierarchical structures, the traversals that answer most questions about them, and heaps for anything that needs the smallest or largest item fast.7 conceptsOpens with credits
- GraphsNodes and edges, and the algorithms that search, order and connect them. Grids, schedules and dependency lists are often graph problems in disguise.9 conceptsOpens with credits
- Coding patternsRecognisable problem shapes that turn a brute force into an efficient solution. Name the pattern and the signal that told you before writing any code.10 conceptsOpens with credits
- Dynamic programmingRecursion plus a cache, then the handful of problem families most DP questions belong to. Start from the state and the recursion, never from the table.10 conceptsOpens with credits
- Timed practice and problem-solving habitsThe routine that makes you reliable under a clock, whether in a contest, an exam or a coding round: clarify, plan, code, test and review.8 conceptsOpens with credits
- 10Glossary, A to ZEvery concept in the sheet and the smaller terms it uses, in one list.161 terms
About this sheet
Data structures and patterns.
Related on Sefism
Picked from the other libraries by shared topics.
Roadmaps
See allCareer questions
See all- Is DSA still worth learning when AI can write code?Yes, but for a different reason than before. AI can produce a sorting function; it cannot tell you whether your design will fall over at scale or whether the code it wrote is quietly quadratic. DSA teaches you to judge code, and many companies still test it. Learn the core patterns well, skip the endless grind.
- I understand tutorials but cannot build anything myself. Why does coding feel so different when I am alone?Tutorials train recognition, not production. When you follow along, someone else makes every decision. Building alone requires you to break a problem down and make choices, which is a separate skill. Build it with small projects, planning on paper first, and a rule to struggle before you look anything up.
- How many LeetCode problems are enough, and how do I practise them properly?For most junior and mid-level interviews, 150 to 250 well-understood problems, organised by pattern, are enough. The number matters far less than whether you can recognise the pattern, explain your approach aloud and solve a similar problem a week later without help.
Work with me
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
- 1:1 Mentorship
- Fresh Graduate Mentorship
- Career Guidance
Brand deals, promos and partnerships: tauseeffayyaz@gmail.com