data-structure-typed 1.18.0 → 1.18.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/README.md +193 -66
  2. package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
  3. package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
  4. package/backup/recursive-type/src/assets/logo.png +0 -0
  5. package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
  6. package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +3 -0
  7. package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +288 -0
  8. package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +3 -0
  9. package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +78 -0
  10. package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +1502 -0
  11. package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +503 -0
  12. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  13. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  14. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  15. package/backup/recursive-type/src/data-structures/binary-tree/index.ts +11 -0
  16. package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +110 -0
  17. package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +243 -0
  18. package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +3 -0
  19. package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +55 -0
  20. package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +3 -0
  21. package/backup/recursive-type/src/data-structures/diagrams/README.md +5 -0
  22. package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +985 -0
  23. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  24. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  25. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  26. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  27. package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  28. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  29. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  30. package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  31. package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
  32. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  33. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  34. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  35. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  36. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  37. package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +478 -0
  38. package/backup/recursive-type/src/data-structures/graph/index.ts +3 -0
  39. package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +293 -0
  40. package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +67 -0
  41. package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +56 -0
  42. package/backup/recursive-type/src/data-structures/hash/hash-table.ts +3 -0
  43. package/backup/recursive-type/src/data-structures/hash/index.ts +6 -0
  44. package/backup/recursive-type/src/data-structures/hash/pair.ts +3 -0
  45. package/backup/recursive-type/src/data-structures/hash/tree-map.ts +3 -0
  46. package/backup/recursive-type/src/data-structures/hash/tree-set.ts +3 -0
  47. package/backup/recursive-type/src/data-structures/heap/heap.ts +176 -0
  48. package/backup/recursive-type/src/data-structures/heap/index.ts +3 -0
  49. package/backup/recursive-type/src/data-structures/heap/max-heap.ts +31 -0
  50. package/backup/recursive-type/src/data-structures/heap/min-heap.ts +34 -0
  51. package/backup/recursive-type/src/data-structures/index.ts +15 -0
  52. package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +42 -0
  53. package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +1 -0
  54. package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +56 -0
  55. package/backup/recursive-type/src/data-structures/interfaces/bst.ts +1 -0
  56. package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +15 -0
  57. package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +1 -0
  58. package/backup/recursive-type/src/data-structures/interfaces/heap.ts +1 -0
  59. package/backup/recursive-type/src/data-structures/interfaces/index.ts +13 -0
  60. package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +1 -0
  61. package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +1 -0
  62. package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +1 -0
  63. package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +1 -0
  64. package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +1 -0
  65. package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +3 -0
  66. package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +573 -0
  67. package/backup/recursive-type/src/data-structures/linked-list/index.ts +3 -0
  68. package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +490 -0
  69. package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +3 -0
  70. package/backup/recursive-type/src/data-structures/matrix/index.ts +4 -0
  71. package/backup/recursive-type/src/data-structures/matrix/matrix.ts +27 -0
  72. package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +208 -0
  73. package/backup/recursive-type/src/data-structures/matrix/navigator.ts +122 -0
  74. package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +316 -0
  75. package/backup/recursive-type/src/data-structures/priority-queue/index.ts +3 -0
  76. package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +49 -0
  77. package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +50 -0
  78. package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +354 -0
  79. package/backup/recursive-type/src/data-structures/queue/deque.ts +251 -0
  80. package/backup/recursive-type/src/data-structures/queue/index.ts +2 -0
  81. package/backup/recursive-type/src/data-structures/queue/queue.ts +120 -0
  82. package/backup/recursive-type/src/data-structures/stack/index.ts +1 -0
  83. package/backup/recursive-type/src/data-structures/stack/stack.ts +98 -0
  84. package/backup/recursive-type/src/data-structures/tree/index.ts +1 -0
  85. package/backup/recursive-type/src/data-structures/tree/tree.ts +80 -0
  86. package/backup/recursive-type/src/data-structures/trie/index.ts +1 -0
  87. package/backup/recursive-type/src/data-structures/trie/trie.ts +227 -0
  88. package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +5 -0
  89. package/backup/recursive-type/src/data-structures/types/avl-tree.ts +8 -0
  90. package/backup/recursive-type/src/data-structures/types/binary-tree.ts +10 -0
  91. package/backup/recursive-type/src/data-structures/types/bst.ts +6 -0
  92. package/backup/recursive-type/src/data-structures/types/directed-graph.ts +8 -0
  93. package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +1 -0
  94. package/backup/recursive-type/src/data-structures/types/heap.ts +5 -0
  95. package/backup/recursive-type/src/data-structures/types/index.ts +12 -0
  96. package/backup/recursive-type/src/data-structures/types/navigator.ts +13 -0
  97. package/backup/recursive-type/src/data-structures/types/priority-queue.ts +9 -0
  98. package/backup/recursive-type/src/data-structures/types/segment-tree.ts +1 -0
  99. package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +1 -0
  100. package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +1 -0
  101. package/backup/recursive-type/src/index.ts +1 -0
  102. package/backup/recursive-type/src/utils/index.ts +2 -0
  103. package/backup/recursive-type/src/utils/types/index.ts +1 -0
  104. package/backup/recursive-type/src/utils/types/utils.ts +6 -0
  105. package/backup/recursive-type/src/utils/utils.ts +78 -0
  106. package/dist/data-structures/binary-tree/avl-tree.d.ts +19 -25
  107. package/dist/data-structures/binary-tree/avl-tree.js +8 -16
  108. package/dist/data-structures/binary-tree/binary-tree.d.ts +99 -98
  109. package/dist/data-structures/binary-tree/binary-tree.js +70 -65
  110. package/dist/data-structures/binary-tree/bst.d.ts +21 -21
  111. package/dist/data-structures/binary-tree/bst.js +15 -17
  112. package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -2
  113. package/dist/data-structures/binary-tree/rb-tree.js +68 -5
  114. package/dist/data-structures/binary-tree/tree-multiset.d.ts +9 -8
  115. package/dist/data-structures/binary-tree/tree-multiset.js +7 -6
  116. package/dist/data-structures/graph/abstract-graph.d.ts +56 -58
  117. package/dist/data-structures/graph/abstract-graph.js +84 -68
  118. package/dist/data-structures/graph/directed-graph.d.ts +127 -96
  119. package/dist/data-structures/graph/directed-graph.js +161 -109
  120. package/dist/data-structures/graph/undirected-graph.d.ts +82 -59
  121. package/dist/data-structures/graph/undirected-graph.js +99 -72
  122. package/dist/data-structures/hash/coordinate-set.d.ts +1 -1
  123. package/dist/data-structures/index.d.ts +1 -0
  124. package/dist/data-structures/index.js +1 -0
  125. package/dist/data-structures/interfaces/abstract-graph.d.ts +22 -0
  126. package/dist/data-structures/interfaces/abstract-graph.js +2 -0
  127. package/dist/data-structures/interfaces/avl-tree.d.ts +1 -0
  128. package/dist/data-structures/interfaces/avl-tree.js +2 -0
  129. package/dist/data-structures/interfaces/binary-tree.d.ts +27 -0
  130. package/dist/data-structures/interfaces/binary-tree.js +2 -0
  131. package/dist/data-structures/interfaces/bst.d.ts +1 -0
  132. package/dist/data-structures/interfaces/bst.js +2 -0
  133. package/dist/data-structures/interfaces/directed-graph.d.ts +9 -0
  134. package/dist/data-structures/interfaces/directed-graph.js +2 -0
  135. package/dist/data-structures/interfaces/doubly-linked-list.d.ts +1 -0
  136. package/dist/data-structures/interfaces/doubly-linked-list.js +2 -0
  137. package/dist/data-structures/interfaces/heap.d.ts +1 -0
  138. package/dist/data-structures/interfaces/heap.js +2 -0
  139. package/dist/data-structures/interfaces/index.d.ts +13 -0
  140. package/dist/data-structures/interfaces/index.js +29 -0
  141. package/dist/data-structures/interfaces/navigator.d.ts +1 -0
  142. package/dist/data-structures/interfaces/navigator.js +2 -0
  143. package/dist/data-structures/interfaces/priority-queue.d.ts +1 -0
  144. package/dist/data-structures/interfaces/priority-queue.js +2 -0
  145. package/dist/data-structures/interfaces/segment-tree.d.ts +1 -0
  146. package/dist/data-structures/interfaces/segment-tree.js +2 -0
  147. package/dist/data-structures/interfaces/singly-linked-list.d.ts +1 -0
  148. package/dist/data-structures/interfaces/singly-linked-list.js +2 -0
  149. package/dist/data-structures/interfaces/tree-multiset.d.ts +1 -0
  150. package/dist/data-structures/interfaces/tree-multiset.js +2 -0
  151. package/dist/data-structures/interfaces/undirected-graph.d.ts +2 -0
  152. package/dist/data-structures/interfaces/undirected-graph.js +2 -0
  153. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
  154. package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -1
  155. package/dist/data-structures/priority-queue/priority-queue.d.ts +1 -1
  156. package/dist/data-structures/priority-queue/priority-queue.js +4 -4
  157. package/dist/data-structures/queue/deque.d.ts +5 -5
  158. package/dist/data-structures/queue/deque.js +6 -6
  159. package/dist/data-structures/queue/queue.d.ts +1 -1
  160. package/dist/data-structures/stack/stack.d.ts +1 -1
  161. package/dist/data-structures/types/abstract-graph.d.ts +1 -20
  162. package/dist/data-structures/types/avl-tree.d.ts +5 -4
  163. package/dist/data-structures/types/binary-tree.d.ts +6 -5
  164. package/dist/data-structures/types/bst.d.ts +4 -3
  165. package/dist/data-structures/types/directed-graph.d.ts +5 -9
  166. package/dist/data-structures/types/directed-graph.js +7 -0
  167. package/dist/data-structures/types/heap.d.ts +2 -2
  168. package/dist/data-structures/types/index.d.ts +0 -1
  169. package/dist/data-structures/types/index.js +0 -1
  170. package/dist/data-structures/types/navigator.d.ts +2 -2
  171. package/dist/data-structures/types/priority-queue.d.ts +2 -2
  172. package/dist/data-structures/types/tree-multiset.d.ts +3 -4
  173. package/docs/assets/search.js +1 -1
  174. package/docs/classes/AVLTree.html +288 -287
  175. package/docs/classes/AVLTreeNode.html +106 -63
  176. package/docs/classes/AaTree.html +14 -12
  177. package/docs/classes/AbstractEdge.html +68 -34
  178. package/docs/classes/AbstractGraph.html +219 -114
  179. package/docs/classes/AbstractVertex.html +71 -30
  180. package/docs/classes/ArrayDeque.html +27 -25
  181. package/docs/classes/BST.html +279 -273
  182. package/docs/classes/BSTNode.html +106 -57
  183. package/docs/classes/BTree.html +14 -12
  184. package/docs/classes/BinaryIndexedTree.html +22 -20
  185. package/docs/classes/BinaryTree.html +283 -277
  186. package/docs/classes/BinaryTreeNode.html +111 -63
  187. package/docs/classes/Character.html +17 -15
  188. package/docs/classes/CoordinateMap.html +22 -20
  189. package/docs/classes/CoordinateSet.html +23 -21
  190. package/docs/classes/Deque.html +47 -45
  191. package/docs/classes/DirectedEdge.html +74 -41
  192. package/docs/classes/DirectedGraph.html +444 -208
  193. package/docs/classes/DirectedVertex.html +63 -36
  194. package/docs/classes/DoublyLinkedList.html +52 -50
  195. package/docs/classes/DoublyLinkedListNode.html +24 -22
  196. package/docs/classes/HashTable.html +14 -12
  197. package/docs/classes/Heap.html +29 -27
  198. package/docs/classes/HeapItem.html +21 -19
  199. package/docs/classes/Matrix2D.html +29 -27
  200. package/docs/classes/MatrixNTI2D.html +17 -15
  201. package/docs/classes/MaxHeap.html +29 -27
  202. package/docs/classes/MaxPriorityQueue.html +67 -60
  203. package/docs/classes/MinHeap.html +29 -27
  204. package/docs/classes/MinPriorityQueue.html +67 -60
  205. package/docs/classes/Navigator.html +24 -22
  206. package/docs/classes/ObjectDeque.html +62 -50
  207. package/docs/classes/Pair.html +14 -12
  208. package/docs/classes/PriorityQueue.html +62 -55
  209. package/docs/classes/Queue.html +29 -27
  210. package/docs/classes/SegmentTree.html +30 -28
  211. package/docs/classes/SegmentTreeNode.html +33 -31
  212. package/docs/classes/SinglyLinkedList.html +49 -47
  213. package/docs/classes/SinglyLinkedListNode.html +21 -19
  214. package/docs/classes/SkipLinkedList.html +14 -12
  215. package/docs/classes/SplayTree.html +14 -12
  216. package/docs/classes/Stack.html +27 -25
  217. package/docs/classes/TreeMap.html +14 -12
  218. package/docs/classes/TreeMultiSet.html +277 -270
  219. package/docs/classes/TreeNode.html +29 -27
  220. package/docs/classes/TreeSet.html +14 -12
  221. package/docs/classes/Trie.html +26 -24
  222. package/docs/classes/TrieNode.html +24 -22
  223. package/docs/classes/TwoThreeTree.html +14 -12
  224. package/docs/classes/UndirectedEdge.html +70 -51
  225. package/docs/classes/UndirectedGraph.html +344 -161
  226. package/docs/classes/UndirectedVertex.html +63 -36
  227. package/docs/classes/Vector2D.html +41 -39
  228. package/docs/enums/CP.html +17 -15
  229. package/docs/enums/FamilyPosition.html +17 -15
  230. package/docs/enums/LoopType.html +16 -14
  231. package/docs/{interfaces/AVLTreeDeleted.html → enums/TopologicalProperty.html} +43 -43
  232. package/docs/index.html +195 -68
  233. package/docs/interfaces/{HeapOptions.html → IBinaryTree.html} +39 -32
  234. package/docs/interfaces/IBinaryTreeNode.html +383 -0
  235. package/docs/interfaces/IDirectedGraph.html +20 -18
  236. package/docs/interfaces/IGraph.html +118 -88
  237. package/docs/interfaces/{PriorityQueueOptions.html → IUNDirectedGraph.html} +22 -53
  238. package/docs/modules.html +25 -21
  239. package/docs/types/{ToThunkFn.html → AVLTreeDeleted.html} +27 -21
  240. package/docs/types/BSTComparator.html +14 -12
  241. package/docs/types/BSTDeletedResult.html +19 -17
  242. package/docs/types/BinaryTreeDeleted.html +19 -17
  243. package/docs/types/BinaryTreeNodeId.html +14 -12
  244. package/docs/types/BinaryTreeNodePropertyName.html +14 -12
  245. package/docs/types/DFSOrderPattern.html +14 -12
  246. package/docs/types/DijkstraResult.html +14 -12
  247. package/docs/types/Direction.html +14 -12
  248. package/docs/types/{TrlFn.html → EdgeId.html} +18 -29
  249. package/docs/types/{TrlAsyncFn.html → HeapOptions.html} +29 -19
  250. package/docs/types/NavigatorParams.html +164 -0
  251. package/docs/types/NodeOrPropertyName.html +14 -12
  252. package/docs/types/PriorityQueueComparator.html +14 -12
  253. package/docs/types/PriorityQueueDFSOrderPattern.html +14 -12
  254. package/docs/types/{SpecifyOptional.html → PriorityQueueOptions.html} +28 -19
  255. package/docs/types/RecursiveAVLTreeNode.html +135 -0
  256. package/docs/types/{Thunk.html → RecursiveBSTNode.html} +23 -24
  257. package/docs/types/RecursiveBinaryTreeNode.html +135 -0
  258. package/docs/types/ResultByProperty.html +17 -15
  259. package/docs/types/ResultsByProperty.html +17 -15
  260. package/docs/types/SegmentTreeNodeVal.html +14 -12
  261. package/docs/types/TopologicalStatus.html +14 -12
  262. package/docs/types/TreeMultiSetDeletedResult.html +19 -17
  263. package/docs/types/Turning.html +14 -12
  264. package/docs/types/VertexId.html +14 -12
  265. package/notes/note.md +8 -1
  266. package/package.json +10 -2
  267. package/docs/classes/RBTree.html +0 -153
  268. package/docs/interfaces/NavigatorParams.html +0 -200
