Introduction to Data Structures and Algorithms
Read at your own pace. Code execution, quizzes, progress tracking, and the AI tutor are available in the interactive view with JavaScript enabled.
Welcome Aboard
Why this lesson matters
This is the starting line for the Fidelity-Data Structures course. Before we study arrays, linked lists, stacks, queues, trees, graphs, hash tables, sorting, searching, recursion, and dynamic programming, we need a shared mental model.
In this lesson, you will learn:
- What data structures are
- What algorithms are
- Why the two are usually discussed together
- How to reason about code beyond “does it work?”
- The basic vocabulary we will reuse throughout the course
Think of this lesson as your map. Later lessons will zoom into specific neighborhoods.

Two Core Ideas
Data structures organize information
A data structure is a way to store and arrange data so that it can be used efficiently.
Examples you may already know in JavaScript:
- An array stores ordered values:
[10, 20, 30] - An object stores key-value pairs:
{ name: "Ada", level: 3 } - A
Mapstores flexible key-value relationships
Algorithms transform information
An algorithm is a step-by-step process for solving a problem.
Examples:
- Find the largest number in a list
- Check whether a username already exists
- Count how many times a value appears
- Decide the shortest path between two points
The key idea: data structures hold the data; algorithms do useful work with it.

A Tiny Algorithm
Example: find the maximum
Let’s start with a small algorithm: find the largest number in an array.
We do not need advanced tools yet. The important part is the process:
- Assume the first value is the largest
- Look at each remaining value
- If a value is larger, update the answer
- Return the final answer
This pattern—keep track of useful state while scanning data—will appear again and again.
```javascript
function findMax(numbers) {
if (numbers.length === 0) {
return undefined;
}
let max = numbers[0];
for (let i = 1; i < numbers.length; i++) {
if (numbers[i] > max) {
max = numbers[i];
}
}
return max;
}
console.log(findMax([4, 9, 2, 17, 6])); // 17
console.log(findMax([-10, -3, -25])); // -3
console.log(findMax([])); // undefined
```
Structure Or Algorithm
You need to store a list of customer IDs in the order they signed up.
Which concept is most directly involved in choosing how to store that ordered collection?
Why Complexity Matters
Working code is not always good enough
For small inputs, almost any correct solution may feel fast. But data structures and algorithms matter because input sizes grow.
Imagine checking whether a number appears in a list:
- With 5 items, scanning everything is fine
- With 5 million items, the choice of approach matters
A useful habit is asking: as the input grows, how does the work grow?
We often describe this with Big O notation, a high-level way to talk about growth. You do not need every detail yet—just focus on the idea that some solutions scale better than others.
```javascript
function countChecks(numbers, target) {
let checks = 0;
for (const number of numbers) {
checks++;
if (number === target) {
return checks;
}
}
return checks;
}
console.log(countChecks([5, 8, 12, 20], 5)); // 1 check
console.log(countChecks([5, 8, 12, 20], 20)); // 4 checks
console.log(countChecks([5, 8, 12, 20], 99)); // 4 checks
```
Input Growth
True or false: If an algorithm works correctly for 10 items, it will always be efficient for 10 million items.
Choosing Structures
The shape of data affects the solution
A good data structure makes the important operations easier.
Before writing code, ask:
- Do I need to preserve order?
- Do I need fast lookup by key?
- Do I add and remove items often?
- Do relationships matter, like parent/child or connected nodes?
- Can duplicate values appear?
There is rarely one “best” data structure for everything. Instead, there are tradeoffs.
For example, if you care about order, one structure may fit well. If you care about quick key-based lookup, another may be better. Upcoming lessons will give names and details to these choices.

Complete The Pair
A data structure organizes data, while an ________ is a step-by-step process for solving a problem.
JavaScript Toolbox
JavaScript already gives you useful structures
In this course, we will use JavaScript to explore data structures and algorithms. Some structures are built into the language, while others we can build ourselves.
Common built-ins include:
-
Arrayfor ordered collections -
Objectfor simple key-value data -
Mapfor key-value data with flexible keys -
Setfor unique values
The goal is not to memorize every method. The goal is to understand when a structure matches the problem.
```javascript
const names = ["Maya", "Omar", "Maya", "Lina"];
console.log(names[0]); // Maya
const userScores = {
Maya: 92,
Omar: 85
};
console.log(userScores.Maya); // 92
const uniqueNames = new Set(names);
console.log([...uniqueNames]); // [ 'Maya', 'Omar', 'Lina' ]
const roles = new Map();
roles.set("Maya", "admin");
roles.set("Omar", "viewer");
console.log(roles.get("Omar")); // viewer
```
Mental Model Check
A team is deciding between two correct solutions. One is simpler but slows down heavily as the input grows. The other is slightly more complex but handles large inputs well.
What are they mainly comparing?
Learning Loop
How to approach this course
For each upcoming topic, use the same loop:
- Understand the problem: What data do we have? What do we need?
- Choose a structure: How should the data be organized?
- Design an algorithm: What steps solve the problem?
- Analyze tradeoffs: How does it behave as input grows?
- Practice: Apply the idea to easy and medium problems
Next, we will start with one of the most common foundations: Arrays and Linked Lists. Keep today’s questions in mind: what operations matter, and how does the structure affect the algorithm?
