Data Structures & Algorithms
A complete guide to DSA — from arrays and linked lists to trees, graphs, sorting, and dynamic programming.
Data Structures & Algorithms
Data structures and algorithms are the foundation of computer science. Every program you write uses them — whether you realize it or not. Understanding them makes you a better programmer in any language, helps you write faster code, and is essential for technical interviews.
This section is language-agnostic. The concepts apply everywhere. All code examples are written in Python.
What is a data structure?
A data structure is a way of organizing and storing data so it can be accessed and modified efficiently. Different structures are designed for different kinds of problems.
Choosing the wrong data structure can turn a fast program into a slow one. Choosing the right one can make an impossible problem trivial.
What is an algorithm?
An algorithm is a step-by-step process for solving a problem. The same problem can be solved by many different algorithms — with dramatically different speeds and memory usage.
How to measure performance — Big O
Before diving in, one concept appears everywhere: Big O notation. It describes how the performance of an algorithm scales as the input grows.
| Notation | Name | Example |
|---|---|---|
| O(1) | Constant | Access array by index |
| O(log n) | Logarithmic | Binary search |
| O(n) | Linear | Loop through array |
| O(n log n) | Linearithmic | Merge sort |
| O(n²) | Quadratic | Nested loops |
| O(2ⁿ) | Exponential | Recursive Fibonacci |
A program that takes O(1) time for 1 element still takes O(1) time for 1,000,000 elements. A program that takes O(n²) time for 10 elements takes 100x longer for 100 elements.
What is covered
Arrays
The foundation of everything. Sliding window, two pointers, prefix sum — patterns that appear in almost every interview.
Linked Lists
Nodes connected by pointers. Singly linked, doubly linked, fast and slow pointer technique.
Stacks & Queues
LIFO and FIFO structures. Monotonic stack — one of the most powerful interview patterns.
Trees
Hierarchical structures. Binary trees, BST, heap, and all four traversal orders.
Graphs
Nodes and edges. BFS, DFS, shortest path algorithms — Dijkstra and Bellman-Ford.
Sorting
Bubble, selection, insertion, merge, quick sort — visualized and explained with complexity analysis.
Searching
Linear search, binary search, search in rotated sorted array.
Recursion
Base cases, recursive cases, backtracking, divide and conquer.
Dynamic Programming
Memoization, tabulation, and classic problems — Fibonacci, knapsack, longest common subsequence.
How to use this section
Each topic starts with an introduction — what it is, a real-world analogy, and a visual. Then individual files cover specific techniques and patterns with animated walkthroughs showing exactly how the algorithm runs step by step.
Do not rush. Spend time on arrays and recursion before moving to trees and dynamic programming. The later topics build on the earlier ones.