DSA Toolbox 📚
Welcome to DSA Toolbox, a comprehensive library of data structures and algorithms designed to streamline your development process! This library is built for JavaScript and TypeScript, offering both fundamental and advanced data structures, search algorithms, sort algorithms, and more.
Whether you're building a lightweight application or handling large datasets, DSA Toolbox provides an optimized library to make your coding journey efficient and fun.
✨ Features
DSA Toolbox offers a variety of powerful toolbox:
🔎 Search Algorithms
- Binary Search
- Exponential Search
- Hybrid Search
- Linear Search
- Ternary Search
🧮 Sort Algorithms
- HeapSort
- MergeSort
- TimSort
🔄 Cache Algorithms
- LFU (Least Frequently Used)
- LRU (Least Recently Used)
🏗️ Data Structures
- Heaps: MaxHeap, MinHeap
- Linked Lists: Singly Linked List, Doubly Linked List
- Queues & Stacks
- Treaps (Binary Search Tree with heap properties)
- Trees: AVL Tree, Red-Black Tree, Binary Search Tree, B-Tree, Trie
- Probabilistic Structures: Bloom Filter, HyperLogLog, CountMinSketch, SkipList, MinHash, SimHash, TDigest
📊 Functional Programming (FP)
- Composition: Function composition for declarative programming
- Currying: Transforming functions into unary functions
- Functors: CanApply for safe function application
- Monads:
- Option: Safe handling of optional values (Some, None)
- Result<T, E>: Error handling without exceptions (Ok, Err)
- Effect<T, E>: Deferred computations with error safety
- Pattern Matching: Expressive control flow using Match (matcher, case-of)
- Lenses & Optics: Immutable state manipulation (Lens, Prism, Traversal)
- Trampoline: Converts deep recursion into iteration to prevent stack overflows
- Transducers: Composable data transformations with high performance (map, filter, reduce fused)
Benchmarks
Data Structures Benchmarks
| (index) | dataStructure | operation | size | time (ms) |
|---|
| 0 | Native Array | Insert | 1000 | 0.0042 |
| 1 | Native Array | Search | 1000 | 0.0015 |
| 2 | Native Array | Delete | 1000 | 0.0008 |
| 3 | Queue | Insert (Enqueue) | 1000 | 0.1306 |
| 4 | Queue | Delete (Dequeue) | 1000 | 0.1355 |
| 5 | Stack | Insert (Push) | 1000 | 0.1216 |
| 6 | Stack | Delete (Pop) | 1000 | 0.1128 |
| 7 | Binary Search Tree | Insert | 1000 | 0.3302 |
| 8 | Binary Search Tree | Search | 1000 | 0.0431 |
| 9 | Binary Search Tree | Delete | 1000 | 0.0308 |
| 10 | Red-Black Tree | Insert | 1000 | 0.8018 |
| 11 | Red-Black Tree | Search | 1000 | 0.0202 |
| 12 | Red-Black Tree | Delete | 1000 | 0.0791 |
| 13 | AVL Tree | Insert | 1000 | 0.6278 |
| 14 | AVL Tree | Search | 1000 | 0.0117 |
| 15 | AVL Tree | Delete | 1000 | 0.0189 |
| 16 | Trie | Insert | 1000 | 0.3451 |
| 17 | Trie | Search | 1000 | 0.0157 |
| 18 | Trie | Delete | 1000 | 0.0184 |
| 19 | Min Heap | Insert | 1000 | 0.1854 |
| 20 | Min Heap | Extract |
Suggested Applications:
- Small Data: For datasets around 1,000 elements, Native Arrays, Queues, and Stacks provide excellent performance.
- Medium Data: Up to 10,000 elements, use AVL Tree for balanced tree operations and Min/Max Heap for priority-based insert/extract operations.
- Large Data: At 100,000 elements, consider using B-Trees or Red-Black Trees for optimized insertion and search performance.
- Extra Large Data: Beyond 1,000,000 elements, B-Trees, with their balanced and efficient nature, are superior for handling large datasets, especially for search and delete operations.
Algorithms Benchmarks
| (index) | algorithm | operation | size | time (ms) |
|---|
| 0 | Heap Sort | Sort | 1000 | 1.1344 |
| 1 | Merge Sort | Sort | 1000 | 0.6770 |
| 2 | Tim Sort | Sort | 1000 | 0.5847 |
| 3 | Native Sort | Sort | 1000 | 0.1421 |
| 4 | Binary Search | Search | 1000 | 0.0278 |
| 5 | Exponential Search | Search | 1000 | 0.0265 |
| 6 | Hybrid Search | Search | 1000 | 0.0377 |
| 7 | Linear Search | Search | 1000 | 0.0218 |
| 8 | Ternary Search | Search | 1000 | 0.0259 |
| 9 | Heap Sort | Sort | 10000 | 2.6921 |
| 10 | Merge Sort | Sort | 10000 | 3.4185 |
| 11 | Tim Sort | Sort | 10000 | 2.1583 |
| 12 | Native Sort | Sort | 10000 | 1.2181 |
| 13 | Binary Search | Search | 10000 | 0.0050 |
| 14 | Exponential Search | Search | 10000 | 0.0062 |
| 15 | Hybrid Search | Search | 10000 | 3.5105 |
| 16 | Linear Search | Search | 10000 | 0.0740 |
| 17 | Ternary Search | Search | 10000 | 0.0067 |
| 18 | Heap Sort | Sort | 100000 | 18.3146 |
| 19 | Merge Sort | Sort | 100000 | 24.6636 |
| 20 | Tim Sort | Sort | 100000 |