Algorithms and Data Structures in JavaScript

Hello Readers!

I’ve recently launched JavaScript Algorithms and Data Structures repository on GitHub with collection of classic algorithms and data-structures implemented in ES6 JavaScript with explanations and links to further readings and YouTube videos.

So I guess you’ve already grasp main idea of the project - helping developers to learn and practice algorithms and do it in JavaScript.

To make this process even smoother I’ve tried to put some graphical illustrations for each algorithm and data structure where it was possible just to make the idea behind those algorithms to be easily grasped and memorized.

You also may find some practical information just in the root README file that may be handy while you’re studying. Such information as:

  • big O notation graphs - to see quickly what is worse O(n!) or, let’s say, O(n²)
  • list of some of the most used Big O notations and their performance comparisons - to get the idea how big is 10! (it is 3628800)
  • data structures operations complexity - how fast are searches, reads or insertions for different data-structures
  • comparative table of sorting algorithms complexity - to help you choose proper sorting algorithm in your situation

All code is 100% covered with tests. This is done not only to keep code working correctly but also to give you an illustration of how each algorithms or data structure works, what basic operations they have (let’s say polling for heap) and what are the edge cases (what to do if graph is directed).

Repository also has a playground. This is just small function template along with empty test case that will help you to start testing or working on algorithms just right after cloning the repo.

Currently there are following data structures a covered:

  • Linked List
  • Queue
  • Stack
  • Hash Table
  • Heap
  • Priority Queue
  • Trie
  • Tree (Binary Search Tree, AVL Tree, Red-Black Tree)
  • Graph (both directed and undirected)
  • Disjoint Set

On top of that data structures there are more then 50 popular algorithms are implemented. Among them are sorting, searching algorithms, graph/tree/sets/string/math related algorithms. All algorithms are also categorized by theirs paradigms:

  • Brute Force Algorithms - look at all the possibilities and selects the best solution
  • Greedy Algorithms - choose the best option at the current time, without any consideration for the future
  • Divide and Conquer Algorithms - divide the problem into smaller parts and then solve those parts**
  • Dynamic Programming Algorithms - build up to a solution using previously found sub-solutions
  • Backtrackig Algorithms - similarly to brute force try to generate all possible solutions but each time you generate a solution test if it satisfies all conditions, and only then continue generating subsequent solutions. Otherwise backtrack and go on a different path of finding solution

JavaScript Algorithms and Data Structures repository is still under active development and more algorithms and data-structures are yet to come. And you may also be a part of it by contributing your code and your implementations of web-known algorithms!

I hope this repository will be helpful for you! Enjoy coding!


Not a big fan of algorithms but i think you had made a really really good job in there. I just picked the bubble sorting and the animation is more then exaplanatory. Good job. Saved the link to your repo and you have +1 star from me. :+1:

Thank you @sorinr! I’m glad that you liked the repo. That was the main point to make algorithms explanations and the code a little bit more readable and easily memorizable.

1 Like

Hey, @trekhleb this is awesome!

I’m a few years into my career and I’ve gotten by with application development skills, but I’ve finally hit a ceiling. I’m struggling through technical interviews because I had zero CS and little experience with algorithms. On FCC, Interview Cake, HackerRank, LeetCode, all the challenges take me hours to figure it out (if I even complete it at all).

Besides this repo, do you have any advice about how to start learning and applying algorithms? I feel like I might have the building blocks, but I don’t know how to fit them together.

For example, I understand recursion, but I don’t really know when I need to reach for it.

Thanks for your time.