My own implementations of common data structures and algorithms in JavaScript. I wrote them to really understand how they work inside instead of only using built-in methods, and to prepare for coding interviews. Every one of them has Jest tests.
| Name | Main methods | Code |
|---|---|---|
| Linked List | add, insert, remove, removeAt, get, toArray |
LinkedList.js |
| Stack | push, pop, peek, size, isEmpty |
Stack.js |
| Hash Table | set, get, delete, has, getValue |
HashTable.js |
| Heap (max) with heap sort | add, remove, sort, find |
Heap.js |
| Max Heap | add, pop, peek |
MaxHeap.js |
| Min Heap | add, remove, peek, find |
MinHeap.js |
| Name | What it does | Code |
|---|---|---|
| Binary Search | Finds an element in a sorted array in O(log n) | BinarySearch.js |
| Kadane's Algorithm | Finds the maximum subarray sum in O(n) | KadanesAlgorithm.js |
| Tortoise and Hare (Floyd) | Finds the start of a cycle in a linked list | TortoiseHare.js |
- JavaScript (Node.js)
- Jest for tests
git clone https://github.com/IkboljonMe/javascript-algorithms.git
cd javascript-algorithms
npm install
npm testRun tests only for one folder, for example the linked list:
npm test -- linked-list- Queue
- Binary Search Tree
- Trie
- Graph (BFS, DFS)
MIT, see LICENSE.
Made by IkboljonMe