# What You Can Build with Data Structures

See why the same million songs can take 999,999 looks to search or only 19, which everyday app features depend on how data is organized, and what you'll build in this course.

Novice · Data Structures · Software Development · Updated November 17, 2026

By Gregor Dzierzon

## After this lesson you can

- Name everyday app features that depend on a data structure, such as undo, search, word suggestions and routes
- Explain why the way data is organized can matter more than the speed of the computer

## Key takeaways

- A data structure is a way of organizing data so the jobs an app does most are fast.
- The undo button, a search box, word suggestions and a map's route all depend on the right data structure.
- Organized well, the same million songs can be searched in 19 looks instead of 999,999.
- Each chapter ends with an exercise of your own, in the language you choose, with tests that tell you when it works.

A music app has a million songs and a search box at the top. You type a title, and the app has to find it, while you wait. How much work is that? And could the same computer do it with far less? That question, asked about songs, orders, players and routes, is what this course is about.

## A million songs, two ways

The songs are kept in A to Z order, `Song 0000001` up to `Song 1000000` (made-up titles, so the code can build them). You want `Song 0999999`, near the end.

The way anyone would try first is to read the titles from the top until you find it. It works, but it reads almost every song. The second way uses the order: look at the middle title, and since the list is sorted, you know at once which half your song is in. Throw the other half away, and look at the middle of what's left.

The code below counts how many titles each way looks at. Don't worry about reading every line yet; the course teaches all of it, and Module 4 builds the second way step by step. Pick your language in the tabs, and look at the two numbers it prints.

```csharp
List<string> songs = new List<string>();
for (int number = 1; number <= 1000000; number++)
{
    songs.Add("Song " + number.ToString("D7"));
}
string wanted = "Song 0999999";

int readingLooks = 0;
foreach (string song in songs)
{
    readingLooks++;
    if (song == wanted)
    {
        break;
    }
}

int halvingLooks = 0;
int low = 0;
int high = songs.Count - 1;
while (low <= high)
{
    int middle = (low + high) / 2;
    halvingLooks++;
    int order = string.CompareOrdinal(songs[middle], wanted);
    if (order == 0)
    {
        break;
    }
    if (order < 0)
    {
        low = middle + 1;
    }
    else
    {
        high = middle - 1;
    }
}

Console.WriteLine("Reading from the top: " + readingLooks + " looks");
Console.WriteLine("Halving the sorted list: " + halvingLooks + " looks");
```

```text
Reading from the top: 999999 looks
Halving the sorted list: 19 looks
```

```java
void main() {
    List<String> songs = new ArrayList<>();
    for (int number = 1; number <= 1000000; number++) {
        songs.add("Song " + String.format("%07d", number));
    }
    String wanted = "Song 0999999";

    int readingLooks = 0;
    for (String song : songs) {
        readingLooks++;
        if (song.equals(wanted)) {
            break;
        }
    }

    int halvingLooks = 0;
    int low = 0;
    int high = songs.size() - 1;
    while (low <= high) {
        int middle = (low + high) / 2;
        halvingLooks++;
        int order = songs.get(middle).compareTo(wanted);
        if (order == 0) {
            break;
        }
        if (order < 0) {
            low = middle + 1;
        } else {
            high = middle - 1;
        }
    }

    IO.println("Reading from the top: " + readingLooks + " looks");
    IO.println("Halving the sorted list: " + halvingLooks + " looks");
}
```

```text
Reading from the top: 999999 looks
Halving the sorted list: 19 looks
```

```python
songs = [f"Song {number:07d}" for number in range(1, 1000001)]
wanted = "Song 0999999"

reading_looks = 0
for song in songs:
    reading_looks += 1
    if song == wanted:
        break

halving_looks = 0
low = 0
high = len(songs) - 1
while low <= high:
    middle = (low + high) // 2
    halving_looks += 1
    if songs[middle] == wanted:
        break
    if songs[middle] < wanted:
        low = middle + 1
    else:
        high = middle - 1

print(f"Reading from the top: {reading_looks} looks")
print(f"Halving the sorted list: {halving_looks} looks")
```

```text
Reading from the top: 999999 looks
Halving the sorted list: 19 looks
```

```javascript
const songs = [];
for (let number = 1; number <= 1000000; number++) {
  songs.push("Song " + String(number).padStart(7, "0"));
}
const wanted = "Song 0999999";

let readingLooks = 0;
for (const song of songs) {
  readingLooks++;
  if (song === wanted) {
    break;
  }
}

let halvingLooks = 0;
let low = 0;
let high = songs.length - 1;
while (low <= high) {
  const middle = Math.floor((low + high) / 2);
  halvingLooks++;
  if (songs[middle] === wanted) {
    break;
  }
  if (songs[middle] < wanted) {
    low = middle + 1;
  } else {
    high = middle - 1;
  }
}

console.log(`Reading from the top: ${readingLooks} looks`);
console.log(`Halving the sorted list: ${halvingLooks} looks`);
```

```text
Reading from the top: 999999 looks
Halving the sorted list: 19 looks
```

