PageSourceSearch

https://data-structure-typed-docs.vercel.app/assets/js/f43d0be6.bbbf432b.js

js data-structure-typed-docs.vercel.app collected 2026-10-03 06:31:58 UTC 37,141 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkdocs_site_docusaurus=globalThis.webpackChunkdocs_site_docusaurus||[]).push([[5247],{1218(e,n,r){r.r(n),r.d(n,{assets:()=>l,contentTitle:()=>d,default:()=>u,frontMatter:()=>a,metadata:()=>t,toc:()=>c});const t=JSON.parse('{"id":"guide/overview","title":"Data Structures Overview \u2014 Trees, Heaps, Graphs, Queues","description":"Complete overview of all 20+ data structures: trees, heaps, graphs, queues, linked lists, hash maps, and more.","source":"@site/docs/guide/overview.md","sourceDirName":"guide","slug":"/guide/overview","permalink":"/docs/guide/overview","draft":false,"unlisted":false,"editUrl":"https://github.com/zrwusa/data-structure-typed/edit/main/docs-site-docusaurus/docs/guide/overview.md","tags":[],"version":"current","frontMatter":{"sidebar_label":"OVERVIEW","description":"Complete overview of all 20+ data structures: trees, heaps, graphs, queues, linked lists, hash maps, and more.","title":"Data Structures Overview \u2014 Trees, Heaps, Graphs, Queues","keywords":["typescript data structures overview","red black tree","heap","priority queue","trie","graph","deque","treemap","treeset"]},"sidebar":"guideSidebar","previous":{"title":"CONCEPTS","permalink":"/docs/guide/concepts"},"next":{"title":"GUIDES","permalink":"/docs/guide/guides"}}');var s=r(4848),i=r(8453);const a={sidebar_label:"OVERVIEW",description:"Complete overview of all 20+ data structures: trees, heaps, graphs, queues, linked lists, hash maps, and more.",title:"Data Structures Overview \u2014 Trees, Heaps, Graphs, Queues",keywords:["typescript data structures overview","red black tree","heap","priority queue","trie","graph","deque","treemap","treeset"]},d="OVERVIEW",l={},c=[{value:"Table of Contents",id:"table-of-contents",level:2},{value:"Quick Reference Table",id:"quick-reference-table",level:2},{value:"All Data Structures",id:"all-data-structures",level:2},{value:"Stack Structure",id:"stack-structure",level:3},{value:"Stack",id:"stack",level:4},{value:"Linear Structures",id:"linear-structures",level:3},{value:"Queue",id:"queue",level:4},{value:"Deque",id:"deque",level:4},{value:"Linked Lists",id:"linked-lists",level:4},{value:"Tree Structures",id:"tree-structures",level:3},{value:"Binary Search Tree (BST)",id:"binary-search-tree-bst",level:4},{value:"Red-Black Tree",id:"red-black-tree",level:4},{value:"AVL Tree",id:"avl-tree",level:4},{value:"TreeMap (Ordered Map)",id:"treemap-ordered-map",level:4},{value:"TreeSet (Ordered Set)",id:"treeset-ordered-set",level:4},{value:"Order-Statistic Tree (Rank Queries)",id:"order-statistic-tree-rank-queries",level:4},{value:"Heap & Priority Queue",id:"heap--priority-queue",level:3},{value:"Heap",id:"heap",level:4},{value:"Priority Queue",id:"priority-queue",level:4},{value:"Special Structures",id:"special-structures",level:3},{value:"Trie (Prefix Tree)",id:"trie-prefix-tree",level:4},{value:"Graph",id:"graph",level:4},{value:"CRUD Operations",id:"crud-operations",level:2},{value:"Create (Add)",id:"create-add",level:3},{value:"Read (Query)",id:"read-query",level:3},{value:"Update (Modify)",id:"update-modify",level:3},{value:"Delete",id:"delete",level:3},{value:"Common Methods",id:"common-methods",level:2},{value:"Available on All Structures",id:"available-on-all-structures",level:3},{value:"Raw Data Mapping",id:"raw-data-mapping",level:3},{value:"Structure-Specific Methods",id:"structure-specific-methods",level:3},{value:"Trees",id:"trees",level:4},{value:"Deque",id:"deque-1",level:4},{value:"Graph",id:"graph-1",level:4},{value:"TypeScript Support",id:"typescript-support",level:2},{value:"Full Generic Support",id:"full-generic-support",level:3},{value:"Type Safety Examples",id:"type-safety-examples",level:3},{value:"Complexity Chart",id:"complexity-chart",level:2},{value:"Common Patterns",id:"common-patterns",level:2},{value:"Iterator Pattern",id:"iterator-pattern",level:3},{value:"Filtering Pattern",id:"filtering-pattern",level:3},{value:"Sorting Pattern",id:"sorting-pattern",level:3},{value:"SkipList",id:"skiplist",level:2},{value:"SegmentTree",id:"segmenttree",level:2},{value:"BinaryIndexedTree (Fenwick Tree)",id:"binaryindexedtree-fenwick-tree",level:2},{value:"Matrix",id:"matrix",level:2}];function o(e){const n={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",hr:"hr",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.header,{children:(0,s.jsx)(n.h1,{id:"overview",children:"OVERVIEW"})}),"\n",(0,s.jsxs)(n.p,{children:["A quick-reference guide to all structures, common operations, and usage patterns. For complete API details with method signatures and examples, see the ",(0,s.jsx)(n.strong,{children:(0,s.jsx)(n.a,{href:"https://data-structure-typed-docs.vercel.app/",children:"Full API Docs"})}),"."]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.strong,{children:[(0,s.jsx)(n.a,{href:"/docs/guide/quick-start",children:"Back to README"})," \u2022 ",(0,s.jsx)(n.a,{href:"https://data-structure-typed-docs.vercel.app/",children:"API Docs"})," \u2022 ",(0,s.jsx)(n.a,{href:"/docs/guide/guides",children:"Real-World Examples"})," \u2022 ",(0,s.jsx)(n.a,{href:"/docs/guide/performance",children:"Performance"})]})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"table-of-contents",children:"Table of Contents"}),"\n",(0,s.jsxs)(n.ol,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#quick-reference-table",children:"Qu
1ick Reference Table"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#all-data-structures",children:"All Data Structures"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#crud-operations",children:"CRUD Operations"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#common-methods",children:"Common Methods"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#typescript-support",children:"TypeScript Support"})}),"\n"]}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"quick-reference-table",children:"Quick Reference Table"}),"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Data Structure"}),(0,s.jsx)(n.th,{children:"Best Use Case"}),(0,s.jsx)(n.th,{children:"Time Complexity"}),(0,s.jsx)(n.th,{children:"Space"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"Array"})}),(0,s.jsx)(n.td,{children:"Direct indexed access"}),(0,s.jsx)(n.td,{children:"O(n) insert/delete"}),(0,s.jsx)(n.td,{children:"O(n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"Linked List"})}),(0,s.jsx)(n.td,{children:"Dynamic size, fast insert"}),(0,s.jsx)(n.td,{children:"O(n) search, O(1) insert"}),(0,s.jsx)(n.td,{children:"O(n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"Stack"})}),(0,s.jsx)(n.td,{children:"Undo/redo, DFS"}),(0,s.jsx)(n.td,{children:"O(1) all"}),(0,s.jsx)(n.td,{children:"O(n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"Queue"})}),(0,s.jsx)(n.td,{children:"FIFO processing"}),(0,s.jsx)(n.td,{children:"O(1) all"}),(0,s.jsx)(n.td,{children:"O(n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"Deque"})}),(0,s.jsx)(n.td,{children:"Head/tail operations"}),(0,s.jsx)(n.td,{children:"O(1) all"}),(0,s.jsx)(n.td,{children:"O(n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"Binary Tree"})}),(0,s.jsx)(n.td,{children:"Hierarchical data"}),(0,s.jsx)(n.td,{children:"O(n) avg"}),(0,s.jsx)(n.td,{children:"O(n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"BST"})}),(0,s.jsx)(n.td,{children:"Sorted search"}),(0,s.jsx)(n.td,{children:"O(log n) avg"}),(0,s.jsx)(n.td,{children:"O(n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"RedBlackTree"})}),(0,s.jsx)(n.td,{children:"Guaranteed sorted"}),(0,s.jsx)(n.td,{children:"O(log n) guaranteed"}),(0,s.jsx)(n.td,{children:"O(n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"AVL Tree"})}),(0,s.jsx)(n.td,{children:"Balanced sorted"}),(0,s.jsx)(n.td,{children:"O(log n) guaranteed"}),(0,s.jsx)(n.td,{children:"O(n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"Heap"})}),(0,s.jsx)(n.td,{children:"Priority queue"}),(0,s.jsx)(n.td,{children:"O(log n) add/remove"}),(0,s.jsx)(n.td,{children:"O(n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"PriorityQueue"})}),(0,s.jsx)(n.td,{children:"Task scheduling"}),(0,s.jsx)(n.td,{children:"O(log n) add/poll"}),(0,s.jsx)(n.td,{children:"O(n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"Trie"})}),(0,s.jsx)(n.td,{children:"Prefix search"}),(0,s.jsx)(n.td,{children:"O(m+k) search"}),(0,s.jsx)(n.td,{children:"O(26n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"Graph"})}),(0,s.jsx)(n.td,{children:"Networks, paths"}),(0,s.jsx)(n.td,{children:"Varies"}),(0,s.jsx)(n.td,{children:"O(V+E)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"SkipList"})}),(0,s.jsx)(n.td,{children:"Sorted KV (probabilistic)"}),(0,s.jsx)(n.td,{children:"O(log n) avg all ops"}),(0,s.jsx)(n.td,{children:"O(n log n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"SegmentTree"})}),(0,s.jsx)(n.td,{children:"Range queries (sum/min/max/custom)"}),(0,s.jsx)(n.td,{children:"O(log n) query/update"}),(0,s.jsx)(n.td,{children:"O(n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"BinaryIndexedTree"})}),(0,s.jsx)(n.td,{children:"Prefix sums, frequency counting"}),(0,s.jsx)(n.td,{children:"O(log n) query/update"}),(0,s.jsx)(n.td,{children:"O(n)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.strong,{children:"Matrix"})}),(0,s.jsx)(n.td,{children:"2D grid arithmetic"}),(0,s.jsx)(n.td,{children:"O(n\xb2) add, O(n\xb3) multiply"}),(0,s.jsx)(n.td,{children:"O(n\xb2)"})]})]})]}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"all-data-structures",children:"All Data Structures"}
1),"\n",(0,s.jsx)(n.h3,{id:"stack-structure",children:"Stack Structure"}),"\n",(0,s.jsx)(n.h4,{id:"stack",children:"Stack"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Stack } from 'data-structure-typed';\n\nconst stack = new Stack<number>([1, 2]);\nstack.push(3);                // add to top\nconst top = stack.pop();      // Remove from top - O(1)\nconst peek = stack.peek();    // View top\nstack.print();                // [1, 2]\n"})}),"\n",(0,s.jsx)(n.h3,{id:"linear-structures",children:"Linear Structures"}),"\n",(0,s.jsx)(n.h4,{id:"queue",children:"Queue"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Queue } from 'data-structure-typed';\n\nconst queue = new Queue<number>([1, 2]);\nqueue.push(3);                   // add to back\nconst first = queue.shift();     // Remove from front - O(1)\nconst length = queue.length;     // Current length\nqueue.print();                   // [2, 3]\n"})}),"\n",(0,s.jsx)(n.h4,{id:"deque",children:"Deque"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Deque } from 'data-structure-typed';\n\nconst deque = new Deque<number>([1, 2]);\ndeque.push(3);               // Add to back\ndeque.unshift(0);            // Add to front\ndeque.pop();                 // Remove from back - O(1)\ndeque.shift();               // Remove from front - O(1)\ndeque.print();               // [1, 2]\n"})}),"\n",(0,s.jsx)(n.h4,{id:"linked-lists",children:"Linked Lists"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { SinglyLinkedList, DoublyLinkedList } from 'data-structure-typed';\n\nconst singly = new SinglyLinkedList<number>([1, 2]);\nconst doubly = new DoublyLinkedList<number>([1, 2]);\n\nsingly.push(3);              // Add to end\nsingly.addAt(1, 99);         // Insert at index - O(n)\nsingly.deleteAt(2);          // Delete at index - O(n)\nsingly.print();              // [1, 99, 3]\n\ndoubly.push(3);              // Add to end\ndoubly.addAt(1, 99);         // Insert at index - O(n)\ndoubly.deleteAt(2);          // Delete at index - O(n)\ndoubly.print();              // [1, 99, 3]\n"})}),"\n",(0,s.jsx)(n.h3,{id:"tree-structures",children:"Tree Structures"}),"\n",(0,s.jsx)(n.h4,{id:"binary-search-tree-bst",children:"Binary Search Tree (BST)"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { BST } from 'data-structure-typed';\n\nconst bst = new BST<number>([1, 3, 5, 8, 6, 2, 4, 7]);\nbst.add(9);                   // Add elements\nbst.has(5);                  // Check existence - O(log n) avg\nbst.delete(1);               // Remove - O(log n) avg\nbst.print();                 // Visual representation\n//      ___4___\n//     /       \\\n//    2_       _6_\n//      \\     /   \\\n//       3    5    7_\n//                   \\\n//                    8_\n//                      \\ \n//                      9 \n"})}),"\n",(0,s.jsx)(n.h4,{id:"red-black-tree",children:"Red-Black Tree"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { RedBlackTree } from 'data-structure-typed';\n\nconst rbTree = new RedBlackTree<number, string>([[1, 'Alice'], [2, 'Bob'], [3, 'Chris']]);\nrbTree.set(4, 'Dan');               // Add key-value\nrbTree.get(1);                      // 'Alice'\nrbTree.delete(2);                   // Remove - O(log n) guaranteed\nconsole.log([...rbTree.values()]);  // ['Alice', 'Chris', 'Dan'] Automatically sorted\nrbTree.print()\n//   _3_\n//  /   \\\n//  1    4\n\n"})}),"\n",(0,s.jsx)(n.h4,{id:"avl-tree",children:"AVL Tree"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import {AVLTree} from 'data-structure-typed';\n\nconst avl = new AVLTree<number>([5, 4, 3, 8, 1]);\navl.add(9);\navl.isAVLBalanced();         // Check balance\navl.delete(3);               // Auto-rebalances\navl.print()\n//    ___5_    \n//   /     \\   \n//   1_     8_  \n//     \\      \\ \n//      4      9 \n"})}),"\n",(0,s.jsx)(n.h4,{id:"treemap-ordered-map",children:"TreeMap (Ordered Map)"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { TreeMap } from 'data-structure-typed';\n\nconst tm = new TreeMap<number, string>([[3, 'c'], [1, 'a'], [2, 'b']]);\ntm.set(4, 'd');                    // Set key-value - O(log n)\ntm.get(2);                         // 'b' - O(log n)\ntm.has(3);                         // true\ntm.delete(1);                      // Remove - O(log n)\n\n// Navigation \u2014 Java NavigableMap-style\ntm.first();                        // [2, 'b'] \u2014 smallest entry\ntm.last();                         // [4, 'd'] \u2014 largest entry\ntm.ceiling(3);                     // [3, 'c'] \u2014 smallest >= 3\ntm.floor(2);                       // [2, 'b'] \u2014 largest <= 2\ntm.higher(2);                      // [3, 'c'] \u2014 strictly > 2\ntm.lower(3);                       // [2, 'b'] \u2014 strictly < 3\n\n// Iteration (sorted order)\nconsole.log([...tm.keys()]);       // [2, 3, 4]\nconsole.log([...tm.values()]);     // ['b', 'c', 'd']\n\n// Bulk operations\ntm.setMany([[5, 'e'], [6, 'f']]);  // Set multiple at once\n\n// Functional\nconst filtered = tm.filter((v, k) => k > 2);\nconst mapped = tm.map((v, k) => [k * 10, v!.toUpperCase()] as [number, string]);\n"})}),"\n",(0,s.jsx)(n.h4,{id:"treeset-ordered-set",children:"TreeSet (Ordered Set)"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { TreeSet } from 'data-structure-typed';\n\nconst ts = new TreeSet<number>([5, 3, 8, 1]);\nts.add(4);                         // Add - O(log n)\nts.has(3);                         // true\nts.delete(5);                      // Remove - O(log n)\n\n// Navigation\nts.first();
1                        // 1\nts.last();                         // 8\nts.ceiling(4);                     // 4 \u2014 smallest >= 4\nts.floor(6);                       // 4 \u2014 largest <= 6\nts.higher(3);                      // 4 \u2014 strictly > 3\nts.lower(4);                       // 3 \u2014 strictly < 4\n\n// Iteration (sorted order)\nconsole.log([...ts.keys()]);       // [1, 3, 4, 8]\n\n// Bulk operations\nts.addMany([10, 20, 30]);          // Add multiple at once\n"})}),"\n",(0,s.jsx)(n.h4,{id:"order-statistic-tree-rank-queries",children:"Order-Statistic Tree (Rank Queries)"}),"\n",(0,s.jsxs)(n.p,{children:["Enable ",(0,s.jsx)(n.code,{children:"enableOrderStatistic: true"})," on any tree-based structure to get O(log n) rank operations:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { RedBlackTree, TreeMap, TreeSet } from 'data-structure-typed';\n\n// Works with RedBlackTree, TreeMap, TreeSet, TreeMultiMap, TreeMultiSet\nconst tree = new RedBlackTree<number, string>(\n  [[100, 'Alice'], [85, 'Bob'], [92, 'Charlie'], [78, 'Diana']],\n  { comparator: (a, b) => b - a, enableOrderStatistic: true }\n);\n\n// getByRank(k) \u2014 element at position k in tree order, O(log n)\ntree.getByRank(0);                 // 100 (1st in tree order)\ntree.getByRank(2);                 // 92  (3rd in tree order)\n\n// getRank(key) \u2014 count of elements before key in tree order, O(log n)\ntree.getRank(92);                  // 2\n\n// rangeByRank(start, end) \u2014 elements between positions, O(log n + k)\ntree.rangeByRank(0, 2);           // [100, 92, 85] \u2014 positions 0..2\n\n// Also works with wrapper classes\nconst tm = new TreeMap<number, string>([], { enableOrderStatistic: true });\ntm.set(10, 'a'); tm.set(20, 'b'); tm.set(30, 'c');\ntm.getByRank(1);                   // [20, 'b']\ntm.getRank(20);                    // 1\n\nconst ts = new TreeSet<number>([], { enableOrderStatistic: true });\nts.addMany([10, 20, 30]);\nts.getByRank(0);                   // 10\nts.getRank(30);                    // 2\n"})}),"\n",(0,s.jsx)(n.h3,{id:"heap--priority-queue",children:"Heap & Priority Queue"}),"\n",(0,s.jsx)(n.h4,{id:"heap",children:"Heap"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { MinHeap, MaxHeap } from 'data-structure-typed';\n\nconst minHeap = new MinHeap<number>([5, 3, 8]);\nminHeap.add(1);               // Add element - O(log n)\nconst min = minHeap.poll();   // Get minimum - O(log n)\nconst peek = minHeap.peek();  // View minimum - O(1)\n"})}),"\n",(0,s.jsx)(n.h4,{id:"priority-queue",children:"Priority Queue"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { MaxPriorityQueue } from 'data-structure-typed';\n\nconst pq = new MaxPriorityQueue<Task>([], {\n  comparator: (a, b) => b.priority - a.priority\n});\npq.add({ id: 1, priority: 5 });  // Add - O(log n)\nconst task = pq.poll();          // Remove highest - O(log n)\nconst size = pq.size;            // Current size\n"})}),"\n",(0,s.jsx)(n.h3,{id:"special-structures",children:"Special Structures"}),"\n",(0,s.jsx)(n.h4,{id:"trie-prefix-tree",children:"Trie (Prefix Tree)"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Trie } from 'data-structure-typed';\n\nconst trie = new Trie(['apple', 'app', 'banana']);\ntrie.add('apply');\ntrie.getWords('app');        // ['apple', 'apply', 'app'] - O(m+k)\ntrie.has('apple');           // true\ntrie.hasPrefix('ap');        // true\n"})}),"\n",(0,s.jsx)(n.h4,{id:"graph",children:"Graph"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { DirectedGraph, UndirectedGraph } from 'data-structure-typed';\n\nconst graph = new DirectedGraph<string>();\ngraph.addVertex('A');\ngraph.addVertex('B');\ngraph.addEdge('A', 'B', 1);  // Add edge with weight\ngraph.hasEdge('A', 'B');     // true\nconst {\n  distMap, distPaths, preMap, seen, paths, minDist, minPath\n} = graph.dijkstra('A', 'B', true, true)!; \nconst order = graph.topologicalSort();\nconsole.log(distMap)\nconsole.log(distPaths)\nconsole.log(preMap)\nconsole.log(seen)\nconsole.log(paths)\nconsole.log(minDist)\nconsole.log(minPath)  // Shortest path\nconsole.log(order)    // DAG order\n"})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"crud-operations",children:"CRUD Operations"}),"\n",(0,s.jsx)(n.h3,{id:"create-add",children:"Create (Add)"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"const tree = new RedBlackTree<number, string>();\ntree.set(1, 'Alice');\ntree.setMany([[2, 'Bob'], [3, 'Charlie']]);\n\n// Heap\nconst heap = new MaxHeap<number>([10, 20]);\nheap.add(15);\n\n// Trie\nconst trie = new Trie(['hello']);\ntrie.add('world');\n\n// Graph\nconst graph = new DirectedGraph<string>();\ngraph.addVertex('A');\ngraph.addEdge('A', 'B', 1);\n"})}),"\n",(0,s.jsx)(n.h3,{id:"read-query",children:"Read (Query)"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"// Tree\ntree.get(1);               // 'Alice'\ntree.has(1);               // true\ntree.size;                 // Number of elements\n\n// Heap\nheap.peek();               // Highest priority element\nheap.size;                 // Current size\n\n// Trie\ntrie.has('hello');            // true\ntrie.hasPrefix('hel');    // true\n\n// Graph\ngraph.hasVertex('A');      // true\ngraph.hasEdge('A', 'B');   // true\ngraph.getNeighbors('A');   // Connected vertices\n"})}),"\n",(0,s.jsx)(n.h3,{id:"update-modify",children:"Update (Modify)"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"// Tree\ntree.set(1, 'Alice Updated'); // Update value\ntree.delete(1);               // Remove\n\n// Heap\nheap.pop();                    // Remove highest\n\n// Graph\ngraph.deleteEdge('A', 'B');   // Remove edge\ngraph.deleteVertex('A');      // Remove vertex\n"})}),"\n",(0,s.jsx)(n.h3,{id:"delete",children:"Delete"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"// All structures support:\nstructure.clear();             // Remove all elements\nstructure.delete(key);         // Remove specific\n\n// Conditional delete (BST-family and Deque)\ntree.deleteWhere(node =>
1 node.key < 10);           // Delete all matching\ntree.deleteWhere(node => node.key < 10, true);     // Delete first match only\ntree.deleteWhere(new Range(5, 15));                 // Delete by range\ndeque.deleteWhere((val, idx) => val > 100);        // Deque predicate delete\n"})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"common-methods",children:"Common Methods"}),"\n",(0,s.jsx)(n.h3,{id:"available-on-all-structures",children:"Available on All Structures"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"// Iteration\nstructure.forEach((value, key) => {\n});\nfor (const item of structure) {\n}\n\n// Conversion\n[...structure];                // Spread\nArray.from(structure);         // Array conversion\n\n// Array methods\nstructure.map((v, k) => v * 2);\nstructure.filter((v, k) => v > 5);\nstructure.reduce((acc, v) => acc + v, 0);\nstructure.find((v, k) => v === 5);\nstructure.some((v, k) => v > 10);\nstructure.every((v, k) => v > 0);\n\n// Properties\nstructure.size;                // Element count\nstructure.isEmpty();           // Check empty\n"})}),"\n",(0,s.jsx)(n.h3,{id:"raw-data-mapping",children:"Raw Data Mapping"}),"\n",(0,s.jsxs)(n.p,{children:["Pass raw objects directly \u2014 no ",(0,s.jsx)(n.code,{children:".map()"})," pre-processing needed:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"// toElementFn \u2014 extract a field, store only that (Heap, Queue, Stack, LinkedList, Trie)\nconst heap = new MinHeap<number, User>(users, {\n  toElementFn: u => u.age\n});\n\n// toEntryFn \u2014 split into key-value pairs (TreeMap, HashMap, SkipList)\nconst map = new TreeMap<number, User, User>(users, {\n  toEntryFn: u => [u.id, u]\n});\n\n// comparator \u2014 store full objects, sort by a field (all sorted structures)\nconst set = new TreeSet<User>(users, {\n  comparator: (a, b) => a.id - b.id\n});\n"})}),"\n",(0,s.jsx)(n.h3,{id:"structure-specific-methods",children:"Structure-Specific Methods"}),"\n",(0,s.jsx)(n.h4,{id:"trees",children:"Trees"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"tree.height;                   // Tree height (getter)\ntree.isAVLBalanced();         // Balance check\ntree.getNode(key);            // Get node object\ntree.getHeight(key);          // Node height\ntree.getLeftMost();           // Leftmost node\ntree.getRightMost();          // Rightmost node\n"})}),"\n",(0,s.jsx)(n.h4,{id:"deque-1",children:"Deque"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"deque.first;                  // View front (getter)\ndeque.last;                   // View back (getter)\ndeque.shift();                // Remove front - O(1)\ndeque.pop();                  // Remove back - O(1)\n"})}),"\n",(0,s.jsx)(n.h4,{id:"graph-1",children:"Graph"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"graph.topologicalSort();      // DAG order\ngraph.dijkstra(start, end);   // Shortest path\ngraph.dfs(vertex);            // Depth-first traversal\ngraph.bfs(vertex);            // Breadth-first traversal\n"})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"typescript-support",children:"TypeScript Support"}),"\n",(0,s.jsx)(n.h3,{id:"full-generic-support",children:"Full Generic Support"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"// Custom type safety\nconst tree = new RedBlackTree<number, User>();\ntree.set(1, { name: 'Alice', age: 30 });\n\nconst value = tree.get(1);  // Type: User | undefined\n\n// Automatic inference\nconst numbers = new Deque<number>([1, 2]);\nnumbers.push(3);\n\n// Custom comparators\nconst descending = new RedBlackTree<number, string>([], {\n    comparator: (a, b) => b - a  // Sort descending\n  });\n"})}),"\n",(0,s.jsx)(n.h3,{id:"type-safety-examples",children:"Type Safety Examples"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"interface Task {\n  id: string;\n  priority: number;\n  action: Promise<void>;\n}\n\nconst pq = new MaxPriorityQueue<Task>(\n  {\n    comparator: (a, b) => a.priority - b.priority\n  }\n);\n\npq.add({\n  id: '1', priority: 5, action: async () => {\n  }\n});\n\n// Type checking catches errors\nconst task = pq.poll();\nif (task) {\n  // task is guaranteed to be Task\n  await task.action;\n}\n"})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"complexity-chart",children:"Complexity Chart"}),"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Operation"}),(0,s.jsx)(n.th,{children:"Array"}),(0,s.jsx)(n.th,{children:"LinkedList"}),(0,s.jsx)(n.th,{children:"BST"}),(0,s.jsx)(n.th,{children:"RBTree"}),(0,s.jsx)(n.th,{children:"Heap"}),(0,s.jsx)(n.th,{children:"Trie"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"Access"}),(0,s.jsx)(n.td,{children:"O(1)"}),(0,s.jsx)(n.td,{children:"O(n)"}),(0,s.jsx)(n.td,{children:"O(log n)"}),(0,s.jsx)(n.td,{children:"O(log n)"}),(0,s.jsx)(n.td,{children:"O(n)"}),(0,s.jsx)(n.td,{children:"N/A"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"Search"}),(0,s.jsx)(n.td,{children:"O(n)"}),(0,s.jsx)(n.td,{children:"O(n)"}),(0,s.jsx)(n.td,{children:"O(log n)"}),(0,s.jsx)(n.td,{children:"O(log n)"}),(0,s.jsx)(n.td,{children:"O(n)"}),(0,s.jsx)(n.td,{children:"O(m)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"Insert"}),(0,s.jsx)(n.td,{children:"O(n)"}),(0,s.jsx)(n.td,{children:"O(1)"}),(0,s.jsx)(n.td,{children:"O(log n)"}),(0,s.jsx)(n.td,{children:"O(log n)"}),(0,s.jsx)(n.td,{children:"O(log n)"}),(0,s.jsx)(n.td,{children:"O(m)"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"Delete"}),(0,s.jsx)(n.td,{children:"O(n)"}),(0,s.jsx)(n.td,{children:"O(1)"}),(0,s.jsx)(n.td,{children:"O(log n)"}),(0,s.jsx)(n.td,{children:"O(log n)"}),(0,s.jsx)(n.td,{children:"O(log n)"}),(0,s.jsx)(n.td,{children:"O(m)"})]})]})]}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"common-patterns",children:"Common Patterns"}),"\n",(0,s.jsx)(n.h3,{id:"iterator-pattern",children:"Iterator Pattern"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"const tree = new RedBlackTree([5, 2, 8]);\n\n// Works everywhere\nconst arr = [...tree.keys()];           // Spread\nconst set = new Set(tree.keys());       // Set constructor\nfor (const val of tree.values()) {\n}      // for...of\nconst [first, ...rest] = tree.keys();   // Destructuring\n"})}),"\n",(0,s.jsx)(n.h3,{id:"filtering-pattern",children:"Filtering Pattern"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"const tree = new RedBlackTree([\n  [1, { active: true }],\n  [2, { active: false }],\n  [3, { active: true }]\n]);\n\nconst inactive = tree\n  .filter((val) => val?.active ?? false)\n  .map((val, key) => [key, !val]);\n\nconsole.log(...inactive);\n"})}),"\n",(0,s.jsx)(n.h3,{id:"sorting-pattern",children:"Sorting Pattern"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"const data = [64, 34, 25, 12, 22, 11, 90];\nconst sorted = [...new RedBlackTree(data).keys()]; // Instant sort!\n"})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"skiplist",children:"SkipList"}),"\n",(0,s.jsxs)(n.p,{children:["Probabilistic sorted containers. Interchangeable with ",(0,s.jsx)(n.code,{children:"TreeMap"}),"/",(0,s.jsx)(n.code,{children:"TreeSet"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { SkipList } from 'data-structure-typed';\n\n// Same API as TreeMap \u2014 drop-in replacement\nconst sl = new SkipList<number, string>([[3, 'c'], [1, 'a'], [2, 'b']]);\nsl.set(4, 'd');                    // upsert \u2014 returns this (chainable)\nsl.get(2);                         // 'b'\nsl.has(5);                         // false\nsl.delete(1);                      // true\n\n// Navigation\nsl.first();                        // [2, 'b']\nsl.last();                         // [4, 'd']\nsl.ceiling(2);                     // [2, 'b'] \u2014 smallest >= 2\nsl.floor(3);                       // [3, 'c'] \u2014 largest <= 3\nsl.higher(2);                      // [3, 'c'] \u2014 strictly > 2\nsl.lower(3);                       // [2, 'b'] \u2014 strictly < 3\nsl.rangeSearch([2, 4]);            // [[2,'b'],[3,'c'],[4,'d']]\nsl.pollFirst();                    // [2, 'b'] \u2014 remove+return first\n\n// Iteration (sorted order)\nfor (const [k, v] of sl) console.log(k, v);\n[...sl.keys()];   // [3, 4]\n[...sl.values()]; // ['c', 'd']\n\n// Functional\nsl.filter((v, k) => k > 2).toArray();   // [[3,'c'],[4,'d']]\nsl.map((v, k) => [k * 10, v]);          // new SkipList\nsl.reduce((acc, v) => acc + v!, '');    // 'cd'\n\n// Custom comparator\nconst reversed = new SkipList<number, string>([], {\n  comparator: (a, b) => b - a\n});\n\n// From objects via toEntryFn\ntype User = { id: number; name: string };\nconst users = new SkipList<number, User, User>(data, {\n  toEntryFn: u => [u.id, u]\n});\n"})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"segmenttree",children:"SegmentTree"}),"\n",(0,s.jsx)(n.p,{children:"Range queries with any associative merge operation."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { SegmentTree } from 'data-structure-typed';\n\n// Convenience factories (covers 90% of use cases)\nconst sumTree = SegmentTree.sum([1, 3, 5, 7, 9]);\nconst minTree = SegmentTree.min([5, 2, 8, 1, 9]);
1\nconst maxTree = SegmentTree.max([5, 2, 8, 1, 9]);\n\n// Range query O(log n)\nsumTree.query(1, 3);   // 15 (3+5+7)\nminTree.query(0, 4);   // 1\nmaxTree.query(0, 2);   // 8\n\n// Point update O(log n)\nsumTree.update(2, 10); // replaces 5 with 10\nsumTree.query(1, 3);   // 20 (3+10+7)\n\n// Single element access O(1)\nsumTree.get(2);        // 10\n\n// Custom merge (gcd, product, etc.)\nconst gcd = (a: number, b: number): number => b === 0 ? a : gcd(b, a % b);\nconst gcdTree = new SegmentTree([12, 8, 6, 18], { merger: gcd, identity: 0 });\ngcdTree.query(0, 3);   // 2\n\n// Binary search on tree (ACL-style)\n// maxRight(l, pred): find max r where pred(query(l, r)) is true\nsumTree.maxRight(0, s => s <= 10);  // rightmost index where prefix \u2264 10\n\n// Standard interface\n[...sumTree];          // leaf values as array\nsumTree.toArray();     // same\nsumTree.size;          // 5\nsumTree.clone();       // independent copy\n"})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"binaryindexedtree-fenwick-tree",children:"BinaryIndexedTree (Fenwick Tree)"}),"\n",(0,s.jsx)(n.p,{children:"Prefix sums and point updates in O(log n). Lighter than SegmentTree; use when you only need sums."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { BinaryIndexedTree } from 'data-structure-typed';\n\n// Construct from size or array\nconst bit = new BinaryIndexedTree(6);\nconst bit2 = new BinaryIndexedTree([1, 3, 5, 7, 9, 11]);\n\n// Point update: add delta\nbit2.update(2, 4);    // index 2 += 4 \u2192 value becomes 9\n\n// Point set: absolute value\nbit2.set(0, 100);     // index 0 = 100\n\n// Point query\nbit2.get(2);          // 9\n\n// Prefix sum [0..i]\nbit2.query(3);        // sum of [0..3]\n\n// Range sum [start..end]\nbit2.queryRange(1, 3); // sum of [1..3]\n\n// Binary search \u2014 requires non-negative values\nbit2.lowerBound(10);  // smallest i where prefix sum [0..i] >= 10\nbit2.upperBound(10);  // smallest i where prefix sum [0..i] > 10\n\n// Standard interface\n[...bit2];            // point values as array\nbit2.toArray();       // same\nbit2.size;            // 6\nbit2.clone();\nbit2.clear();\n"})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"matrix",children:"Matrix"}),"\n",(0,s.jsx)(n.p,{children:"2D grid arithmetic. Correct, minimal \u2014 not competing with NumPy."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-typescript",children:"import { Matrix } from 'data-structure-typed';\n\n// Construction\nconst m = new Matrix([[1, 2, 3], [4, 5, 6]]);\nMatrix.zeros(3, 4);       // 3\xd74 zero matrix\nMatrix.identity(3);       // 3\xd73 identity matrix\nMatrix.from([[1, 2], [3, 4]]); // from plain array\n\n// Element access\nm.get(0, 1);              // 2\nm.set(0, 1, 99);          // returns boolean\nm.size;                   // [2, 3]\nm.rows;                   // 2\nm.cols;                   // 3\n\n// Arithmetic (returns new Matrix)\na.add(b);\na.subtract(b);\na.multiply(b);            // matrix multiplication\na.dot(b);                 // dot product\na.transpose();            // supports rectangular matrices\na.inverse();              // square matrices only\n\n// Standard interface\n[...m];                   // array of rows (copies)\nm.toArray();              // deep copy as number[][]\nm.flatten();              // [1,2,3,4,5,6] row-major\nm.forEach((v, r, c) => ...);\nm.map(v => v * 2);        // new Matrix\nm.clone();                // independent copy\nm.isEmpty();              // true if 0 rows or 0 cols\n"})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.strong,{children:"Need details?"})," Check ",(0,s.jsx)(n.a,{href:"/docs/guide/guides",children:"GUIDES.md"})," for real-world examples."]}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.strong,{children:"Performance curious?"})," See ",(0,s.jsx)(n.a,{href:"/docs/guide/performance",children:"PERFORMANCE.md"})," for benchmarks."]})]})}function u(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(o,{...e})}):o(e)}},8453(e,n,r){r.d(n,{R:()=>a,x:()=>d});var t=r(6540);const s={},i=t.createContext(s);function a(e){const n=t.useContext(i);return t.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:a(e.components),t.createElement(i.Provider,{value:n},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.