Mastering the Blind 75 for System Design Interviews
Data Structures
Ways to Organize Data
When you write a program, you're constantly working with data. Data structures are simply different ways of organizing that data so you can use it effectively. Choosing the right structure for a task can make your code much faster and easier to manage. Let's look at some of the most fundamental building blocks.
Data structures are formats for the organization, management, and storage of data that enable efficient access and modification.
Arrays
The simplest data structure is the array. Think of it as a row of numbered boxes, one right after the other. Each box holds a piece of data, and you can find any box instantly if you know its number, or index. In most programming languages, the first box is index 0, the second is index 1, and so on.
Because all the boxes are lined up together in memory, computers are incredibly fast at jumping to a specific index. This makes arrays great for situations where you need to quickly access elements by their position.
The downside? Arrays have a fixed size. If you want to add an element to a full array, you have to create a new, bigger array and copy everything over. Similarly, inserting an element in the middle requires shifting all subsequent elements down one spot, which can be slow if the array is large.
Linked Lists
What if you need a list that can easily grow and shrink? A linked list is a great alternative to an array. Instead of storing elements side-by-side in memory, a linked list stores each element in its own object, called a node. Each node contains two things: the data itself and a pointer, or link, to the next node in the sequence.
This structure is like a scavenger hunt. You start at the first node (the head), and it tells you where to find the second. The second tells you where to find the third, and so on, until you reach a node that points to null, marking the end of the list.
The trade-off here is the reverse of an array's. Adding or removing nodes is very efficient, you just need to change a couple of pointers. But if you want to get to the 50th element, you have no choice but to start at the head and follow 49 links to get there. There's no way to jump directly to an element.
Stacks & Queues
Stacks and queues are specialized data structures that restrict how you add and remove elements. They aren't about storing data for general access; they're about managing a flow of items.
A stack follows a LIFO (Last-In, First-Out) principle. Imagine a stack of plates: you add a new plate to the top, and you also take a plate from the top. The last plate you put on is the first one you take off.
The main operations are push (add to the top) and pop (remove from the top). This is useful for things like the 'undo' functionality in a text editor or managing function calls in a program.
A queue follows a FIFO (First-In, First-Out) principle. This is just like a line at a grocery store. The first person to get in line is the first person to be served.
The operations are enqueue (add to the back of the line) and dequeue (remove from the front). Queues are perfect for managing tasks, like print jobs sent to a printer or requests coming into a web server.
Hash Tables
What if you want to store and retrieve data not by a numerical index, but by a meaningful key? For example, looking up a person's phone number using their name. This is what hash tables (also called hash maps or dictionaries) are for.
A hash table uses a special hash function to convert a key (like the name "Alice") into a numerical index. It then uses that index to store the value (Alice's phone number) in an underlying array. When you want to look up "Alice" again, it runs her name through the same hash function, gets the same index, and retrieves the number instantly.
This makes insertions, deletions, and lookups incredibly fast, usually happening in what's considered constant time. The main challenge is designing a good hash function that distributes keys evenly across the array to avoid collisions (when two different keys hash to the same index). But when implemented well, hash tables are one of the most powerful and widely used data structures.
Trees & Graphs
Arrays and linked lists are linear—they represent a simple sequence. Trees and graphs are non-linear structures that represent more complex relationships.
A tree is a hierarchical structure. It starts with a single root node, and each node can have several child nodes. Think of a family tree or a file system directory. An important rule is that a tree can't have cycles; you can never follow the links and end up back where you started.
A graph is a more general structure. It consists of a set of nodes (or vertices) and the lines connecting them (edges). Unlike trees, graphs can have cycles. They can represent anything from a social network (people are vertices, friendships are edges) to a map (cities are vertices, roads are edges).
Trees are often used for efficient searching and sorting (like in a binary search tree) or for storing data that has a natural hierarchy. Graphs are the go-to for modeling networks and finding the best path between two points.
You are building a playlist application where users will frequently add and remove songs from the middle of their playlists. Which data structure would be most efficient for this specific task?
A queue data structure operates on a "First-In, First-Out" (FIFO) principle.
These are the fundamental tools for organizing data. Understanding their strengths and weaknesses is the first step toward writing clean, efficient, and effective code.