```typescript
const songs: string[] = [];
for (let number = 1; number <= 1000000; number++) {
  songs.push("Song " + String(number).padStart(7, "0"));
}
const wanted = "Song 0999999";

let readingLooks = 0;
for (const song of songs) {
  readingLooks++;
  if (song === wanted) {
    break;
  }
}

let halvingLooks = 0;
let low = 0;
let high = songs.length - 1;
while (low <= high) {
  const middle = Math.floor((low + high) / 2);
  halvingLooks++;
  if (songs[middle] === wanted) {
    break;
  }
  if (songs[middle] < wanted) {
    low = middle + 1;
  } else {
    high = middle - 1;
  }
}

console.log(`Reading from the top: ${readingLooks} looks`);
console.log(`Halving the sorted list: ${halvingLooks} looks`);
```

```text
Reading from the top: 999999 looks
Halving the sorted list: 19 looks
```

Same songs, same computer, same answer: 999,999 looks against 19. A computer twice as fast wouldn't close that gap; it would read 999,999 titles a little sooner. The difference is that the songs are **organized** (sorted), and the second way takes advantage of it.

That idea has a name. A way of organizing data so the jobs you do most are fast is a **data structure**. A step-by-step way of doing a job, such as "look at the middle and throw half away", is an **algorithm**. And how an algorithm's work grows as the data grows is what **Big-O** describes, in Chapter 3. That's the whole course in one example: organize the data for the job, use an algorithm that takes advantage of it, and the work shrinks.

![A chart of looks to find one song, for playlists of 1,000, 10,000, 100,000 and 1,000,000 songs: reading from the top climbs from 1,000 to 1,000,000 looks, while halving the sorted list stays between 10 and 20 looks](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/54c43f5a99c34df0b2caf5817711eb4f.webp)

## The apps you already use

Every app that stays fast with a lot of data has made a choice like this one. You use those choices every day, even though no app tells you their names:

| What you do | What makes it work | Where this course teaches it |
|---|---|---|
| Press undo, then redo | Two **stacks**, like two piles of plates | Module 2 |
| Wait in a print queue or a support line | A **queue**, like the line at a coffee shop | Module 2 |
| See a folder's total size | **Recursion** over folders inside folders | Module 3 |
| Search a sorted list or a phone book | **Binary search**, cutting the list in half each time | Module 4 |
| Sign in, or spot a message you've already seen | A **hash table**, which finds things by name without searching | Module 5 |
| Get word suggestions as you type | A **trie**, a tree of letters | Module 6 |
| Get the quickest route on a map | A **graph** of stations and the lines between them | Module 7 |

You don't need to know any of those words yet. Each one arrives when you meet the problem it solves.

![Four small app screens side by side: a text editor with undo and redo buttons, a search box suggesting "pizza" under the letters "pi", a subway map with a highlighted route between two stations, and an inbox with one message flagged as a repeat](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/cebc76c9d237480cbad965b380a86219.webp)

## What you'll build

Every chapter ends with an exercise: a small program of your own, in the language you choose, with tests that tell you when it works. Here are a few of them:

| Module | Exercise | What it does |
|---|---|---|
| 1. Why Organizing Matters | *Race Two Solutions* | times two ways of doing the same job, and shows with a stopwatch why one falls behind |
| 2. Things in a Line | *The Coffee Shop Order Line* | serves orders in the order they came in, each in the next clean mug from the stack |
| 3. Recursion | *Menus Inside Menus* | counts the dishes on a restaurant menu with sections inside sections, finds the priciest one and prints it all |
| 4. Searching and Sorting | *Sort the Music Library* | lists a music library by artist, then album, then track number, with your own merge sort |
| 5. Fast Lookup | *The Word Counter* | finds an author's ten favorite words in a whole book |
| 6. Trees and Heaps | *Emergency Room Triage* | always calls the most urgent patient next |
| 7. Graphs, and Choosing Well | *Plan Your Class Schedule* | orders a college's courses so every course comes after the ones it needs |

## Why this course, and why now

If you're taking a Data Structures class, this is the class where many smart people decide they "aren't math people". It's usually not the math. It's that the structures arrive before anyone shows the problem they solve. Here, every structure starts the way this lesson did: with a real job where what you have isn't enough. You try the plain fixes first and see where each one breaks, and then you meet the structure that fixes it, its real name, and its symbol, read aloud. You'll learn the words your class and your interviews use, because you'll need them, but you'll never be expected to know them before they're taught.

It also helps to have taken a programming course first. If loops, lists and classes in your language feel new, Chapter 2, *The Code You Need*, reviews exactly what this course uses.

## Check yourself

2 questions to try on the lesson page.

## So what

The apps you use every day feel fast because someone chose the right data structure. By the end of this course, that someone can be you, and you'll be able to explain the choice in the words a teammate, a teacher or an interviewer expects.

## Key terms

- [Data Structure](https://www.ask-codey.com/glossary/data-structure)
- [Algorithm](https://www.ask-codey.com/glossary/algorithm)
- [Big-O Notation](https://www.ask-codey.com/glossary/big-o-notation)

## Cheat sheets

- [What You Can Build with Data Structures](https://www.ask-codey.com/cheat-sheets/ds-what-you-can-build-cheat-sheet)

Source: https://www.ask-codey.com/lessons/ds-what-you-can-build
