12 Data Structures You Use Every Day

Algorithms

  1. Dynamic Programming

Spell checkers measure how far your typo is from real words by computing the edit distance, the fewest insertions, deletions and swaps needed to turn one word into another. That table of smaller answers is classic dynamic programming.

1. Dynamic Programming

Spell checkers suggest the right word.

They compare your typo with dictionary words using edit distance, built one small subproblem at a time.

"cut" is 1 edit away from "cat"

  1. Arrays

A digital photo is a grid of pixels.

2. Arrays

An image is a 2D array of pixels.

Any pixel is read instantly from its row and column, which is how filters touch every pixel quickly.

pixels[row][col]

  1. Graphs

Flight search treats airports as vertices and direct flights as edges. Finding a trip with connections is a path search through that graph.

3. Graphs

Airline networks are graphs.

Airports are vertices and direct flights are edges.

  1. Breadth First Search

Professional networks group people by how many introductions away they are. First degree connections are one hop away, second degree are two hops away, which is exactly the order BFS visits them.

4. Breadth First Search

Networking sites rank people by degrees of connection.

BFS explores everyone one hop away before anyone two hops away.

Orange: 1st degree. Teal: 2nd degree.

  1. Sorting Algorithms

Game leaderboards keep millions of scores in order so the top players appear first.

5. Sorting Algorithms

Leaderboards sort scores from highest to lowest.

Built-in sorts like Timsort mix merge sort and insertion sort to handle partly sorted data fast.

  1. Linked Lists

A music player's queue keeps a pointer to the previous and next song, so skipping back and forth or inserting a song in the middle never shifts the rest of the queue.

6. Linked Lists

Music queues are doubly linked lists.

Each song points to the next and previous one, so inserting or skipping is O(1).

next → ← previous

  1. Hash Tables

Your phone's contacts app looks names up in a hash table, so finding a number takes the same time whether you have ten contacts or ten thousand.

7. Hash Tables

Contacts apps map names to numbers.

Hashing the name jumps straight to the entry, with no scan through the list.

  1. Topological Sort

Course planners use topological sorting to order classes so that every prerequisite comes before the classes that need it.

8. Topological Sort

Degree planners order courses by prerequisites.

A course is scheduled only after everything pointing into it is done.

Intro → Data → Web → Algo → Sys → AI

  1. Trees

Every web page is a tree. The browser's DOM nests elements inside elements, and rendering or searching the page walks that tree.

9. Trees

Web pages are trees of HTML elements.

Each tag is a node, and the tags nested inside it are its children.

  1. Heaps

Operating systems pick the next process to run from a priority queue, so urgent work like handling a key press jumps ahead of background jobs.

10. Heaps

Schedulers run the most urgent task first.

A heap always keeps the highest priority task on top, ready in O(1).

Top of the heap runs next

  1. Dijkstra's Algorithm

Navigation apps find the quickest route by treating intersections as vertices and roads as weighted edges, where the weight is the expected travel time.

11. Dijkstra's Algorithm

Map apps find the fastest route.

Roads are weighted edges, and Dijkstra always expands the closest unexplored intersection next.

Fastest A → E: 2 + 3 + 2 = 7 minutes

  1. Binary Search

When an outage starts, engineers search sorted logs by timestamp. Halving the range each time finds the first error among millions of lines in about twenty checks.

12. Binary Search

Finding the first error in sorted logs.

Check the middle entry, then keep only the half that must contain the first failure.

8 entries, found in 3 checks