- Home
- /
- Tutorials
- /
- DSA Tutorial
- /
- What Are Data Structures and Algorithms
DSA Introduction
What Are Data Structures and Algorithms
A data structure is how you store data. An algorithm is what you do with it. Choosing badly on either one is the difference between a page that loads instantly and one that times out.
The short version
A data structure is an arrangement of data. An array, an object, a Map, a tree. Each one is fast at some things and slow at others.
An algorithm is a sequence of steps that produces a result. Searching, sorting, counting, finding a path.
They are not separate topics. Picking the right structure is usually most of the work, and the algorithm follows from it.
Why it matters, with numbers
Say you have 10,000 users and you need to look one up by id. Two ways to store them:
The same task, two structures
javascript
const users = [ /* 10,000 objects */ ]
// Array: check every element until you find it.
function findInArray(id) {
for (const user of users) {
if (user.id === id) return user
}
}
// Map: jump straight to it.
const byId = new Map(users.map((u) => [u.id, u]))
function findInMap(id) {
return byId.get(id)
}findInArray may check all 10,000 entries. findInMap checks one. At 10,000 users you might not notice. At 10 million you will, and so will your server bill.
Nothing about that is JavaScript-specific. It is the same in every language, which is why interviews ask about it.
What this tutorial covers
Every example here is plain JavaScript that runs in the editor on each page. No frameworks, no build step, no libraries - the point is the idea, not the tooling.
- Complexity - how to say "this gets slower as the input grows" precisely.
- Core structures - arrays, strings, hash maps, stacks, queues, linked lists, trees, graphs.
- Core techniques - recursion, sorting, searching, dynamic programming, greedy.
- Patterns - the handful of shapes that most interview questions turn out to be.
What you need first
Comfortable JavaScript: functions, loops, arrays, objects, and how const and let differ. If any of that is shaky, work through the JavaScript tutorial first - this one moves quickly and assumes it.
You do not need maths beyond arithmetic. Big O looks like maths and is really just a way of describing shape.
