This is the coding implementations of the DSA.js book and the repo for the NPM package.
In this repository, you can find the implementation of algorithms and data structures in JavaScript. This material can be used as a reference manual for developers, or you can refresh specific topics before an interview. Also, you can find ideas to solve problems more efficiently.
You can clone the repo or install the code from NPM:
npm install dsa.js
and then you can import it into your programs or CLI
const { LinkedList, Queue, Stack } = require('dsa.js');
For a full list of all the exposed data structures and algorithms see.
Algorithms are an essential toolbox for every programmer.
You usually need algorithms when you have to sort data, search for a value, transform data, scale your code to many users, to name a few. Algorithms are just the step you follow to solve a problem while data structures are where you store the data for later manipulation. Both combined create programs.
Algorithms + Data Structures = Programs.
Most programming languages and libraries indeed provide implementations for basic data structures and algorithms. However, to make use of data structures properly, you have to know the tradeoffs so you can choose the best tool for the job.
This material is going to teach you to:
- 🛠 Apply strategies to tackle algorithm questions. Never to get stuck again. Ace those interviews!
- ✂️ Construct efficient algorithms. Learn how to break down problems in manageable pieces.
- 🧠 Improve your problem-solving skills and become a stronger developer by understanding fundamental computer science concepts.
- 🤓 Cover essential topics, such as big O time, data structures, and must-know algorithms. Implement 10+ data structures from scratch.
All the code and explanations are available on this repo. You can dig through the links and code examples from the (src folder). However, the inline code examples are not expanded (because of Github's asciidoc limitations), but you can follow the path and see the implementation.
Note: If you prefer to consume the information more linearly then the book format would be more appropriate for you.
The topics are divided into four main categories as you can see below:
(You can click on the triangle ⯈ to expand the topics)
Computer Science nuggets without all the mumbo-jumbo
Learn how to compare algorithms using Big O notation.
Let's say you want to find the duplicates on an array. Using Big O notation, we can compare different implementations that do the same but they take different time to complete.
8 examples to explain with code how to calculate time complexity
8 examples to explain with code how to calculate time complexity
Understand the ins and outs of the most common data structures.
Arrays: Built-in in most languages so not implemented here. Array Time complexity
Linked List: each data node has a link to the next (and previous). Code | Linked List Time Complexity
Queue: data flows in a "first-in, first-out" (FIFO) manner. Code | Queue Time Complexity
Stack: data flows in a "last-in, first-out" (LIFO) manner. Code | Stack Time Complexity
When to use an Array or Linked List. Know the tradeoffs.
Use Arrays when…
- You need to access data in random order fast (using an index).
- Your data is multi-dimensional (e.g., matrix, tensor).
Use Linked Lists when:
- You will access your data sequentially.
- You want to save memory and only allocate memory as you need it.
- You want constant time to remove/add from extremes of the list.
Build a List, Stack, and a Queue.
Build any of these data structures from scratch: