A dsa cheat expanse is simply a compact revision representation of information structures, algorithms, patterns, complexity rules, and implementation cues. It matters because interviews seldom trial isolated syntax; they trial whether you tin take the correct building for problems for illustration UPI fraud checks, IRCTC allocation, aliases routing. After reading, you tin revise, classify, and instrumentality halfway DSA ideas faster.
This page is built for dsa speedy revision earlier coding interviews, GATE-style mentation questions, and timed problem-solving rounds. Use it arsenic a one-page reference, past prevention the page arsenic a dsa cheat expanse pdf from your browser people paper if you want an offline copy.
You will beryllium capable to comparison each awesome DSA concepts, recognise modular patterns, estimate clip and abstraction complexity, and constitute cleanable starter codification for arrays, lists, trees, graphs, move programming, greedy algorithms, and precocious structures.
Core Concepts
DSA has 4 layers: complexity analysis, information structures, algorithms, and problem-solving patterns. Complexity tells you really a solution scales. Data structures determine really information is stored and accessed. Algorithms specify the procedure. Patterns thief you recognise repeated problem shapes quickly.
The array beneath useful arsenic a compact comparison matrix for the complete cheat sheet. Treat it arsenic your first-pass revision earlier going into the elaborate sections.
1.Time and Space Complexity
Complexity study measures really clip and representation turn arsenic input size increases. Big O describes an precocious bound, Big Omega describes a little bound, and Big Theta describes a tight bound. For interviews, Big O is astir commonly asked because it helps comparison whether a solution will walk constraints.
A acquainted illustration is checking 1 Aadhaar number successful an unsorted database of 1 crore records: a linear scan is O(n), while a hash-based lookup is expected O(1). An industry-specific illustration is simply a healthcare assignment level calculating disposable slots; checking each expert and each slot whitethorn go O(d × s), while indexed calendars trim applicable lookup time.
Most GATE and question and reply questions inquire for worst-case clip complexity. Binary hunt is O(log n), merge benignant is O(n log n), BFS is O(V + E), and nested loops complete the aforesaid input are usually O(n²) unless the loop variables move monotonically.Code Example
2.Arrays and Strings
Arrays shop elements successful contiguous representation and let O(1) indexed access. Strings behave for illustration arrays of characters successful galore DSA problems, though immutability depends connected the language. Core variants see fixed arrays, move arrays, characteristic arrays, strings, prefix arrays, suffix arrays, and two-dimensional arrays.
A acquainted illustration is simply a UPI transaction history database wherever the latest 50 entries tin beryllium indexed quickly. An industry-specific illustration is an e-commerce inventory grid wherever rows correspond warehouses and columns correspond SKUs. Use arrays erstwhile position matters, scanning is frequent, and representation locality helps performance.
For subarray sum problems, prefix sums move repeated range-sum queries from O(n) each into O(1) aft O(n) preprocessing. For substring and model problems, for illustration 2 pointers aliases sliding model earlier trying nested loops.Code Example
3.Linked Lists
A linked database stores information successful nodes wherever each node points to different node. The modular variants are singly linked list, doubly linked list, information singly linked list, and information doubly linked list. Linked lists are useful erstwhile insertion and deletion adjacent known nodes are much important than random indexing.
A acquainted illustration is simply a euphony playlist wherever moving to the adjacent opus is earthy and a doubly linked database besides supports erstwhile navigation. An industry-specific illustration is an LRU cache successful a SaaS dashboard, wherever a doubly linked database positive hash representation supports speedy eviction of the slightest precocious utilized item.
A communal correction is utilizing a linked database for predominant index-based access. Accessing the kth node takes O(k), truthful arrays are usually amended erstwhile random entree is required.Code Example
4.Stacks and Queues
A stack follows LIFO: past in, first out. A queue follows FIFO: first in, first out. A deque supports insertion and deletion astatine some ends. Important variants see normal stack, monotonic stack, normal queue, information queue, privilege queue, and monotonic queue.
A acquainted illustration is undo history successful a note-taking app, wherever the latest action is reversed first. Another illustration is simply a slope token queue, wherever customers are served successful presence order. Industry-specific usage cases see BFS occupation processing, compiler look parsing, and rate-limited task scheduling.
Balanced parentheses, adjacent greater element, and look information usually request stacks. Level-order traversal and shortest way successful an unweighted chart usually request queues.Code Example
5.Hashing
Hashing maps keys to values utilizing a hash function. Standard structures are hash set, hash map, wave map, ordered hash map, and hash array pinch collision handling done chaining aliases unfastened addressing. Average lookup, insertion, and deletion are O(1), but worst-case tin degrade if collisions are severe.
A acquainted illustration is checking whether a PAN number has already been submitted during onboarding. An industry-specific illustration is fraud discovery successful payments, wherever transaction IDs tin beryllium stored successful a hash group to observe copy processing. Hashing is besides the backbone of grouping, counting, caching, and deduplication problems.
Use a hash representation erstwhile the problem asks for “first occurrence”, “frequency”, “seen before”, “pair pinch target sum”, aliases “group by key”. Sorting whitethorn work, but hashing often preserves linear-time performance.Code Example
6.Recursion and Backtracking
Recursion solves a problem by calling the aforesaid usability connected a smaller input. Backtracking is recursion pinch controlled exploration: choose, explore, and undo. Standard variants see linear recursion, character recursion, divide-and-conquer recursion, tail recursion, subset generation, permutation generation, operation search, and constraint satisfaction.
A acquainted illustration is generating each imaginable telephone keypad combinations for a support helpline. An industry-specific illustration is assigning nurses to shifts successful a infirmary while respecting constraints specified arsenic readiness and maximum hours. Backtracking is powerful erstwhile the hunt abstraction is ample but constraints tin prune invalid paths early.
Missing the guidelines lawsuit causes infinite recursion. Forgetting to undo a prime during backtracking corrupts later branches and produces incorrect results.Code Example
7.Sorting and Searching
Sorting arranges information successful a defined order, while searching locates a target aliases boundary. Sorting variants see bubble sort, action sort, insertion sort, merge sort, speedy sort, heap sort, counting sort, radix sort, bucket sort, and unchangeable built-in sorts. Searching variants see linear search, binary search, little bound, precocious bound, and binary hunt connected answer.
A acquainted illustration is sorting nutrient transportation orders by transportation time. An industry-specific illustration is ranking security claims by consequence people earlier manual review. Binary hunt applies only erstwhile the hunt abstraction is monotonic: if a information is existent astatine immoderate point, it remains existent connected 1 side.
Merge benignant has O(n log n) worst-case clip and O(n) other space. Quick benignant has O(n log n) mean clip but O(n²) worst-case without bully pivoting. Binary hunt is O(log n), but only connected sorted aliases monotonic spaces.Code Example
8.Trees and BSTs
A character is simply a hierarchical building pinch nodes and edges, while a binary character limits each node to astatine astir 2 children. Important types see wide tree, binary tree, afloat binary tree, complete binary tree, cleanable binary tree, balanced tree, binary hunt tree, AVL tree, red-black tree, B-tree, and look tree.
A acquainted illustration is simply a family hierarchy, wherever parent-child relationships shape a tree. An industry-specific illustration is simply a database index, wherever B-trees thief find records efficiently. Tree traversals see preorder, inorder, postorder, and level order; BST inorder traversal produces sorted order.
For a valid BST, each node successful the near subtree must beryllium smaller than the guidelines and each node successful the correct subtree must beryllium larger. Checking only contiguous children is not enough.Code Example
9.Heaps and Priorities
A heap is simply a complete binary character that keeps either the minimum aliases maximum constituent astatine the root. Standard variants see min heap, max heap, binary heap, d-ary heap, binomial heap, Fibonacci heap, and privilege queue abstraction. In interviews, binary heaps are the astir communal implementation.
A acquainted illustration is showing the cheapest train options first aft a search. An industry-specific illustration is simply a unreality monitoring strategy that ever processes the astir terrible alert earlier lower-priority logs. Heaps are perfect for Top K, merging sorted streams, scheduling, and Dijkstra’s algorithm.
Python’s modular heapq module implements a min heap. For max heap behavior, shop antagonistic values aliases wrap objects pinch reversed comparison logic.Code Example
10.Tries
A trie is simply a tree-like building wherever each way represents a prefix. Common variants see modular trie, compressed trie aliases radix tree, suffix trie, ternary hunt tree, and binary trie for bitwise queries. Tries waste and acquisition representation for accelerated prefix operations.
A acquainted illustration is interaction hunt connected a phone, wherever typing “ra” suggests names starting pinch that prefix. An industry-specific illustration is simply a logistics level matching pincode prefixes for serviceability rules. Tries are useful for autocomplete, spell check, dictionary search, prefix count, and longest prefix matching.
A trie tin devour precocious representation erstwhile the alphabet is ample and strings stock fewer prefixes. Use hash maps for children alternatively of fixed-size arrays erstwhile the characteristic group is sparse.Code Example
11.Range Query Structures
Range query structures reply questions complete subarrays efficiently. The main variants are prefix sum, quality array, sparse table, square-root decomposition, Fenwick tree, lazy Fenwick tree, conception tree, and lazy conception tree. Choose based connected whether updates are absent, point-based, aliases range-based.
A acquainted illustration is calculating monthly disbursal totals from regular transactions. An industry-specific illustration is simply a banal analytics work answering repeated scope maximum aliases sum queries complete value history. Prefix sums are champion for fixed sums, Fenwick trees for constituent updates pinch prefix queries, and conception trees for broader associative operations.
Fenwick character update and prefix query are O(log n). Segment character scope query and constituent update are besides O(log n), but conception trees grip much operations specified arsenic min, max, GCD, and lazy scope updates.Code Example
12.Graph Algorithms
A chart contains vertices and edges. Core variants see directed graph, undirected graph, weighted graph, unweighted graph, cyclic graph, acyclic graph, connected graph, disconnected graph, dense graph, sparse graph, tree, DAG, multigraph, and bipartite graph. Representations see adjacency list, adjacency matrix, and separator list.
A acquainted illustration is metro stations connected by routes. An industry-specific illustration is simply a proposal chart wherever users, restaurants, and orders shape relationships. Essential algorithms see BFS, DFS, topological sort, rhythm detection, Dijkstra, Bellman-Ford, Floyd-Warshall, Prim, Kruskal, and powerfully connected components.
Use BFS for shortest way successful an unweighted graph. Use Dijkstra for non-negative weighted graphs. Use Bellman-Ford erstwhile antagonistic edges whitethorn exist. Topological benignant useful only connected a DAG.Code Example
13.Disjoint Set Union
Disjoint Set Union, besides called Union-Find, tracks elements divided into non-overlapping sets. The 2 cardinal optimisations are way compression and national by rank aliases size. It supports find and national operations almost successful changeless amortized time, commonly written arsenic O(α(n)), wherever α is the inverse Ackermann function.
A acquainted illustration is grouping mobile numbers that beryllium to the aforesaid family plan. An industry-specific illustration is detecting whether adding a web cablegram would create a rhythm successful a data-center topology. DSU is heavy utilized successful Kruskal’s minimum spanning tree, connected components, relationship merging, and offline query problems.
The modular question and reply mobility is rhythm discovery successful an undirected graph. If an separator connects 2 vertices already successful the aforesaid DSU set, adding that separator creates a cycle.Code Example
14.Greedy Algorithms
Greedy algorithms make the champion section prime astatine each step. They activity only erstwhile the problem has greedy-choice spot and optimal substructure. Standard greedy categories see interval scheduling, activity selection, fractional knapsack, Huffman coding, occupation sequencing, minimum spanning tree, coin alteration for canonical coin systems, and shortest paths pinch non-negative edges.
A acquainted illustration is choosing the maximum number of non-overlapping movie shows successful 1 day. An industry-specific illustration is simply a logistics level assigning deliveries by earliest deadline to trim missed SLA windows. Greedy solutions are short, but the impervious matters: sorting by the correct cardinal is usually the bosom of the solution.
Greedy does not activity for each optimisation problem. The classical 0/1 knapsack problem needs move programming, while fractional knapsack useful greedily by value-to-weight ratio.Code Example
15.Dynamic Programming
Dynamic programming stores answers to overlapping subproblems. The main variants are top-down memoization, bottom-up tabulation, one-dimensional DP, two-dimensional DP, interval DP, character DP, digit DP, bitmask DP, DP connected graphs aliases DAGs, and space-optimised DP. DP is utilized erstwhile brute unit repeats the aforesaid states.
A acquainted illustration is calculating the number of ways to climb stairs erstwhile you tin return 1 aliases 2 steps. An industry-specific illustration is an ed-tech level recommending an optimal learning way based connected prerequisite completion and disposable time. Define state, transition, guidelines case, bid of computation, and last answer.
A DP solution is incomplete until you tin authorities the authorities meaning and transition. For example, dp[i] whitethorn mean “best reply considering the first one items”; without that meaning, the recurrence is easy to misuse.Code Example
16.Bit Manipulation
Bit manipulation useful straight pinch binary digits. Core operations see AND, OR, XOR, NOT, near shift, correct shift, group bit, clear bit, toggle bit, cheque bit, count group bits, extract lowest group bit, and bitmask enumeration. It is useful erstwhile values are people represented arsenic flags aliases compact states.
A acquainted illustration is storing notification preferences wherever SMS, email, and WhatsApp alerts are individual bits. An industry-specific illustration is simply a permissions strategy successful a SaaS merchandise wherever read, write, export, and admin capabilities are mixed successful 1 integer mask. XOR is particularly communal for uncovering unsocial values.
The look x & (x - 1) removes the lowest group bit. It is utilized to count group bits successful O(number of group bits), which tin beryllium faster than checking each bit.Code Example
17.Math and Number Theory
Math-based DSA covers arithmetic techniques that trim brute force. Standard subtopics see divisibility, premier testing, sieve of Eratosthenes, GCD, LCM, modular arithmetic, modular inverse, accelerated exponentiation, permutations, combinations, factorial precomputation, matrix exponentiation, and probability basics.
A acquainted illustration is calculating the adjacent communal billing rhythm utilizing LCM. An industry-specific illustration is cryptographic cardinal handling, wherever modular arithmetic appears heavy successful public-key systems. Competitive and question and reply problems often usage modulo 1,000,000,007 to support ample counting answers bounded.
Euclid’s algorithm computes GCD successful O(log min(a, b)) time. The narration lcm(a, b) = abs(a × b) // gcd(a, b) is often tested.Code Example
Choose the building from the required operation: accelerated lookup suggests hashing, ordered scope queries propose trees, repeated optimal subproblems propose DP, shortest unweighted way suggests BFS, and apical K suggests heap.Problem-Solving Patterns
Patterns link problem statements to implementation choices. During dsa speedy revision, practise recognising these triggers earlier penning code: contiguous range, sorted input, repeated state, chart relation, apical K, prefix, cycle, aliases monotonic condition.
Sliding Window
Sliding model handles contiguous subarray aliases substring problems. Fixed-size windows lick problems specified arsenic maximum sum of k consecutive values. Variable-size windows lick problems specified arsenic longest substring pinch astatine astir k chopped characters.
A acquainted illustration is uncovering the highest spending streak crossed 7 days of wallet transactions. An industry-specific illustration is monitoring the maximum API errors successful immoderate five-minute model for a unreality service. Use this shape erstwhile the reply depends connected a continuous segment.
Code Example
Two Pointers
Two pointers usage 2 indices that move done information successful a controlled way. Variants see opposite-direction pointers, same-direction fast-slow pointers, partition pointers, and merge pointers. This shape often reduces O(n²) brace checks to O(n) aft sorting aliases erstwhile monotonic activity is possible.
A acquainted illustration is uncovering 2 wallet transactions that adhd up to a target fund aft sorting amounts. An industry-specific illustration is merging 2 sorted logs from different servers into 1 chronological stream. Fast-slow pointers are besides utilized to observe cycles successful linked lists.
Code Example
Learning Path
Use this roadmap to person the cheat expanse into a applicable study plan. Each shape builds 1 layer: correctness, efficiency, shape recognition, and question and reply readiness.
Frequently Asked Questions
What is DSA Cheat Sheet: All Concepts successful One Page (Free PDF)?
It is simply a compact reference that summarises information structures, algorithms, patterns, complexity rules, and communal implementation templates successful 1 place. You tin usage this page for revision and prevention it arsenic a dsa cheat expanse pdf utilizing your browser’s print-to-PDF option.
What should a dsa cheat expanse include?
It should see complexity analysis, arrays, strings, linked lists, stacks, queues, hashing, recursion, sorting, searching, trees, heaps, tries, scope query structures, graphs, DSU, greedy, DP, spot manipulation, and number theory. It should besides see erstwhile to usage each concept, not only definitions.
How do I usage this cheat expanse for question and reply revision?
Start pinch the comparison table, past revise 1 conception group astatine a time. For each topic, inquire 3 questions: what cognition is needed, what building supports it efficiently, and what is the time-space complexity?
When should I usage hashing alternatively of sorting?
Use hashing erstwhile you request accelerated lookup, wave counting, copy detection, aliases brace checks successful expected O(1) clip per operation. Use sorting erstwhile bid matters, representation should beryllium lower, aliases the problem depends connected ranking, intervals, aliases monotonic scanning.
When should I usage move programming alternatively of greedy?
Use greedy only erstwhile a section prime tin beryllium proven safe for the world optimum. Use DP erstwhile choices interact crossed states, subproblems overlap, and trying 1 locally champion prime whitethorn artifact a amended early answer.
What is the astir communal DSA correction successful interviews?
The astir communal correction is jumping into codification earlier identifying the shape and constraints. A solution that useful for mini input whitethorn neglect if O(n²) is utilized wherever n is ample and an O(n log n) aliases O(n) solution is expected.
How galore DSA patterns are capable for placements?
There is nary fixed number, but astir placement problems many times usage arrays, strings, hashing, 2 pointers, sliding window, binary search, recursion, trees, graphs, heaps, greedy, and DP. Depth matters much than memorising labels.
Is Python acceptable for DSA interviews?
Python is accepted successful galore interviews and coding platforms, but you must cognize its capacity characteristics. Lists, dictionaries, sets, deque from collections, and heapq are particularly useful; the charismatic collections documentation is simply a reliable reference.
Key Takeaways
The astir useful DSA revision points are concrete: arrays springiness accelerated indexing, hashing gives expected O(1) lookup, heaps lick Top K and privilege problems, BFS solves unweighted shortest paths, DSU tracks components, and DP removes repeated subproblem work.
For GATE and interviews, the astir tested areas are clip complexity, recursion recurrence, sorting bounds, character traversals, BFS versus DFS, Dijkstra versus Bellman-Ford, greedy proof, DP authorities transition, and amortized DSU complexity.
The earthy adjacent measurement is to move this dsa cheat expanse into progressive practice: prime 1 conception daily, lick 3 mixed problems without looking astatine the taxable tag, constitute the complexity first, and past codification the cleanest accepted solution.
English (US) ·
Indonesian (ID) ·