package/README.md CHANGED
@@ -8,10 +8,200 @@ wide range of data structures
8
8
 
9
9
  ## Data Structures
10
10
 
11
- Binary Tree, Binary Search Tree (BST), AVL Tree, Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed
12
- Graph, Undirected Graph, Linked List, Singly Linked List, Doubly Linked List, Queue, Object Deque, Array Deque, Stack,
13
- Hash, Coordinate Set, Coordinate Map, Heap, Priority Queue, Max Priority Queue, Min Priority Queue, Trie
11
+ <table>
12
+ <thead>
13
+ <tr>
14
+ <th>Data Structure</th>
15
+ <th>Unit Test</th>
16
+ <th>Performance Test</th>
17
+ <th>API Documentation</th>
18
+ <th>Implemented</th>
19
+ </tr>
20
+ </thead>
21
+ <tbody>
22
+ <tr>
23
+ <td>Binary Tree</td>
24
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt="">
25
+ </img></td>
26
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt="">
27
+ </img></td>
28
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTree.html"><span>Binary Tree</span></a></td>
29
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
30
+ </tr>
31
+ <tr>
32
+ <td>Binary Search Tree (BST)</td>
33
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
34
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
35
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/BST.html"><span>BST</span></a></td>
36
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
37
+ </tr>
38
+ <tr>
39
+ <td>AVL Tree</td>
40
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
41
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
42
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTree.html"><span>AVLTree</span></a></td>
43
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
44
+ </tr>
45
+ <tr>
46
+ <td>Tree Multiset</td>
47
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
48
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
49
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/TreeMultiSet.html"><span>TreeMultiSet</span></a></td>
50
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
51
+ </tr>
52
+ <tr>
53
+ <td>Segment Tree</td>
54
+ <td></td>
55
+ <td></td>
56
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTree.html"><span>SegmentTree</span></a></td>
57
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
58
+ </tr>
59
+ <tr>
60
+ <td>Binary Indexed Tree</td>
61
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
62
+ <td></td>
63
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryIndexedTree.html"><span>BinaryIndexedTree</span></a></td>
64
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
65
+ </tr>
66
+ <tr>
67
+ <td>Graph</td>
68
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
69
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
70
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractGraph.html"><span>AbstractGraph</span></a></td>
71
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
72
+ </tr>
73
+ <tr>
74
+ <td>Directed Graph</td>
75
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
76
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
77
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedGraph.html"><span>DirectedGraph</span></a></td>
78
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
79
+ </tr>
80
+ <tr>
81
+ <td>Undirected Graph</td>
82
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
83
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
84
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedGraph.html"><span>UndirectedGraph</span></a></td>
85
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
86
+ </tr>
87
+ <tr>
88
+ <td>Linked List</td>
89
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
90
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
91
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedList.html"><span>SinglyLinkedList</span></a></td>
92
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
93
+ </tr>
94
+ <tr>
95
+ <td>Singly Linked List</td>
96
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
97
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
98
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedList.html"><span>SinglyLinkedList</span></a></td>
99
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
100
+ </tr>
101
+ <tr>
102
+ <td>Doubly Linked List</td>
103
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
104
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
105
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/DoublyLinkedList.html"><span>DoublyLinkedList</span></a></td>
106
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
107
+ </tr>
108
+ <tr>
109
+ <td>Queue</td>
110
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
111
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
112
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/Queue.html"><span>Queue</span></a></td>
113
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
114
+ </tr>
115
+ <tr>
116
+ <td>Object Deque</td>
117
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
118
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
119
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/ObjectDeque.html"><span>ObjectDeque</span></a></td>
120
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
121
+ </tr>
122
+ <tr>
123
+ <td>Array Deque</td>
124
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
125
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
126
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/ArrayDeque.html"><span>ArrayDeque</span></a></td>
127
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
128
+ </tr>
129
+ <tr>
130
+ <td>Stack</td>
131
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
132
+ <td></td>
133
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/Stack.html"><span>Stack</span></a></td>
134
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
135
+ </tr>
136
+
137
+ [//]: # (<tr>)
138
+
139
+ [//]: # (<td>Hash</td>)
140
+
141
+ [//]: # (<td></td>)
142
+
143
+ [//]: # (<td></td>)
144
+
145
+ [//]: # (<td><a href="https://data-structure-typed-docs.vercel.app/classes/HashTable.html"><span>HashTable</span></a></td>)
146
+
147
+ [//]: # (<td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>)
148
+
149
+ [//]: # (</tr>)
150
+ <tr>
151
+ <td>Coordinate Set</td>
152
+ <td></td>
153
+ <td></td>
154
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateSet.html"><span>CoordinateSet</span></a></td>
155
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
156
+ </tr>
157
+ <tr>
158
+ <td>Coordinate Map</td>
159
+ <td></td>
160
+ <td></td>
161
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateMap.html"><span>CoordinateMap</span></a></td>
162
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
163
+ </tr>
164
+ <tr>
165
+ <td>Heap</td>
166
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
167
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
168
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/Heap.html"><span>Heap</span></a></td>
169
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
170
+ </tr>
171
+ <tr>
172
+ <td>Priority Queue</td>
173
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
174
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
175
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/PriorityQueue.html"><span>PriorityQueue</span></a></td>
176
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
177
+ </tr>
178
+ <tr>
179
+ <td>Max Priority Queue</td>
180
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
181
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
182
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/MaxPriorityQueue.html"><span>MaxPriorityQueue</span></a></td>
183
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
184
+ </tr>
185
+ <tr>
186
+ <td>Min Priority Queue</td>
187
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
188
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
189
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/MinPriorityQueue.html"><span>MinPriorityQueue</span></a></td>
190
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
191
+ </tr>
192
+ <tr>
193
+ <td>Trie</td>
194
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
195
+ <td></td>
196
+ <td><a href="https://data-structure-typed-docs.vercel.app/classes/Trie.html"><span>Trie</span></a></td>
197
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
198
+ </tr>
199
+ </tbody>
200
+ </table>
201
+
202
+ ## Algorithms list only a few out, you can discover more in API docs
14
203
 
204
+ DFS, DFSIterative, BFS, morris, Bellman-Ford Algorithm, Dijkstra's Algorithm, Floyd-Warshall Algorithm, Tarjan's Algorithm
15
205
 
16
206
  # How
17
207
 
@@ -409,69 +599,6 @@ describe('DirectedGraph Test3', () => {
409
599
 
410
600
  ## API docs
411
601
 
412
- [//]: # ([api docs]&#40;https://data-structure-typed-docs.vercel.app/&#41;)
413
-
414
- <nav class="tsd-navigation"><a href="https://data-structure-typed-docs.vercel.app/modules.html" class="current"><span>data-<wbr/>structure-<wbr/>typed</span></a>
415
- <ul class="tsd-small-nested-navigation">
416
-
417
- [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/enums/CP.html"><span>CP</span></a></li>)
418
-
419
- [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/enums/FamilyPosition.html"><span>Family<wbr/>Position</span></a></li>)
420
-
421
- [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/enums/LoopType.html"><span>Loop<wbr/>Type</span></a></li>)
422
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTree.html"><span>AVLTree</span></a></li>
423
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/AVLTreeNode.html"><span>AVLTree<wbr/>Node</span></a></li>
424
-
425
- [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/AaTree.html"><span>Aa<wbr/>Tree</span></a></li>)
426
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractEdge.html"><span>Abstract<wbr/>Edge</span></a></li>
427
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractGraph.html"><span>Abstract<wbr/>Graph</span></a></li>
428
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/AbstractVertex.html"><span>Abstract<wbr/>Vertex</span></a></li>
429
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/ArrayDeque.html"><span>Array<wbr/>Deque</span></a></li>
430
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/BST.html"><span>BST</span></a></li>
431
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/BSTNode.html"><span>BSTNode</span></a></li>
432
-
433
- [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/BTree.html"><span>BTree</span></a></li>)
434
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryIndexedTree.html"><span>Binary<wbr/>Indexed<wbr/>Tree</span></a></li>
435
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTree.html"><span>Binary<wbr/>Tree</span></a></li>
436
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTreeNode.html"><span>Binary<wbr/>Tree<wbr/>Node</span></a></li>
437
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Character.html"><span>Character</span></a></li>
438
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateMap.html"><span>Coordinate<wbr/>Map</span></a></li>
439
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/CoordinateSet.html"><span>Coordinate<wbr/>Set</span></a></li>
440
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Deque.html"><span>Deque</span></a></li>
441
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedEdge.html"><span>Directed<wbr/>Edge</span></a></li>
442
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedGraph.html"><span>Directed<wbr/>Graph</span></a></li>
443
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/DirectedVertex.html"><span>Directed<wbr/>Vertex</span></a></li>
444
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/DoublyLinkedList.html"><span>Doubly<wbr/>Linked<wbr/>List</span></a></li>
445
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/DoublyLinkedListNode.html"><span>Doubly<wbr/>Linked<wbr/>List<wbr/>Node</span></a></li>
446
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Heap.html"><span>Heap</span></a></li>
447
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Matrix2D.html"><span>Matrix2D</span></a></li>
448
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/MatrixNTI2D.html"><span>MatrixNTI2D</span></a></li>
449
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/MaxHeap.html"><span>Max<wbr/>Heap</span></a></li>
450
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/MaxPriorityQueue.html"><span>Max<wbr/>Priority<wbr/>Queue</span></a></li>
451
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/MinHeap.html"><span>Min<wbr/>Heap</span></a></li>
452
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/MinPriorityQueue.html"><span>Min<wbr/>Priority<wbr/>Queue</span></a></li>
453
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Navigator.html"><span>Navigator</span></a></li>
454
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/ObjectDeque.html"><span>Object<wbr/>Deque</span></a></li>
455
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/PriorityQueue.html"><span>Priority<wbr/>Queue</span></a></li>
456
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Queue.html"><span>Queue</span></a></li>
457
-
458
- [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/RBTree.html"><span>RBTree</span></a></li>)
459
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTree.html"><span>Segment<wbr/>Tree</span></a></li>
460
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/SegmentTreeNode.html"><span>Segment<wbr/>Tree<wbr/>Node</span></a></li>
461
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedList.html"><span>Singly<wbr/>Linked<wbr/>List</span></a></li>
462
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/SinglyLinkedListNode.html"><span>Singly<wbr/>Linked<wbr/>List<wbr/>Node</span></a></li>
463
-
464
- [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/SplayTree.html"><span>Splay<wbr/>Tree</span></a></li>)
465
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Stack.html"><span>Stack</span></a></li>
466
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/TreeMultiSet.html"><span>Tree<wbr/>Multi<wbr/>Set</span></a></li>
467
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Trie.html"><span>Trie</span></a></li>
468
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/TrieNode.html"><span>Trie<wbr/>Node</span></a></li>
469
-
470
- [//]: # (<li><a href="https://data-structure-typed-docs.vercel.app/classes/TwoThreeTree.html"><span>Two<wbr/>Three<wbr/>Tree</span></a></li>)
471
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedEdge.html"><span>Undirected<wbr/>Edge</span></a></li>
472
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedGraph.html"><span>Undirected<wbr/>Graph</span></a></li>
473
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/UndirectedVertex.html"><span>Undirected<wbr/>Vertex</span></a></li>
474
- <li><a href="https://data-structure-typed-docs.vercel.app/classes/Vector2D.html"><span>Vector2D</span></a></li></ul></nav>
475
602
 
476
603
  [//]: # ([Examples Repository]&#40;https://github.com/zrwusa/data-structure-typed-examples&#41;)
477
604
 
@@ -0,0 +1,3 @@
1
+ export class AaTree {
2
+
3
+ }
@@ -0,0 +1,288 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import {BST, BSTNode} from './bst';
9
+ import type {AVLTreeDeleted, BinaryTreeNodeId, RecursiveAVLTreeNode} from '../types';
10
+ import {IBinaryTreeNode} from '../interfaces';
11
+
12
+
13
+ export class AVLTreeNode<T, FAMILY extends AVLTreeNode<T, FAMILY > = RecursiveAVLTreeNode<T>> extends BSTNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
14
+
15
+ }
16
+
17
+ export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode<number>> extends BST<N> {
18
+
19
+ override _createNode(id: BinaryTreeNodeId, val: N['val'], count?: number): N {
20
+ const node = new AVLTreeNode<N['val'], N>(id, val, count);
21
+ return node as N;
22
+ }
23
+
24
+ /**
25
+ * The function overrides the add method of a Binary Search Tree to insert a node with a given id and value, and then
26
+ * balances the tree.
27
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add or
28
+ * update in the AVL tree.
29
+ * @param {N | null} val - The `val` parameter represents the value that you want to assign to the node with the given
30
+ * `id`. It can be of type `N` (the generic type) or `null`.
31
+ * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
32
+ * of times the value `val` should be inserted into the AVL tree. If the `count` parameter is not provided, it defaults
33
+ * to `1`, indicating that the value should be inserted once.
34
+ * @returns The method is returning either an N object or null.
35
+ */
36
+ override add(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null {
37
+ const inserted = super.add(id, val, count);
38
+ if (inserted) this.balancePath(inserted);
39
+ return inserted;
40
+ }
41
+
42
+ /**
43
+ * The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and
44
+ * then balances the tree if necessary.
45
+ * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
46
+ * removed from the AVL tree.
47
+ * @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean parameter that
48
+ * determines whether the left sum of all nodes in the AVL tree should be updated after removing a node. If
49
+ * `isUpdateAllLeftSum` is set to `true`, the left sum of all nodes will be recalculated.
50
+ * @returns The method is returning an array of `AVLTreeDeleted<N>` objects.
51
+ */
52
+ override remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): AVLTreeDeleted<N>[] {
53
+ const deletedResults = super.remove(id, isUpdateAllLeftSum);
54
+ for (const {needBalanced} of deletedResults) {
55
+ if (needBalanced) {
56
+ this.balancePath(needBalanced);
57
+ }
58
+ }
59
+ return deletedResults;
60
+ }
61
+
62
+ /**
63
+ * The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the
64
+ * height of its right subtree.
65
+ * @param node - The parameter "node" is of type N, which represents a node in an AVL tree.
66
+ * @returns The balance factor of the given AVL tree node.
67
+ */
68
+ balanceFactor(node: N): number {
69
+ if (!node.right) // node has no right subtree
70
+ return -node.height;
71
+ else if (!node.left) // node has no left subtree
72
+ return +node.height;
73
+ else
74
+ return node.right.height - node.left.height;
75
+ }
76
+
77
+ /**
78
+ * The function updates the height of a node in an AVL tree based on the heights of its left and right subtrees.
79
+ * @param node - The parameter `node` is an AVLTreeNode object, which represents a node in an AVL tree.
80
+ */
81
+ updateHeight(node: N): void {
82
+ if (!node.left && !node.right) // node is a leaf
83
+ node.height = 0;
84
+ else if (!node.left) {
85
+ // node has no left subtree
86
+ const rightHeight = node.right ? node.right.height : 0;
87
+ node.height = 1 + rightHeight;
88
+ } else if (!node.right) // node has no right subtree
89
+ node.height = 1 + node.left.height;
90
+ else
91
+ node.height = 1 + Math.max(node.right.height, node.left.height);
92
+ }
93
+
94
+ /**
95
+ * The `balancePath` function balances the AVL tree by performing appropriate rotations based on the balance factor of
96
+ * each node in the path from the given node to the root.
97
+ * @param node - The `node` parameter is an AVLTreeNode object, which represents a node in an AVL tree.
98
+ */
99
+ balancePath(node: N): void {
100
+ const path = this.getPathToRoot(node);
101
+ for (let i = path.length - 1; i >= 0; i--) {
102
+ const A = path[i];
103
+ this.updateHeight(A);
104
+ switch (this.balanceFactor(A)) {
105
+ case -2:
106
+ if (A && A.left) {
107
+ if (this.balanceFactor(A.left) <= 0) {
108
+ this.balanceLL(A); // Perform LL rotation
109
+ } else {
110
+ this.balanceLR(A); // Perform LR rotation
111
+ }
112
+ }
113
+ break;
114
+ case +2:
115
+ if (A && A.right) {
116
+ if (this.balanceFactor(A.right) >= 0) {
117
+ this.balanceRR(A); // Perform RR rotation
118
+ } else {
119
+ this.balanceRL(A); // Perform RL rotation
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+
126
+ /**
127
+ * The `balanceLL` function performs a left-left rotation on an AVL tree to balance it.
128
+ * @param A - The parameter A is an AVLTreeNode object.
129
+ */
130
+ balanceLL(A: N): void {
131
+ const parentOfA = A.parent;
132
+ const B = A.left; // A is left-heavy and B is left-heavy
133
+ A.parent = B;
134
+ if (B && B.right) {
135
+ B.right.parent = A;
136
+ }
137
+ if (B) B.parent = parentOfA;
138
+ if (A === this.root) {
139
+ if (B) this._setRoot(B);
140
+ } else {
141
+ if (parentOfA?.left === A) {
142
+ parentOfA.left = B;
143
+ } else {
144
+ if (parentOfA) parentOfA.right = B;
145
+ }
146
+ }
147
+
148
+ if (B) {
149
+ A.left = B.right; // Make T2 the left subtree of A
150
+ B.right = A; // Make A the left child of B
151
+ }
152
+ this.updateHeight(A);
153
+ if (B) this.updateHeight(B);
154
+ }
155
+
156
+ /**
157
+ * The `balanceLR` function performs a left-right rotation to balance an AVL tree.
158
+ * @param A - A is an AVLTreeNode object.
159
+ */
160
+ balanceLR(A: N): void {
161
+ const parentOfA = A.parent;
162
+ const B = A.left; // A is left-heavy
163
+ let C = null;
164
+ if (B) {
165
+ C = B.right;// B is right-heavy
166
+ }
167
+ if (A) A.parent = C;
168
+ if (B) B.parent = C;
169
+
170
+ if (C) {
171
+ if (C.left) {
172
+ C.left.parent = B;
173
+ }
174
+ if (C.right) {
175
+ C.right.parent = A;
176
+ }
177
+ C.parent = parentOfA;
178
+ }
179
+
180
+ if (A === this.root) {
181
+ if (C) this._setRoot(C);
182
+ } else {
183
+ if (parentOfA) {
184
+ if (parentOfA.left === A) {
185
+ parentOfA.left = C;
186
+ } else {
187
+ parentOfA.right = C;
188
+ }
189
+ }
190
+ }
191
+
192
+ if (C) {
193
+ A.left = C.right; // Make T3 the left subtree of A
194
+ if (B) B.right = C.left; // Make T2 the right subtree of B
195
+ C.left = B;
196
+ C.right = A;
197
+ }
198
+
199
+ this.updateHeight(A); // Adjust heights
200
+ B && this.updateHeight(B);
201
+ C && this.updateHeight(C);
202
+ }
203
+
204
+ /**
205
+ * The `balanceRR` function performs a right-right rotation on an AVL tree to balance it.
206
+ * @param A - The parameter A is an AVLTreeNode object.
207
+ */
208
+ balanceRR(A: N): void {
209
+ const parentOfA = A.parent;
210
+ const B = A.right; // A is right-heavy and B is right-heavy
211
+ A.parent = B;
212
+ if (B) {
213
+ if (B.left) {
214
+ B.left.parent = A;
215
+ }
216
+ B.parent = parentOfA;
217
+ }
218
+
219
+ if (A === this.root) {
220
+ if (B) this._setRoot(B);
221
+ } else {
222
+ if (parentOfA) {
223
+ if (parentOfA.left === A) {
224
+ parentOfA.left = B;
225
+ } else {
226
+ parentOfA.right = B;
227
+ }
228
+ }
229
+ }
230
+
231
+ if (B) {
232
+ A.right = B.left; // Make T2 the right subtree of A
233
+ B.left = A;
234
+ }
235
+ this.updateHeight(A);
236
+ B && this.updateHeight(B);
237
+ }
238
+
239
+ /**
240
+ * The `balanceRL` function performs a right-left rotation to balance an AVL tree.
241
+ * @param A - A is an AVLTreeNode object.
242
+ */
243
+ balanceRL(A: N): void {
244
+ const parentOfA = A.parent;
245
+ const B = A.right; // A is right-heavy
246
+ let C = null;
247
+ if (B) {
248
+ C = B.left; // B is left-heavy
249
+ }
250
+
251
+ A.parent = C;
252
+ if (B) B.parent = C;
253
+
254
+ if (C) {
255
+ if (C.left) {
256
+ C.left.parent = A;
257
+ }
258
+ if (C.right) {
259
+ C.right.parent = B;
260
+ }
261
+ C.parent = parentOfA;
262
+ }
263
+
264
+
265
+ if (A === this.root) {
266
+ if (C) this._setRoot(C);
267
+ } else {
268
+ if (parentOfA) {
269
+ if (parentOfA.left === A) {
270
+ parentOfA.left = C;
271
+ } else {
272
+ parentOfA.right = C;
273
+ }
274
+ }
275
+ }
276
+
277
+ if (C) A.right = C.left; // Make T2 the right subtree of A
278
+ if (B && C) B.left = C.right; // Make T3 the left subtree of B
279
+ if (C) C.left = A;
280
+ if (C) C.right = B;
281
+
282
+ this.updateHeight(A); // Adjust heights
283
+ B && this.updateHeight(B);
284
+ C && this.updateHeight(C);
285
+ }
286
+ }
287
+
288
+
@@ -0,0 +1,3 @@
1
+ export class BTree {
2
+
3
+ }