DSA Notes
A comprehensive look at how data structures and algorithms are used in real systems — search engines, GPS navigation, social media, databases, operating systems, compilers, games, and more. With detailed explanations of which specific data structures and algorithms are used and why.
Introduction
One of the most effective ways to stay motivated while learning Data Structures and Algorithms is to understand deeply where they appear in the real world. This is not a list of abstract possibilities — DSA is actively running in every piece of software you interact with, often multiple times per second.
This lesson takes you through ten major software domains and shows you precisely which data structures and algorithms power them, how they work, and why the choice of data structure makes all the difference. By the end of this lesson, you will see DSA not as a collection of theoretical concepts to pass exams, but as the invisible architecture of the digital world.
2. GPS Navigation — Google Maps, Apple Maps, Waze
Every time you ask for directions, you are asking a computer to solve the Shortest Path Problem on a massive graph representing the road network.
The Road Network as a Weighted Graph
A major city's road network might have millions of nodes and tens of millions of edges.
Dijkstra's Algorithm
The classical algorithm for finding the shortest path from a source to all other nodes in a graph with non-negative edge weights is Dijkstra's Algorithm, published by Edsger W. Dijkstra in 1959.
The key internal data structure inside Dijkstra's is a min-heap (priority queue), which always gives you the unvisited node with the smallest current known distance in O(log n) time.
Real-Time Traffic — Dynamic Edge Weights
Waze and Google Maps update routes in real time based on traffic. When a traffic jam is detected, the weights of affected road edges increase. The routing algorithm re-runs with updated weights. This requires not just the shortest-path algorithm, but efficient mechanisms to update the graph and quickly recompute paths.
A* Algorithm — Faster than Dijkstra for Single-Destination
For GPS navigation where you have a specific destination (not just "find shortest path to everywhere"), the **A\* Algorithm** is more efficient than Dijkstra. A* uses a heuristic — typically the straight-line distance to the destination — to guide the search toward the goal, avoiding exploring roads that are clearly in the wrong direction. A* is Dijkstra's Algorithm enhanced with a guiding heuristic.
3. Social Media — Facebook, Instagram, Twitter/X, LinkedIn
Social networks are, at their core, graphs. Every social media platform is built on graph data structures and graph algorithms.
The Social Graph
| Undirected edges (both people are "friends") | |
| Directed edges (you follow someone; they may not follow back) | |
| Both directed (connection requests) and weighted (strength of connection) |
A major social platform manages a graph with billions of nodes and hundreds of billions of edges.
Friend-of-Friend Suggestions — BFS
When Facebook or LinkedIn suggests "People You May Know," they are running a Breadth-First Search (BFS) starting from your node, exploring outward:
- Depth 1: Your direct friends (connections you already have)
- Depth 2: Friends of your friends (these are the suggestions)
- Depth 3 and beyond: Usually too distant for meaningful suggestions
Feed Ranking — Priority Queue and Heap
Your Instagram or Twitter feed is not shown in chronological order. Every post on the platform is scored based on your past interactions, recency, and relationship strength with the poster. The platform must efficiently retrieve the top-N highest-scored posts for you from potentially millions of candidates.
This is a Top-K problem, solved using a Min-Heap of size K:
import heapq
def get_top_k_posts(all_posts_with_scores, k):
"""
Efficiently find the k highest-scored posts.
Uses a min-heap of size k.
Time: O(n log k) — much better than O(n log n) for sorting all posts
"""
min_heap = []
for score, post in all_posts_with_scores:
heapq.heappush(min_heap, (score, post))
# Keep heap size at most k
if len(min_heap) > k:
heapq.heappop(min_heap) # Remove the lowest-scored post
# Return results sorted by score descending
return sorted(min_heap, reverse=True)For ten million candidate posts and k=100, a min-heap approach runs in O(n log k) = O(n × 7) instead of O(n log n) = O(n × 23) for sorting everything. At scale, this difference is significant.
4. Databases — MySQL, PostgreSQL, MongoDB
Databases are entirely built on data structures. Their performance characteristics — why some queries are instant while others take minutes — are determined almost entirely by the data structures used internally.
B+ Tree Indexes — The Heart of Relational Databases
Every relational database uses B+ Trees as the primary index data structure. A B+ Tree is a self-balancing tree where:
- All data is stored at leaf nodes
- Internal nodes store only keys for routing
- All leaf nodes are linked together (making range queries efficient)
- The tree always remains balanced, guaranteeing O(log n) operations
Query: SELECT * FROM users WHERE id = 54321
Without index:
→ Scan every row from start to finish
→ If table has 50 million rows: 50 million comparisons
→ Time: Several seconds
With B+ Tree index on id:
→ Start at root, traverse tree following the correct branch
→ A B+ Tree of height h can store billions of records with h ≈ 3-4
→ 3-4 comparisons needed regardless of table size
→ Time: MicrosecondsThis is why CREATE INDEX commands exist in SQL — they build a B+ Tree structure that transforms O(n) table scans into O(log n) lookups.
Hash Indexes — O(1) Exact Lookups
For exact equality queries (WHERE id = 12345), some database engines use hash indexes:
| Query | SELECT * WHERE username = 'alice' |
| hash("alice") | bucket 4892 → [row pointer to alice's data] |
| Direct lookup | O(1) average |
The limitation is that hash indexes do not support range queries (WHERE age BETWEEN 20 AND 30). For range queries, B+ Tree indexes are used because the sorted tree structure makes it easy to find all values in a range.
LRU Cache for Buffer Pool — Doubly Linked List + Hash Map
Disk access is roughly 100,000 times slower than RAM access. Databases maintain a buffer pool — a region of RAM that caches frequently accessed disk pages. When a page is needed:
- Check the buffer pool (cache hit: fast)
- If not present, read from disk into the buffer pool (cache miss: slow), evicting the least recently used page if the pool is full
The eviction policy is LRU (Least Recently Used), implemented with a doubly linked list + hash map:
- Hash map gives O(1) lookup: "Is this page in cache?"
- Doubly linked list maintains access order: most recent at front, least recent at back
- Eviction: remove from back of list and from hash map in O(1)
This combination achieves O(1) for all operations: lookup, insert, and eviction.
5. Operating Systems — Windows, macOS, Linux
CPU Process Scheduling — Priority Queue
The operating system must decide which process gets CPU time at every moment. With potentially hundreds of processes running simultaneously, this decision must be made efficiently many times per second.
Modern schedulers use priority queues (heaps) to organize processes by their scheduling priority. The scheduler always picks the highest-priority process from the min/max heap in O(log n) time.
Different scheduling algorithms use different criteria for priority:
- Shortest Job First (SJF): Priority = estimated CPU burst time (shorter jobs first)
- Priority Scheduling: Priority = assigned priority number
- Round Robin: A queue-based approach where each process gets equal time slices
Memory Allocation — Free Lists
When a program calls malloc() or new, the operating system allocates a block of memory. The OS maintains a free list — a linked list of available memory blocks — to track which regions of RAM are available.
| Block A: address 0x1000, size 256 bytes | points to Block B |
| Block B: address 0x2500, size 512 bytes | points to Block C |
| Block C: address 0x4000, size 128 bytes | NULL |
File System — Trees
Your operating system's file system is a tree:
Every directory is a node. Files are leaves. Navigating a path like /Documents/Projects/project1.zip is a root-to-leaf path traversal in this tree.
Under the hood, modern file systems like NTFS (Windows) and ext4 (Linux) use B+ Trees to store directory entries and file metadata, enabling fast lookup of files by name even in directories with millions of files.
6. Compilers and Interpreters — How Code Becomes Instructions
When you write Python, Java, or C++ code, a compiler or interpreter transforms it into executable instructions. This transformation relies heavily on tree data structures.
Lexical Analysis — Finite Automata / Trie
The first step of compilation is lexical analysis (lexing) — breaking source code into tokens (keywords, identifiers, operators, literals). The lexer uses a form of deterministic finite automaton or a Trie to recognize tokens as it scans character by character.
Abstract Syntax Tree (AST) — Tree Data Structure
After lexing, the compiler builds an Abstract Syntax Tree (AST) that represents the syntactic structure of the source code.
Every node in the AST represents a syntactic construct. The tree structure naturally captures operator precedence and program structure. The compiler traverses this tree to:
- Check for type errors (semantic analysis)
- Generate intermediate representation
- Apply optimizations
- Generate machine code or bytecode
Symbol Table — Hash Map
The compiler maintains a symbol table — a hash map from every identifier (variable name, function name, class name) to its properties (type, scope, memory location):
# Symbol table as a hash map
symbol_table = {
"result": {"type": "int", "scope": "local", "address": "0x4A20"},
"a": {"type": "float", "scope": "local", "address": "0x4A24"},
"b": {"type": "float", "scope": "local", "address": "0x4A28"},
# ...
}Every time a variable is referenced, the compiler looks it up in the symbol table in O(1) time.
7. Networking — Routers, Protocols, and DNS
Routing Tables — Tries
Internet routers must decide, for every incoming packet, which port to forward it through. A routing table maps IP address prefixes to outgoing ports. With billions of possible IP addresses, routers use Tries (prefix trees) to store routing prefixes:
| Packet destined for | 192.168.1.45 |
| Trie traversal: 1 | 9 → 2 → . → 1 → 6 → 8 → ... |
| Match found: 192.168.1.0/24 | Forward to Port 3 |
| Lookup time | O(32) = O(1) for IPv4 (32-bit addresses) |
DNS Resolution — Hash Map with Caching
The Domain Name System (DNS) translates human-readable domain names like "www.google.com" into IP addresses. DNS resolvers use hash maps to cache recently resolved names, avoiding redundant lookups:
| "google.com" | 142.250.80.46 (cached for TTL seconds) |
| "github.com" | 140.82.121.4 (cached) |
| "wohotech.in" | 152.67.xx.xx (cached) |
When you visit a website, your computer first checks this local DNS cache before making a network request. Most domain lookups resolve from cache in microseconds.
8. Game Development
Pathfinding — A* Algorithm
In almost every game that involves navigation — real-time strategy games, RPGs, action games — characters need to find paths around obstacles. The industry-standard algorithm is A\*, which finds the optimal path while being significantly faster than exhaustive search.
Collision Detection — Spatial Data Structures
A game with 1,000 objects cannot check all 1,000 × 999 / 2 ≈ 500,000 pairs for collisions every frame. Instead, spatial data structures partition space to reduce collision checks:
- Quadtree (2D games): Divides the game world into four quadrants recursively. Only check collisions between objects in the same quadrant.
- Octree (3D games): Same concept in three dimensions.
- BVH (Bounding Volume Hierarchy): A tree of bounding boxes around groups of objects.
These structures reduce collision detection from O(n²) to O(n log n) per frame.
9. Cryptography and Security
Hash Functions in Password Storage
When you set a password on a website, the website should never store the actual password. Instead it stores a cryptographic hash — a fixed-size digest produced by a hash function (like SHA-256 or bcrypt).
Registration
User sets password: "MySecret123"
System computes: hash("MySecret123") → "a3f8b2d..."
Stores: "a3f8b2d..." in the database
Login
User enters: "MySecret123"
System computes: hash("MySecret123") → "a3f8b2d..."
Compares with stored hash
Match → login successful
Even if database is stolen, attacker cannot reverse hash → original password
Merkle Trees in Blockchain
Bitcoin and other blockchains use Merkle Trees — binary trees where each leaf node contains the hash of a transaction, and each internal node contains the hash of its two children.
The root hash (Merkle root) summarizes the entire set of transactions in a block. Changing any single transaction changes its hash, which changes its parent's hash, all the way up to the root. This makes tampering immediately detectable while allowing efficient verification of individual transactions without downloading the entire blockchain.
10. Text Editors and IDEs
Undo/Redo — Stack
Every text editor implements undo/redo using two stacks:
| Undo stack | [action1, action2, action3] ← top |
| Redo stack | [] |
| Undo stack | [type_H, type_e, type_l, type_l, type_o] |
| Pop from undo stack | type_o |
| Push to redo stack | type_o |
| Undo stack | [type_H, type_e, type_l, type_l] |
| Redo stack | [type_o] |
| Pop from redo stack | type_o |
| Push to undo stack | type_o |
Syntax Highlighting — Trie / Finite Automaton
When your code editor highlights keywords like for, while, class, and def in different colors, it uses a Trie or finite automaton to match tokens against a list of keywords as you type.
Code Completion — Trie
When your IDE suggests method names as you type, it uses a Trie built from the symbols available in your current scope, filtering suggestions based on the characters you have typed so far.
Summary
Data structures and algorithms are not theoretical concepts invented for exams. They are the practical engineering tools that make every piece of software you use fast, reliable, and scalable.
| Software System | Key Data Structures | Key Algorithms |
|---|---|---|
| Search Engines | Inverted Index, Trie, Graph | PageRank, Graph Traversal |
| GPS Navigation | Weighted Graph, Min-Heap | Dijkstra's, A* |
| Social Media | Graph, Min-Heap | BFS, Top-K |
| Databases | B+ Tree, Hash Map | Tree traversal, Hash joins |
| Operating Systems | Priority Queue, Linked List, Tree | Scheduling, LRU eviction |
| Compilers | AST (Tree), Hash Map | Tree traversal, Parsing |
| Networking | Trie, Hash Map | Prefix matching, Caching |
| Games | Graph, Spatial Trees | A*, Collision detection |
| Cryptography | Hash-based structures | Hash functions, Merkle proofs |
| Text Editors | Stack, Trie | Undo/Redo, Pattern matching |
When you learn DSA, you are learning the vocabulary, grammar, and logic of the entire software industry. Every lesson in this curriculum brings you closer to understanding not just how to write code, but how the systems around you are built from the ground up.
*Next Lesson: Time and Space Complexity Overview — Learn how to measure and compare the efficiency of algorithms using Big O notation.*
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Applications of DSA — How Data Structures and Algorithms Power Real-World Software.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Data Structures & Algorithms topic.
Search Terms
data-structures-algorithms, data structures & algorithms, data, structures, algorithms, introduction, applications, dsa
Related Data Structures & Algorithms Topics