$ show loiane/javascript-datastructures-algorithms
This repository is an educational library providing implementations of fundamental data structures and algorithms in JavaScript and TypeScript. It covers arrays, stacks, queues, linked lists, sets, dictionaries/hash tables, trees (BST, AVL, Red-Black, Fenwick, Segment), heaps, tries, and graphs, along with associated algorithms (sorting, searching, graph traversals, shortest paths, minimum spanning trees). The code is well-structured, generic, and thoroughly tested with Jest. Each data structure and algorithm is presented as an independent module, making it easy to study or reuse. The TypeScript versions include type annotations and complexity documentation. While primarily a learning resource, the implementations are production-quality and can be extracted for use in other projects.
The LLM identified 5 files worth highlighting for reuse:
A generic AVL tree implementation that extends BinarySearchTree. It maintains balance through left and right rotations (including left-right and right-left cases) after insertions and deletions. The code is self-contained, uses a comparator for flexibility, and includes comprehensive traversal methods (in-order, pre-order, post-order). It demonstrates non-obvious skill in implementing tree rotations and balance factor calculations.
A generic Red-Black tree implementation with insertion fixup that handles all cases (uncle red, rotations) to maintain the red-black properties. It includes deletion with rebalancing. The code is well-documented, uses a comparator, and provides traversal methods. It demonstrates advanced understanding of tree balancing and color flipping.
A generic heap (priority queue) implementation supporting min-heap or max-heap via a custom comparator. It provides insert, extract, heapify, peek, and clear operations. The heapify method builds a heap in O(n) time. The code is clean, generic, and reusable for any comparable type.
A trie (prefix tree) implementation with insert, search, startsWith, and remove operations. The remove method recursively deletes nodes and cleans up unused branches. The code is self-contained, uses a Map for children, and demonstrates non-trivial recursive deletion logic.
An implementation of Dijkstra's shortest-path algorithm for weighted graphs represented as adjacency matrices. It returns both the shortest distances and the predecessor paths for all vertices. The code is clean, uses a helper function for minimum distance selection, and constructs full paths from predecessors. It is a standalone, reusable algorithm module.