@raikuxq/alg-ds 1.2.4 → 2.0.0
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.
- package/README.md +0 -25
- package/lib/index.d.ts +1216 -3
- package/lib/index.mjs +1 -0
- package/package.json +78 -72
- package/lib/app/algorithms/binary-search.d.ts +0 -5
- package/lib/app/algorithms/binary-search.js +0 -27
- package/lib/app/algorithms/factorial.d.ts +0 -9
- package/lib/app/algorithms/factorial.js +0 -17
- package/lib/app/algorithms/fibonacci.d.ts +0 -9
- package/lib/app/algorithms/fibonacci.js +0 -17
- package/lib/app/algorithms/graph/iterator/AbstractGraphIterator.d.ts +0 -39
- package/lib/app/algorithms/graph/iterator/AbstractGraphIterator.js +0 -87
- package/lib/app/algorithms/graph/iterator/GraphIteratorBFS.d.ts +0 -28
- package/lib/app/algorithms/graph/iterator/GraphIteratorBFS.js +0 -70
- package/lib/app/algorithms/graph/iterator/GraphIteratorDFS.d.ts +0 -28
- package/lib/app/algorithms/graph/iterator/GraphIteratorDFS.js +0 -70
- package/lib/app/algorithms/graph/iterator/GraphIteratorDijkstra.d.ts +0 -32
- package/lib/app/algorithms/graph/iterator/GraphIteratorDijkstra.js +0 -97
- package/lib/app/algorithms/graph/iterator-strategy/BFSIterationStrategy.d.ts +0 -6
- package/lib/app/algorithms/graph/iterator-strategy/BFSIterationStrategy.js +0 -13
- package/lib/app/algorithms/graph/iterator-strategy/DFSIterationStrategy.d.ts +0 -6
- package/lib/app/algorithms/graph/iterator-strategy/DFSIterationStrategy.js +0 -13
- package/lib/app/algorithms/graph/iterator-strategy/DijkstraIterationStrategy.d.ts +0 -6
- package/lib/app/algorithms/graph/iterator-strategy/DijkstraIterationStrategy.js +0 -13
- package/lib/app/algorithms/graph/presenter/presenterAdjacencyLists.d.ts +0 -19
- package/lib/app/algorithms/graph/presenter/presenterAdjacencyLists.js +0 -28
- package/lib/app/algorithms/graph/presenter/presenterAdjacencyMatrix.d.ts +0 -32
- package/lib/app/algorithms/graph/presenter/presenterAdjacencyMatrix.js +0 -48
- package/lib/app/algorithms/graph/searching/hasPath.d.ts +0 -9
- package/lib/app/algorithms/graph/searching/hasPath.js +0 -30
- package/lib/app/algorithms/graph/searching/shortestPath.d.ts +0 -9
- package/lib/app/algorithms/graph/searching/shortestPath.js +0 -30
- package/lib/app/algorithms/graph/transposing/transposeDirectedGraph.d.ts +0 -2
- package/lib/app/algorithms/graph/transposing/transposeDirectedGraph.js +0 -14
- package/lib/app/algorithms/memoize.d.ts +0 -5
- package/lib/app/algorithms/memoize.js +0 -22
- package/lib/app/algorithms/sorts/bubble-sort.d.ts +0 -9
- package/lib/app/algorithms/sorts/bubble-sort.js +0 -23
- package/lib/app/algorithms/sorts/insertion-sort.d.ts +0 -9
- package/lib/app/algorithms/sorts/insertion-sort.js +0 -25
- package/lib/app/algorithms/sorts/merge-sort.d.ts +0 -9
- package/lib/app/algorithms/sorts/merge-sort.js +0 -61
- package/lib/app/algorithms/sorts/quick-sort.d.ts +0 -9
- package/lib/app/algorithms/sorts/quick-sort.js +0 -45
- package/lib/app/algorithms/sorts/select-sort.d.ts +0 -9
- package/lib/app/algorithms/sorts/select-sort.js +0 -20
- package/lib/app/algorithms/transpose-matrix.d.ts +0 -6
- package/lib/app/algorithms/transpose-matrix.js +0 -19
- package/lib/app/constants.d.ts +0 -2
- package/lib/app/constants.js +0 -6
- package/lib/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.d.ts +0 -15
- package/lib/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.js +0 -53
- package/lib/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.d.ts +0 -60
- package/lib/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.js +0 -35
- package/lib/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.d.ts +0 -13
- package/lib/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.js +0 -59
- package/lib/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.d.ts +0 -75
- package/lib/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.js +0 -276
- package/lib/app/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.d.ts +0 -16
- package/lib/app/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.js +0 -70
- package/lib/app/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.d.ts +0 -58
- package/lib/app/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.js +0 -236
- package/lib/app/data-structures/BinaryTree/_helpers/createBinaryTree.d.ts +0 -6
- package/lib/app/data-structures/BinaryTree/_helpers/createBinaryTree.js +0 -22
- package/lib/app/data-structures/Graph/AbstractGraph.d.ts +0 -84
- package/lib/app/data-structures/Graph/AbstractGraph.js +0 -143
- package/lib/app/data-structures/Graph/DirectedGraph.d.ts +0 -27
- package/lib/app/data-structures/Graph/DirectedGraph.js +0 -89
- package/lib/app/data-structures/Graph/GraphEdge.d.ts +0 -16
- package/lib/app/data-structures/Graph/GraphEdge.js +0 -43
- package/lib/app/data-structures/Graph/UndirectedGraph.d.ts +0 -31
- package/lib/app/data-structures/Graph/UndirectedGraph.js +0 -106
- package/lib/app/data-structures/Graph/_helpers/createGraph.d.ts +0 -6
- package/lib/app/data-structures/Graph/_helpers/createGraph.js +0 -22
- package/lib/app/data-structures/Graph/_helpers/createGraphFromMatrix.d.ts +0 -7
- package/lib/app/data-structures/Graph/_helpers/createGraphFromMatrix.js +0 -42
- package/lib/app/data-structures/Graph/_helpers/generateRandomGraph.d.ts +0 -4
- package/lib/app/data-structures/Graph/_helpers/generateRandomGraph.js +0 -67
- package/lib/app/data-structures/HashTable/HashTable.d.ts +0 -73
- package/lib/app/data-structures/HashTable/HashTable.js +0 -171
- package/lib/app/data-structures/HashTable/HashTableNode.d.ts +0 -11
- package/lib/app/data-structures/HashTable/HashTableNode.js +0 -39
- package/lib/app/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.d.ts +0 -134
- package/lib/app/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.js +0 -247
- package/lib/app/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedNode.d.ts +0 -20
- package/lib/app/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedNode.js +0 -41
- package/lib/app/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.d.ts +0 -42
- package/lib/app/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.js +0 -98
- package/lib/app/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedNode.d.ts +0 -25
- package/lib/app/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedNode.js +0 -65
- package/lib/app/data-structures/LinkedList/DoubleLinkedList/IterableDoubleLinkedList.d.ts +0 -18
- package/lib/app/data-structures/LinkedList/DoubleLinkedList/IterableDoubleLinkedList.js +0 -86
- package/lib/app/data-structures/LinkedList/SingleLinkedList/IterableSingleLinkedList.d.ts +0 -18
- package/lib/app/data-structures/LinkedList/SingleLinkedList/IterableSingleLinkedList.js +0 -68
- package/lib/app/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.d.ts +0 -46
- package/lib/app/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.js +0 -103
- package/lib/app/data-structures/LinkedList/SingleLinkedList/SingleLinkedNode.d.ts +0 -7
- package/lib/app/data-structures/LinkedList/SingleLinkedList/SingleLinkedNode.js +0 -29
- package/lib/app/data-structures/LinkedList/_helpers/createLinkedList.d.ts +0 -3
- package/lib/app/data-structures/LinkedList/_helpers/createLinkedList.js +0 -34
- package/lib/app/data-structures/LoopedArray/LoopedArray.d.ts +0 -86
- package/lib/app/data-structures/LoopedArray/LoopedArray.js +0 -165
- package/lib/app/data-structures/Queue/Queue.d.ts +0 -50
- package/lib/app/data-structures/Queue/Queue.js +0 -85
- package/lib/app/data-structures/Stack/Stack.d.ts +0 -50
- package/lib/app/data-structures/Stack/Stack.js +0 -85
- package/lib/app/exceptions/CollectionIsEmptyException.d.ts +0 -4
- package/lib/app/exceptions/CollectionIsEmptyException.js +0 -28
- package/lib/app/exceptions/CollectionIsFullException.d.ts +0 -4
- package/lib/app/exceptions/CollectionIsFullException.js +0 -28
- package/lib/app/exceptions/IndexOutOfBoundsException.d.ts +0 -4
- package/lib/app/exceptions/IndexOutOfBoundsException.js +0 -28
- package/lib/app/exceptions/IsAlreadyExistsException.d.ts +0 -4
- package/lib/app/exceptions/IsAlreadyExistsException.js +0 -28
- package/lib/app/exceptions/IsNotFoundException.d.ts +0 -4
- package/lib/app/exceptions/IsNotFoundException.js +0 -28
- package/lib/app/exceptions/ValueOutOfRangeException.d.ts +0 -4
- package/lib/app/exceptions/ValueOutOfRangeException.js +0 -28
- package/lib/app/exceptions/base/IllegalArgumentException.d.ts +0 -3
- package/lib/app/exceptions/base/IllegalArgumentException.js +0 -27
- package/lib/app/exceptions/base/IllegalStateException.d.ts +0 -3
- package/lib/app/exceptions/base/IllegalStateException.js +0 -27
- package/lib/app/types/EnumBinarySearchTreeType.d.ts +0 -4
- package/lib/app/types/EnumBinarySearchTreeType.js +0 -9
- package/lib/app/types/EnumGraphTraversalType.d.ts +0 -5
- package/lib/app/types/EnumGraphTraversalType.js +0 -10
- package/lib/app/types/EnumGraphType.d.ts +0 -4
- package/lib/app/types/EnumGraphType.js +0 -9
- package/lib/app/types/EnumLinkedListType.d.ts +0 -4
- package/lib/app/types/EnumLinkedListType.js +0 -9
- package/lib/app/types/EnumRandomGenerationFormat.d.ts +0 -4
- package/lib/app/types/EnumRandomGenerationFormat.js +0 -9
- package/lib/app/types/EnumSortType.d.ts +0 -7
- package/lib/app/types/EnumSortType.js +0 -12
- package/lib/app/types/EnumTreeTraversalType.d.ts +0 -5
- package/lib/app/types/EnumTreeTraversalType.js +0 -10
- package/lib/app/types/FnCompareTwo.d.ts +0 -1
- package/lib/app/types/FnCompareTwo.js +0 -3
- package/lib/app/types/FnToMemoize.d.ts +0 -1
- package/lib/app/types/FnToMemoize.js +0 -3
- package/lib/app/types/IArrayFacade.d.ts +0 -4
- package/lib/app/types/IArrayFacade.js +0 -3
- package/lib/app/types/IBiDirectIterable.d.ts +0 -5
- package/lib/app/types/IBiDirectIterable.js +0 -3
- package/lib/app/types/IBiDirectIterator.d.ts +0 -11
- package/lib/app/types/IBiDirectIterator.js +0 -3
- package/lib/app/types/IBinaryTree.d.ts +0 -12
- package/lib/app/types/IBinaryTree.js +0 -3
- package/lib/app/types/IConvertableToArray.d.ts +0 -4
- package/lib/app/types/IConvertableToArray.js +0 -3
- package/lib/app/types/IGraph.d.ts +0 -14
- package/lib/app/types/IGraph.js +0 -3
- package/lib/app/types/IGraphIterationStrategy.d.ts +0 -5
- package/lib/app/types/IGraphIterationStrategy.js +0 -3
- package/lib/app/types/IGraphIterator.d.ts +0 -11
- package/lib/app/types/IGraphIterator.js +0 -3
- package/lib/app/types/IIterable.d.ts +0 -4
- package/lib/app/types/IIterable.js +0 -3
- package/lib/app/types/IIterator.d.ts +0 -14
- package/lib/app/types/IIterator.js +0 -3
- package/lib/app/types/IKeyValueStorage.d.ts +0 -8
- package/lib/app/types/IKeyValueStorage.js +0 -3
- package/lib/app/types/ILinearStorage.d.ts +0 -11
- package/lib/app/types/ILinearStorage.js +0 -3
- package/lib/app/types/ILinearStorageRA.d.ts +0 -13
- package/lib/app/types/ILinearStorageRA.js +0 -3
- package/lib/app/types/ILinkedList.d.ts +0 -4
- package/lib/app/types/ILinkedList.js +0 -3
- package/lib/app/types/TypeArrayMatrix.d.ts +0 -1
- package/lib/app/types/TypeArrayMatrix.js +0 -3
- package/lib/app/utils.d.ts +0 -37
- package/lib/app/utils.js +0 -115
- package/lib/exports/algorithms.d.ts +0 -16
- package/lib/exports/algorithms.js +0 -36
- package/lib/exports/constants.d.ts +0 -2
- package/lib/exports/constants.js +0 -7
- package/lib/exports/data-structures.d.ts +0 -13
- package/lib/exports/data-structures.js +0 -28
- package/lib/exports/helpers.d.ts +0 -6
- package/lib/exports/helpers.js +0 -14
- package/lib/exports/sorts.d.ts +0 -6
- package/lib/exports/sorts.js +0 -14
- package/lib/exports/types.d.ts +0 -16
- package/lib/exports/types.js +0 -34
- package/lib/exports/utils.d.ts +0 -3
- package/lib/exports/utils.js +0 -14
- package/lib/exports.d.ts +0 -55
- package/lib/exports.js +0 -109
- package/lib/index.js +0 -5
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,1216 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
export type FnToMemoize<Key, Value> = (...args: Array<Key>) => Value;
|
|
4
|
+
/**
|
|
5
|
+
* Time complexity: O(n!)
|
|
6
|
+
*/
|
|
7
|
+
export declare const factorial: (x: number) => number;
|
|
8
|
+
/**
|
|
9
|
+
* Time complexity: O(n) - due to caching
|
|
10
|
+
*/
|
|
11
|
+
export declare const memoizedFactorial: FnToMemoize<number, number>;
|
|
12
|
+
/**
|
|
13
|
+
* Time complexity: O(n!)
|
|
14
|
+
*/
|
|
15
|
+
export declare const fibonacci: (n: number) => number;
|
|
16
|
+
/**
|
|
17
|
+
* Time complexity: O(n) - due to caching
|
|
18
|
+
*/
|
|
19
|
+
export declare const memoizedFibonacci: FnToMemoize<number, number>;
|
|
20
|
+
/**
|
|
21
|
+
* Find element's index in sorted array
|
|
22
|
+
* Time complexity: O(log(n))
|
|
23
|
+
*/
|
|
24
|
+
export declare const binarySearch: (elements: Array<number>, searchElement: number) => number | null;
|
|
25
|
+
export type TypeArrayMatrix = Array<Array<number>>;
|
|
26
|
+
/**
|
|
27
|
+
* Will flips a matrix over its diagonal
|
|
28
|
+
* @throws {IllegalArgumentException} when array is not a matrix
|
|
29
|
+
*/
|
|
30
|
+
export declare const transposeMatrix: (matrix: TypeArrayMatrix) => TypeArrayMatrix;
|
|
31
|
+
export interface IGraph<T> {
|
|
32
|
+
weight(): number;
|
|
33
|
+
vertices(): Array<T>;
|
|
34
|
+
verticesCount(): number;
|
|
35
|
+
edgesCount(): number;
|
|
36
|
+
addVertex(data: T): this;
|
|
37
|
+
removeVertex(data: T): this;
|
|
38
|
+
hasVertex(data: T): boolean;
|
|
39
|
+
getVertexNeighbors(data: T): Array<T>;
|
|
40
|
+
addEdge(from: T, to: T, weight?: number): this;
|
|
41
|
+
removeEdge(from: T, to: T): this;
|
|
42
|
+
hasEdge(from: T, to: T): boolean;
|
|
43
|
+
getEdgeWeight(from: T, to: T): number;
|
|
44
|
+
}
|
|
45
|
+
export declare const transposeDirectedGraph: <T>(sourceGraph: IGraph<T>) => IGraph<T>;
|
|
46
|
+
export interface IIterator<T> {
|
|
47
|
+
/**
|
|
48
|
+
* Will do one iteration and returns next item value
|
|
49
|
+
*/
|
|
50
|
+
next(): T;
|
|
51
|
+
/**
|
|
52
|
+
* Will returns current value
|
|
53
|
+
*/
|
|
54
|
+
current(): T;
|
|
55
|
+
/**
|
|
56
|
+
* Check if next element exists
|
|
57
|
+
*/
|
|
58
|
+
hasNext(): boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface IGraphIterator<T> extends IIterator<T> {
|
|
61
|
+
/**
|
|
62
|
+
* Get path which passed by iterator between two vertices
|
|
63
|
+
*/
|
|
64
|
+
getPath(from: T, to: T): Array<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Initialize iterator by passing start vertex
|
|
67
|
+
*/
|
|
68
|
+
initIterator(from: T): void;
|
|
69
|
+
}
|
|
70
|
+
export interface IGraphIterationStrategy<T> {
|
|
71
|
+
createIterator(graph: IGraph<T>): IGraphIterator<T>;
|
|
72
|
+
}
|
|
73
|
+
export declare class BFSIterationStrategy<T> implements IGraphIterationStrategy<T> {
|
|
74
|
+
createIterator(graph: IGraph<T>): IGraphIterator<T>;
|
|
75
|
+
}
|
|
76
|
+
export declare class DFSIterationStrategy<T> implements IGraphIterationStrategy<T> {
|
|
77
|
+
createIterator(graph: IGraph<T>): IGraphIterator<T>;
|
|
78
|
+
}
|
|
79
|
+
export declare class DijkstraIterationStrategy<T> implements IGraphIterationStrategy<T> {
|
|
80
|
+
createIterator(graph: IGraph<T>): IGraphIterator<T>;
|
|
81
|
+
}
|
|
82
|
+
declare abstract class AbstractGraphIterator<T> implements IGraphIterator<T> {
|
|
83
|
+
protected readonly graph: IGraph<T>;
|
|
84
|
+
protected readonly visited: Map<T, boolean>;
|
|
85
|
+
protected readonly parents: Map<T, T>;
|
|
86
|
+
/**
|
|
87
|
+
* Creates empty instance
|
|
88
|
+
*/
|
|
89
|
+
protected constructor(graph: IGraph<T>);
|
|
90
|
+
protected abstract currentImpl(): T;
|
|
91
|
+
protected abstract nextImpl(): T;
|
|
92
|
+
protected abstract initIteratorImpl(from: T): void;
|
|
93
|
+
protected abstract hasNextImpl(): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* @inheritDoc
|
|
96
|
+
* @throws {IsNotFoundException} when start vertex was not found
|
|
97
|
+
*/
|
|
98
|
+
initIterator(from: T): void;
|
|
99
|
+
/**
|
|
100
|
+
* @inheritDoc
|
|
101
|
+
*/
|
|
102
|
+
hasNext(): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* @inheritDoc
|
|
105
|
+
* @throws {IllegalStateException} when next element does not exist
|
|
106
|
+
*/
|
|
107
|
+
next(): T;
|
|
108
|
+
/**
|
|
109
|
+
* @inheritDoc
|
|
110
|
+
* @throws {IllegalStateException} when current element does not exist
|
|
111
|
+
*/
|
|
112
|
+
current(): T;
|
|
113
|
+
/**
|
|
114
|
+
* @inheritDoc
|
|
115
|
+
* @throws {IllegalStateException} when there is no path between given vertices
|
|
116
|
+
*/
|
|
117
|
+
getPath(from: T, to: T): Array<T>;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Breadth first graph traversal
|
|
121
|
+
*/
|
|
122
|
+
export declare class GraphIteratorBFS<T> extends AbstractGraphIterator<T> {
|
|
123
|
+
private readonly queue;
|
|
124
|
+
/**
|
|
125
|
+
* @inheritDoc
|
|
126
|
+
*/
|
|
127
|
+
constructor(graph: IGraph<T>);
|
|
128
|
+
/**
|
|
129
|
+
* @inheritDoc
|
|
130
|
+
*/
|
|
131
|
+
protected currentImpl(): T;
|
|
132
|
+
/**
|
|
133
|
+
@inheritDoc
|
|
134
|
+
*/
|
|
135
|
+
initIteratorImpl(startVertex: T): void;
|
|
136
|
+
/**
|
|
137
|
+
* @inheritDoc
|
|
138
|
+
*/
|
|
139
|
+
hasNextImpl(): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* @inheritDoc
|
|
142
|
+
*/
|
|
143
|
+
protected nextImpl(): T;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Deep first graph traversal
|
|
147
|
+
*/
|
|
148
|
+
export declare class GraphIteratorDFS<T> extends AbstractGraphIterator<T> {
|
|
149
|
+
private readonly stack;
|
|
150
|
+
/**
|
|
151
|
+
* @inheritDoc
|
|
152
|
+
*/
|
|
153
|
+
constructor(graph: IGraph<T>);
|
|
154
|
+
/**
|
|
155
|
+
* @inheritDoc
|
|
156
|
+
*/
|
|
157
|
+
hasNextImpl(): boolean;
|
|
158
|
+
/**
|
|
159
|
+
@inheritDoc
|
|
160
|
+
*/
|
|
161
|
+
initIteratorImpl(startVertex: T): void;
|
|
162
|
+
/**
|
|
163
|
+
* @inheritDoc
|
|
164
|
+
*/
|
|
165
|
+
currentImpl(): T;
|
|
166
|
+
/**
|
|
167
|
+
* @inheritDoc
|
|
168
|
+
*/
|
|
169
|
+
nextImpl(): T;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Dijkstra method graph traversal
|
|
173
|
+
*/
|
|
174
|
+
export declare class GraphIteratorDijkstra<T> extends AbstractGraphIterator<T> {
|
|
175
|
+
private readonly costs;
|
|
176
|
+
/**
|
|
177
|
+
* @inheritDoc
|
|
178
|
+
*/
|
|
179
|
+
constructor(graph: IGraph<T>);
|
|
180
|
+
/**
|
|
181
|
+
* Get not visited vertex with minimal cost
|
|
182
|
+
*/
|
|
183
|
+
private getClosestNotVisited;
|
|
184
|
+
/**
|
|
185
|
+
* @inheritDoc
|
|
186
|
+
*/
|
|
187
|
+
initIteratorImpl(startVertex: T): void;
|
|
188
|
+
/**
|
|
189
|
+
* @inheritDoc
|
|
190
|
+
*/
|
|
191
|
+
hasNextImpl(): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* @inheritDoc
|
|
194
|
+
*/
|
|
195
|
+
currentImpl(): T;
|
|
196
|
+
/**
|
|
197
|
+
* @inheritDoc
|
|
198
|
+
*/
|
|
199
|
+
nextImpl(): T;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Check if graph has a path between two vertices
|
|
203
|
+
* @throws {IsNotFoundException} when start vertex was not found
|
|
204
|
+
* @throws {IsNotFoundException} when end vertex was not found
|
|
205
|
+
* @throws {IllegalStateException} when there is no path between two vertices
|
|
206
|
+
*/
|
|
207
|
+
export declare const hasPath: <T>(graph: IGraph<T>, from: T, to: T, strategy: IGraphIterationStrategy<T>) => boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Find the shortest path between two vertices
|
|
210
|
+
* @throws {IsNotFoundException} when start vertex was not found
|
|
211
|
+
* @throws {IsNotFoundException} when end vertex was not found
|
|
212
|
+
* @throws {IllegalStateException} when there is no path between two vertices
|
|
213
|
+
*/
|
|
214
|
+
export declare const shortestPath: <T>(graph: IGraph<T>, from: T, to: T, strategy: IGraphIterationStrategy<T>) => Array<T>;
|
|
215
|
+
/**
|
|
216
|
+
* Get graph adjacency matrix N x N
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
*
|
|
220
|
+
* Directed graph:
|
|
221
|
+
* - Bob [Maria]
|
|
222
|
+
* - Maria [Bob, John]
|
|
223
|
+
* - John []
|
|
224
|
+
*
|
|
225
|
+
* Its matrix:
|
|
226
|
+
* | Bob | Maria | John |
|
|
227
|
+
* Bob | 0 | 1 | 0 |
|
|
228
|
+
* Maria | 1 | 0 | 1 |
|
|
229
|
+
* John | 0 | 0 | 0 |
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
*
|
|
233
|
+
* Undirected graph:
|
|
234
|
+
* - Bob [Maria]
|
|
235
|
+
* - Maria [Bob, John]
|
|
236
|
+
* - John [Maria]
|
|
237
|
+
*
|
|
238
|
+
* Its matrix:
|
|
239
|
+
* | Bob | Maria | John |
|
|
240
|
+
* Bob | 0 | 1 | 0 |
|
|
241
|
+
* Maria | 1 | 0 | 1 |
|
|
242
|
+
* John | 0 | 1 | 0 |
|
|
243
|
+
*/
|
|
244
|
+
export declare const presenterAdjacencyMatrix: <T>(graph: IGraph<T>) => TypeArrayMatrix;
|
|
245
|
+
/**
|
|
246
|
+
* Get graph adjacency list
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
*
|
|
250
|
+
* Directed graph:
|
|
251
|
+
* - Bob [Maria]
|
|
252
|
+
* - Maria [Bob, John]
|
|
253
|
+
* - John []
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
*
|
|
257
|
+
* Undirected graph:
|
|
258
|
+
* - Bob [Maria]
|
|
259
|
+
* - Maria [Bob, John]
|
|
260
|
+
* - John [Maria]
|
|
261
|
+
**/
|
|
262
|
+
export declare const presenterAdjacencyLists: <T>(graph: IGraph<T>) => Map<T, Array<T>>;
|
|
263
|
+
declare enum EnumGraphType {
|
|
264
|
+
DIRECTED = "DIRECTED",
|
|
265
|
+
UNDIRECTED = "UNDIRECTED"
|
|
266
|
+
}
|
|
267
|
+
declare enum EnumRandomGenerationFormat {
|
|
268
|
+
NUMBERS = "NUMBERS",
|
|
269
|
+
HASH = "HASH"
|
|
270
|
+
}
|
|
271
|
+
export declare const generateRandomGraph: (verticesCount: number, edgesCount: number, type?: EnumGraphType, format?: EnumRandomGenerationFormat) => IGraph<string>;
|
|
272
|
+
declare enum EnumLinkedListType {
|
|
273
|
+
DOUBLE = "Double linked list",
|
|
274
|
+
SINGLE = "Single linked list"
|
|
275
|
+
}
|
|
276
|
+
export interface ILinearStorage<T> {
|
|
277
|
+
peek(): T;
|
|
278
|
+
push(value: T): void;
|
|
279
|
+
pop(): T;
|
|
280
|
+
has(value: T): boolean;
|
|
281
|
+
isEmpty(): boolean;
|
|
282
|
+
isFull(): boolean;
|
|
283
|
+
length(): number;
|
|
284
|
+
clear(): void;
|
|
285
|
+
reverse(): void;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Interface extends default linear storage with methods that allows read/write operations for all storage elements
|
|
289
|
+
* RA - randomly accessible
|
|
290
|
+
*/
|
|
291
|
+
export interface ILinearStorageRA<T> extends ILinearStorage<T> {
|
|
292
|
+
peekFromStart(): T;
|
|
293
|
+
peekByIndex(index: number): T;
|
|
294
|
+
unshift(value: T): void;
|
|
295
|
+
pushFromIndex(value: T, fromIndex: number): void;
|
|
296
|
+
shift(): T;
|
|
297
|
+
deleteFromIndex(fromIndex: number): T;
|
|
298
|
+
}
|
|
299
|
+
export interface IConvertableToArray<T> {
|
|
300
|
+
pushFromArray(elements: Array<T>): void;
|
|
301
|
+
getAsArray(): Array<T>;
|
|
302
|
+
}
|
|
303
|
+
export interface ILinkedList<T> extends ILinearStorageRA<T>, IConvertableToArray<T> {
|
|
304
|
+
}
|
|
305
|
+
export declare const createLinkedList: <T>(type: EnumLinkedListType, isIterable?: boolean, capacity?: number) => ILinkedList<T>;
|
|
306
|
+
declare enum EnumBinarySearchTreeType {
|
|
307
|
+
BST = "Binary Search Tree",
|
|
308
|
+
RANDOMIZED_BST = "Randomized Binary Search Tree"
|
|
309
|
+
}
|
|
310
|
+
declare enum EnumTreeTraversalType {
|
|
311
|
+
IN_ORDER = "IN_ORDER",
|
|
312
|
+
PRE_ORDER = "PRE_ORDER",
|
|
313
|
+
POST_ORDER = "POST_ORDER"
|
|
314
|
+
}
|
|
315
|
+
export interface IBinaryTree<T> {
|
|
316
|
+
has(value: T): boolean;
|
|
317
|
+
insert(value: T): void;
|
|
318
|
+
delete(value: T): void;
|
|
319
|
+
subtree(value: T): IBinaryTree<T>;
|
|
320
|
+
max(): T;
|
|
321
|
+
min(): T;
|
|
322
|
+
length(): number;
|
|
323
|
+
height(): number;
|
|
324
|
+
traverse(type: EnumTreeTraversalType): Array<T>;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Returns binary tree by type
|
|
328
|
+
*/
|
|
329
|
+
export declare const createBinaryTree: <T>(type: EnumBinarySearchTreeType) => IBinaryTree<T>;
|
|
330
|
+
/**
|
|
331
|
+
* Returns graph by type
|
|
332
|
+
*/
|
|
333
|
+
export declare const createGraph: <T>(type: EnumGraphType) => IGraph<T>;
|
|
334
|
+
/**
|
|
335
|
+
* Creates a graph from N*N matrix that contains 1 in case of edge exists or 0 in case it does not
|
|
336
|
+
*/
|
|
337
|
+
export declare const createGraphFromMatrix: <T>(matrix: TypeArrayMatrix, fieldsList: Array<T>, type: EnumGraphType) => IGraph<T>;
|
|
338
|
+
export declare const EDGE_EXISTS_STATE = 1;
|
|
339
|
+
export declare const EDGE_NOT_EXISTS_STATE = 0;
|
|
340
|
+
/**
|
|
341
|
+
* FIFO data structure
|
|
342
|
+
*/
|
|
343
|
+
export declare class Queue<T> implements ILinearStorage<T> {
|
|
344
|
+
private readonly _list;
|
|
345
|
+
/**
|
|
346
|
+
* Create a queue instance
|
|
347
|
+
*/
|
|
348
|
+
constructor(capacity?: number);
|
|
349
|
+
/**
|
|
350
|
+
* Get first element in queue (without deleting)
|
|
351
|
+
* @throws {CollectionIsEmptyException} when list is empty
|
|
352
|
+
*/
|
|
353
|
+
peek(): T;
|
|
354
|
+
/**
|
|
355
|
+
* Add element to queue
|
|
356
|
+
* @throws {CollectionIsFullException} when list is full
|
|
357
|
+
*/
|
|
358
|
+
push(item: T): void;
|
|
359
|
+
/**
|
|
360
|
+
* Delete first element in queue
|
|
361
|
+
* @throws {CollectionIsEmptyException} when list is empty
|
|
362
|
+
*/
|
|
363
|
+
pop(): T;
|
|
364
|
+
/**
|
|
365
|
+
* Check if element exists in list
|
|
366
|
+
*/
|
|
367
|
+
has(item: T): boolean;
|
|
368
|
+
/**
|
|
369
|
+
* Is queue empty
|
|
370
|
+
*/
|
|
371
|
+
isEmpty(): boolean;
|
|
372
|
+
/**
|
|
373
|
+
* Is stack full
|
|
374
|
+
*/
|
|
375
|
+
isFull(): boolean;
|
|
376
|
+
/**
|
|
377
|
+
* Remove all elements in queue
|
|
378
|
+
*/
|
|
379
|
+
clear(): void;
|
|
380
|
+
/**
|
|
381
|
+
* Queue length
|
|
382
|
+
*/
|
|
383
|
+
length(): number;
|
|
384
|
+
/**
|
|
385
|
+
* Reverse queue
|
|
386
|
+
*/
|
|
387
|
+
reverse(): void;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* LIFO data structure
|
|
391
|
+
*/
|
|
392
|
+
export declare class Stack<T> implements ILinearStorage<T> {
|
|
393
|
+
private readonly _list;
|
|
394
|
+
/**
|
|
395
|
+
* Create a stack instance
|
|
396
|
+
*/
|
|
397
|
+
constructor(capacity?: number);
|
|
398
|
+
/**
|
|
399
|
+
* Get stack top element
|
|
400
|
+
* @throws {CollectionIsEmptyException} when list is empty
|
|
401
|
+
*/
|
|
402
|
+
peek(): T;
|
|
403
|
+
/**
|
|
404
|
+
* Add element to stack head
|
|
405
|
+
* @throws {CollectionIsFullException} when list is full
|
|
406
|
+
*/
|
|
407
|
+
push(item: T): void;
|
|
408
|
+
/**
|
|
409
|
+
* Remove element from stack head
|
|
410
|
+
* @throws {CollectionIsEmptyException} when list is empty
|
|
411
|
+
*/
|
|
412
|
+
pop(): T;
|
|
413
|
+
/**
|
|
414
|
+
* Check if element exists in list
|
|
415
|
+
*/
|
|
416
|
+
has(item: T): boolean;
|
|
417
|
+
/**
|
|
418
|
+
* Is stack empty
|
|
419
|
+
*/
|
|
420
|
+
isEmpty(): boolean;
|
|
421
|
+
/**
|
|
422
|
+
* Is stack full
|
|
423
|
+
*/
|
|
424
|
+
isFull(): boolean;
|
|
425
|
+
/**
|
|
426
|
+
* Remove all elements in stack
|
|
427
|
+
*/
|
|
428
|
+
clear(): void;
|
|
429
|
+
/**
|
|
430
|
+
* Queue length
|
|
431
|
+
*/
|
|
432
|
+
length(): number;
|
|
433
|
+
/**
|
|
434
|
+
* Reverse stack
|
|
435
|
+
*/
|
|
436
|
+
reverse(): void;
|
|
437
|
+
}
|
|
438
|
+
declare class GraphEdge<T> {
|
|
439
|
+
private readonly _fromVertex;
|
|
440
|
+
private readonly _toVertex;
|
|
441
|
+
private _weight;
|
|
442
|
+
/**
|
|
443
|
+
* Create instance with linked "from" and "to" vertices
|
|
444
|
+
*/
|
|
445
|
+
constructor(fromVertex: T, toVertex: T, weight?: number);
|
|
446
|
+
get fromVertex(): T;
|
|
447
|
+
get toVertex(): T;
|
|
448
|
+
get weight(): number;
|
|
449
|
+
set weight(value: number);
|
|
450
|
+
}
|
|
451
|
+
declare abstract class AbstractGraph<T> {
|
|
452
|
+
protected _vertices: Map<T, Array<T>>;
|
|
453
|
+
protected _edges: Array<GraphEdge<T>>;
|
|
454
|
+
/**
|
|
455
|
+
* Created empty instance
|
|
456
|
+
*/
|
|
457
|
+
protected constructor();
|
|
458
|
+
/**
|
|
459
|
+
* Find edge by its from and to vertices
|
|
460
|
+
*/
|
|
461
|
+
protected abstract getEdgeByValue(from: T, to: T): GraphEdge<T>;
|
|
462
|
+
/**
|
|
463
|
+
* Get vertices list in array format
|
|
464
|
+
*/
|
|
465
|
+
protected getVerticesArrayFormat(): Array<T>;
|
|
466
|
+
/**
|
|
467
|
+
* Find vertex in vertices list by its data
|
|
468
|
+
* @throws {IsNotFoundException} when vertex was not found
|
|
469
|
+
*/
|
|
470
|
+
protected tryFindVertex(data: T): T;
|
|
471
|
+
/**
|
|
472
|
+
* Update edge weight between from and to vertices
|
|
473
|
+
*/
|
|
474
|
+
protected updateEdgeWeight(from: T, to: T, weight: number): void;
|
|
475
|
+
/**
|
|
476
|
+
* Will remove all vertex relations with others vertices
|
|
477
|
+
*/
|
|
478
|
+
protected cascadeRemoveVertexRelations(vertexToRemove: T): void;
|
|
479
|
+
/**
|
|
480
|
+
* Will remove all vertices edges with vertex to remove
|
|
481
|
+
*/
|
|
482
|
+
protected cascadeRemoveVertexEdges(vertexToRemove: T): void;
|
|
483
|
+
/**
|
|
484
|
+
* Get sum of all graph edges
|
|
485
|
+
*/
|
|
486
|
+
weight(): number;
|
|
487
|
+
/**
|
|
488
|
+
* Get array of vertices
|
|
489
|
+
*/
|
|
490
|
+
vertices(): Array<T>;
|
|
491
|
+
/**
|
|
492
|
+
* Get vertices count
|
|
493
|
+
*/
|
|
494
|
+
verticesCount(): number;
|
|
495
|
+
/**
|
|
496
|
+
* Get edges count
|
|
497
|
+
*/
|
|
498
|
+
edgesCount(): number;
|
|
499
|
+
/**
|
|
500
|
+
* Add vertex
|
|
501
|
+
* @throws {IsAlreadyExistsException} when vertex is already exists
|
|
502
|
+
*/
|
|
503
|
+
addVertex(data: T): this;
|
|
504
|
+
/**
|
|
505
|
+
* Remove vertex
|
|
506
|
+
* @throws {IsNotFoundException} when vertex is already does not exist
|
|
507
|
+
*/
|
|
508
|
+
removeVertex(data: T): this;
|
|
509
|
+
/**
|
|
510
|
+
* Add edge between two vertices
|
|
511
|
+
*/
|
|
512
|
+
abstract addEdge(from: T, to: T, weight?: number): this;
|
|
513
|
+
/**
|
|
514
|
+
* Remove edge between two vertices
|
|
515
|
+
*/
|
|
516
|
+
abstract removeEdge(from: T, to: T): this;
|
|
517
|
+
/**
|
|
518
|
+
* Get vertex neighbors by its data
|
|
519
|
+
*/
|
|
520
|
+
getVertexNeighbors(data: T): Array<T>;
|
|
521
|
+
/**
|
|
522
|
+
* Check if graph has vertex
|
|
523
|
+
*/
|
|
524
|
+
hasVertex(data: T): boolean;
|
|
525
|
+
/**
|
|
526
|
+
* Check if graph has edge between from and to vertices
|
|
527
|
+
*/
|
|
528
|
+
hasEdge(from: T, to: T): boolean;
|
|
529
|
+
/**
|
|
530
|
+
* Get edge weight between from and to vertices
|
|
531
|
+
*/
|
|
532
|
+
getEdgeWeight(from: T, to: T): number;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Undirected graph - data structure where edges with same pair of vertices are equal
|
|
536
|
+
* @example A-B is same as B-A
|
|
537
|
+
*/
|
|
538
|
+
export declare class UndirectedGraph<T> extends AbstractGraph<T> {
|
|
539
|
+
/**
|
|
540
|
+
* @inheritDoc
|
|
541
|
+
*/
|
|
542
|
+
constructor();
|
|
543
|
+
/**
|
|
544
|
+
* @inheritDoc
|
|
545
|
+
* @throws {IsNotFoundException} when vertex was not found
|
|
546
|
+
*/
|
|
547
|
+
protected getEdgeByValue(from: T, to: T): GraphEdge<T>;
|
|
548
|
+
/**
|
|
549
|
+
* @inheritDoc
|
|
550
|
+
*/
|
|
551
|
+
hasEdge(from: T, to: T): boolean;
|
|
552
|
+
/**
|
|
553
|
+
* @inheritDoc
|
|
554
|
+
* @throws {IsNotFoundException} when vertex was not found
|
|
555
|
+
*/
|
|
556
|
+
addEdge(from: T, to: T, weight?: number): this;
|
|
557
|
+
/**
|
|
558
|
+
* @inheritDoc
|
|
559
|
+
* @throws {IsNotFoundException} when vertex was not found
|
|
560
|
+
*/
|
|
561
|
+
removeEdge(from: T, to: T): this;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Directed graph - data structure where edges with same pair of vertices are not equal
|
|
565
|
+
* @example A-B is not the same as B-A
|
|
566
|
+
*/
|
|
567
|
+
export declare class DirectedGraph<T> extends AbstractGraph<T> {
|
|
568
|
+
/**
|
|
569
|
+
* @inheritDoc
|
|
570
|
+
*/
|
|
571
|
+
constructor();
|
|
572
|
+
/**
|
|
573
|
+
* @inheritDoc
|
|
574
|
+
* @throws {IsNotFoundException} when vertex was not found
|
|
575
|
+
*/
|
|
576
|
+
protected getEdgeByValue(from: T, to: T): GraphEdge<T>;
|
|
577
|
+
/**
|
|
578
|
+
* @inheritDoc
|
|
579
|
+
* @throws {IsNotFoundException} when vertex was not found
|
|
580
|
+
*/
|
|
581
|
+
addEdge(from: T, to: T, weight?: number): this;
|
|
582
|
+
/**
|
|
583
|
+
* @inheritDoc
|
|
584
|
+
* @throws {IsNotFoundException} when vertex was not found
|
|
585
|
+
*/
|
|
586
|
+
removeEdge(from: T, to: T): this;
|
|
587
|
+
}
|
|
588
|
+
export type FnCompareTwo<T> = (firstItem: T, secondItem: T) => boolean;
|
|
589
|
+
declare abstract class AbstractBinaryNode<T> {
|
|
590
|
+
protected _data: T;
|
|
591
|
+
protected _left: AbstractBinaryNode<T> | null;
|
|
592
|
+
protected _right: AbstractBinaryNode<T> | null;
|
|
593
|
+
protected _parent: AbstractBinaryNode<T> | null;
|
|
594
|
+
protected constructor(initialData: T);
|
|
595
|
+
get data(): T;
|
|
596
|
+
set data(value: T);
|
|
597
|
+
get left(): AbstractBinaryNode<T> | null;
|
|
598
|
+
set left(value: AbstractBinaryNode<T> | null);
|
|
599
|
+
get right(): AbstractBinaryNode<T> | null;
|
|
600
|
+
set right(value: AbstractBinaryNode<T> | null);
|
|
601
|
+
get parent(): AbstractBinaryNode<T> | null;
|
|
602
|
+
set parent(value: AbstractBinaryNode<T> | null);
|
|
603
|
+
}
|
|
604
|
+
declare abstract class AbstractBinaryTree<T> implements IBinaryTree<T> {
|
|
605
|
+
/**
|
|
606
|
+
* Function that checks is node A better
|
|
607
|
+
* @default a > b
|
|
608
|
+
* @example 5 > 4
|
|
609
|
+
* @example 'abc' > 'aba'
|
|
610
|
+
*/
|
|
611
|
+
protected compare: FnCompareTwo<T>;
|
|
612
|
+
protected _head: AbstractBinaryNode<T> | null;
|
|
613
|
+
protected _length: number;
|
|
614
|
+
/**
|
|
615
|
+
*
|
|
616
|
+
* @param fnCompare
|
|
617
|
+
* @protected
|
|
618
|
+
*/
|
|
619
|
+
protected constructor(fnCompare?: FnCompareTwo<T>);
|
|
620
|
+
/**
|
|
621
|
+
* Returns nodes count in the entire tree
|
|
622
|
+
*/
|
|
623
|
+
length(): number;
|
|
624
|
+
/**
|
|
625
|
+
* Will create new node and place it according to the type of tree rules
|
|
626
|
+
*/
|
|
627
|
+
abstract insert(value: T): void;
|
|
628
|
+
/**
|
|
629
|
+
* Will check if tree has a node with given data
|
|
630
|
+
*/
|
|
631
|
+
abstract has(value: T): boolean;
|
|
632
|
+
/**
|
|
633
|
+
* Will delete node from the tree and restructure it
|
|
634
|
+
*/
|
|
635
|
+
abstract delete(value: T): void;
|
|
636
|
+
/**
|
|
637
|
+
* Max value of the tree
|
|
638
|
+
*/
|
|
639
|
+
abstract max(): T;
|
|
640
|
+
/**
|
|
641
|
+
* Min value of the tree
|
|
642
|
+
*/
|
|
643
|
+
abstract min(): T;
|
|
644
|
+
/**
|
|
645
|
+
* Returns same class instance with new head node
|
|
646
|
+
*/
|
|
647
|
+
abstract subtree(value: T): IBinaryTree<T>;
|
|
648
|
+
/**
|
|
649
|
+
* Returns the highest branch length in the tree
|
|
650
|
+
*/
|
|
651
|
+
abstract height(): number;
|
|
652
|
+
/**
|
|
653
|
+
* In-order/Pre-order/Post-order traversing of the tree
|
|
654
|
+
*/
|
|
655
|
+
abstract traverse(type: EnumTreeTraversalType): Array<T>;
|
|
656
|
+
}
|
|
657
|
+
declare class BinarySearchNode<T> extends AbstractBinaryNode<T> {
|
|
658
|
+
protected _left: BinarySearchNode<T> | null;
|
|
659
|
+
protected _right: BinarySearchNode<T> | null;
|
|
660
|
+
protected _parent: BinarySearchNode<T> | null;
|
|
661
|
+
constructor(initialData: T);
|
|
662
|
+
get left(): BinarySearchNode<T> | null;
|
|
663
|
+
set left(value: BinarySearchNode<T> | null);
|
|
664
|
+
get right(): BinarySearchNode<T> | null;
|
|
665
|
+
set right(value: BinarySearchNode<T> | null);
|
|
666
|
+
get parent(): BinarySearchNode<T> | null;
|
|
667
|
+
set parent(value: BinarySearchNode<T> | null);
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Unbalanced binary search tree implementation
|
|
671
|
+
*/
|
|
672
|
+
export declare class BinarySearchTree<T> extends AbstractBinaryTree<T> {
|
|
673
|
+
/**
|
|
674
|
+
* Override types
|
|
675
|
+
*/
|
|
676
|
+
protected _head: BinarySearchNode<T> | null;
|
|
677
|
+
/**
|
|
678
|
+
* @inheritDoc
|
|
679
|
+
*/
|
|
680
|
+
constructor(fnCompare?: FnCompareTwo<T>);
|
|
681
|
+
/**
|
|
682
|
+
*
|
|
683
|
+
* @throws {CollectionIsEmptyException} when tree is empty
|
|
684
|
+
*/
|
|
685
|
+
protected checkIsEmpty(): void;
|
|
686
|
+
/**
|
|
687
|
+
* Will update left and right links parent with current node
|
|
688
|
+
*/
|
|
689
|
+
protected updateLeftRightParents(node: BinarySearchNode<T>): void;
|
|
690
|
+
/**
|
|
691
|
+
* Will return node instance by its data
|
|
692
|
+
*/
|
|
693
|
+
protected findNode(value: T): BinarySearchNode<T> | null;
|
|
694
|
+
/**
|
|
695
|
+
* @inheritDoc
|
|
696
|
+
*/
|
|
697
|
+
protected insertToLeaf(createdNode: BinarySearchNode<T>): void;
|
|
698
|
+
/**
|
|
699
|
+
* Will join two trees into one */
|
|
700
|
+
protected join(treeLeft: BinarySearchNode<T> | null, treeRight: BinarySearchNode<T> | null): BinarySearchNode<T> | null;
|
|
701
|
+
/**
|
|
702
|
+
* @inheritDoc
|
|
703
|
+
* @throws {CollectionIsEmptyException} when tree is empty
|
|
704
|
+
*/
|
|
705
|
+
max(): T;
|
|
706
|
+
/**
|
|
707
|
+
* @inheritDoc
|
|
708
|
+
* @throws {CollectionIsEmptyException} when tree is empty
|
|
709
|
+
*/
|
|
710
|
+
min(): T;
|
|
711
|
+
/**
|
|
712
|
+
* @inheritDoc
|
|
713
|
+
* @throws {IsAlreadyExistsException} when node already exists
|
|
714
|
+
*/
|
|
715
|
+
insert(value: T): void;
|
|
716
|
+
/**
|
|
717
|
+
* @inheritDoc
|
|
718
|
+
*/
|
|
719
|
+
has(value: T): boolean;
|
|
720
|
+
/**
|
|
721
|
+
* @inheritDoc
|
|
722
|
+
* @throws {IsNotFoundException} when node was not found
|
|
723
|
+
*/
|
|
724
|
+
delete(value: T): void;
|
|
725
|
+
/**
|
|
726
|
+
* @inheritDoc
|
|
727
|
+
*/
|
|
728
|
+
subtree(value: T): IBinaryTree<T>;
|
|
729
|
+
/**
|
|
730
|
+
* @inheritDoc
|
|
731
|
+
* @throws {CollectionIsEmptyException} when tree is empty
|
|
732
|
+
*/
|
|
733
|
+
traverse(type: EnumTreeTraversalType, from?: T): Array<T>;
|
|
734
|
+
/**
|
|
735
|
+
* Calc max height of the largest branch of the tree
|
|
736
|
+
*/
|
|
737
|
+
height(): number;
|
|
738
|
+
}
|
|
739
|
+
declare class RandBinarySearchNode<T> extends BinarySearchNode<T> {
|
|
740
|
+
private _rank;
|
|
741
|
+
protected _left: RandBinarySearchNode<T> | null;
|
|
742
|
+
protected _right: RandBinarySearchNode<T> | null;
|
|
743
|
+
protected _parent: RandBinarySearchNode<T> | null;
|
|
744
|
+
constructor(initialData: T);
|
|
745
|
+
get rank(): number;
|
|
746
|
+
set rank(value: number);
|
|
747
|
+
get left(): RandBinarySearchNode<T> | null;
|
|
748
|
+
set left(value: RandBinarySearchNode<T> | null);
|
|
749
|
+
get right(): RandBinarySearchNode<T> | null;
|
|
750
|
+
set right(value: RandBinarySearchNode<T> | null);
|
|
751
|
+
get parent(): RandBinarySearchNode<T> | null;
|
|
752
|
+
set parent(value: RandBinarySearchNode<T> | null);
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Randomized binary search tree implementation
|
|
756
|
+
*/
|
|
757
|
+
export declare class RandBinarySearchTree<T> extends BinarySearchTree<T> {
|
|
758
|
+
/**
|
|
759
|
+
* Override types
|
|
760
|
+
*/
|
|
761
|
+
protected _head: RandBinarySearchNode<T> | null;
|
|
762
|
+
/**
|
|
763
|
+
* @inheritDoc
|
|
764
|
+
*/
|
|
765
|
+
constructor(fnCompare?: FnCompareTwo<T>);
|
|
766
|
+
/**
|
|
767
|
+
* Will update node rank by summing left and right subtrees tanks and itself rank (1)
|
|
768
|
+
*/
|
|
769
|
+
private updateRank;
|
|
770
|
+
/**
|
|
771
|
+
* Will set rank and parent attributes and update tree length
|
|
772
|
+
*/
|
|
773
|
+
private addCreatedNode;
|
|
774
|
+
/**
|
|
775
|
+
* Will rotate node to the right side
|
|
776
|
+
*/
|
|
777
|
+
private rotateNodeRight;
|
|
778
|
+
/**
|
|
779
|
+
* Will rotate node to the left side
|
|
780
|
+
*/
|
|
781
|
+
private rotateNodeLeft;
|
|
782
|
+
/**
|
|
783
|
+
* @inheritDoc
|
|
784
|
+
*/
|
|
785
|
+
protected join(treeLeft: RandBinarySearchNode<T> | null, treeRight: RandBinarySearchNode<T> | null): RandBinarySearchNode<T> | null;
|
|
786
|
+
/**
|
|
787
|
+
* @inheritDoc
|
|
788
|
+
*/
|
|
789
|
+
protected updateLeftRightParents(node: RandBinarySearchNode<T>): void;
|
|
790
|
+
/**
|
|
791
|
+
* @inheritDoc
|
|
792
|
+
*/
|
|
793
|
+
protected insertToRoot(createdNode: RandBinarySearchNode<T>, fromNode?: RandBinarySearchNode<T>): void;
|
|
794
|
+
/**
|
|
795
|
+
* @inheritDoc
|
|
796
|
+
*/
|
|
797
|
+
protected insertRandomly(createdNode: RandBinarySearchNode<T>): void;
|
|
798
|
+
/**
|
|
799
|
+
* @inheritDoc
|
|
800
|
+
* @throws {IsAlreadyExistsException} when node already exists
|
|
801
|
+
*/
|
|
802
|
+
insert(value: T): void;
|
|
803
|
+
/**
|
|
804
|
+
* @inheritDoc
|
|
805
|
+
*/
|
|
806
|
+
delete(value: T): void;
|
|
807
|
+
length(): number;
|
|
808
|
+
}
|
|
809
|
+
declare abstract class AbstractLinkedNode<T> {
|
|
810
|
+
protected _next: AbstractLinkedNode<T> | null;
|
|
811
|
+
protected readonly _data: T;
|
|
812
|
+
/**
|
|
813
|
+
* Will create empty node
|
|
814
|
+
*/
|
|
815
|
+
protected constructor(data: T, next?: AbstractLinkedNode<T> | null);
|
|
816
|
+
/**
|
|
817
|
+
* Get data of node
|
|
818
|
+
*/
|
|
819
|
+
get data(): T;
|
|
820
|
+
/**
|
|
821
|
+
* Get next node link
|
|
822
|
+
*/
|
|
823
|
+
get next(): AbstractLinkedNode<T> | null;
|
|
824
|
+
/**
|
|
825
|
+
* Set next node link
|
|
826
|
+
*/
|
|
827
|
+
set next(value: AbstractLinkedNode<T> | null);
|
|
828
|
+
}
|
|
829
|
+
declare abstract class AbstractLinkedList<T> implements ILinkedList<T> {
|
|
830
|
+
protected readonly _capacity: number;
|
|
831
|
+
protected _length: number;
|
|
832
|
+
protected _head: AbstractLinkedNode<T> | null;
|
|
833
|
+
protected _tail: AbstractLinkedNode<T> | null;
|
|
834
|
+
/**
|
|
835
|
+
* Create empty instance
|
|
836
|
+
*/
|
|
837
|
+
protected constructor(capacity?: number);
|
|
838
|
+
/**
|
|
839
|
+
* Will calculate real capacity value
|
|
840
|
+
* @throws {ValueOutOfRangeException} when capacity is out of range
|
|
841
|
+
*/
|
|
842
|
+
private static calculateCapacity;
|
|
843
|
+
/**
|
|
844
|
+
* Will insert node between nodeLeft and nodeRight
|
|
845
|
+
* @throws {CollectionIsFullException} when list is full
|
|
846
|
+
*/
|
|
847
|
+
private insertNodeBetweenTwoNodes;
|
|
848
|
+
/**
|
|
849
|
+
* Will remove the node from its neighbors nodes links
|
|
850
|
+
* @throws {CollectionIsEmptyException} when list is empty
|
|
851
|
+
*/
|
|
852
|
+
private deleteNode;
|
|
853
|
+
/**
|
|
854
|
+
* Will find node by its index
|
|
855
|
+
* @throws {CollectionIsEmptyException} when list is empty
|
|
856
|
+
* @throws {IndexOutOfBoundsException} when given index is out of range
|
|
857
|
+
*/
|
|
858
|
+
protected getNodeByIndex(index: number): AbstractLinkedNode<T>;
|
|
859
|
+
/**
|
|
860
|
+
* Will set links between target, left and right siblings
|
|
861
|
+
*/
|
|
862
|
+
protected abstract insertNodeBetweenTwoNodesImpl(nodeToPush: AbstractLinkedNode<T>, nodeLeft: AbstractLinkedNode<T>, nodeRight: AbstractLinkedNode<T>): void;
|
|
863
|
+
/**
|
|
864
|
+
* Will unset itself links and its neighbors links
|
|
865
|
+
*/
|
|
866
|
+
protected abstract deleteNodeImpl(node: AbstractLinkedNode<T>): void;
|
|
867
|
+
/**
|
|
868
|
+
* Update head link
|
|
869
|
+
*/
|
|
870
|
+
protected abstract popImpl(): void;
|
|
871
|
+
/**
|
|
872
|
+
* Update tail link
|
|
873
|
+
*/
|
|
874
|
+
protected abstract shiftImpl(): void;
|
|
875
|
+
/**
|
|
876
|
+
* Will create empty node instance
|
|
877
|
+
*/
|
|
878
|
+
protected abstract createNode(value: T): AbstractLinkedNode<T>;
|
|
879
|
+
/**
|
|
880
|
+
* Push into start
|
|
881
|
+
* @throws {CollectionIsFullException} when there is no space available
|
|
882
|
+
*/
|
|
883
|
+
unshift(value: T): void;
|
|
884
|
+
/**
|
|
885
|
+
* Push into end
|
|
886
|
+
* @throws {CollectionIsFullException} when there is no space available
|
|
887
|
+
*/
|
|
888
|
+
push(value: T): void;
|
|
889
|
+
/**
|
|
890
|
+
* Push from index
|
|
891
|
+
* @throws {IndexOutOfBoundsException} when given index is out of range
|
|
892
|
+
* @throws {CollectionIsFullException} when there is no space available
|
|
893
|
+
*/
|
|
894
|
+
pushFromIndex(value: T, fromIndex: number): void;
|
|
895
|
+
/**
|
|
896
|
+
* Delete node from list's end
|
|
897
|
+
* @throws {CollectionIsEmptyException} when list is empty
|
|
898
|
+
*/
|
|
899
|
+
pop(): T;
|
|
900
|
+
/**
|
|
901
|
+
* Delete node from list's start and get its data
|
|
902
|
+
* @throws {CollectionIsEmptyException} when list is empty
|
|
903
|
+
*/
|
|
904
|
+
shift(): T;
|
|
905
|
+
/**
|
|
906
|
+
* Delete node from list by index from start
|
|
907
|
+
* @throws {CollectionIsEmptyException} when list is empty
|
|
908
|
+
*/
|
|
909
|
+
deleteFromIndex(fromIndex: number): T;
|
|
910
|
+
/**
|
|
911
|
+
* List length
|
|
912
|
+
*/
|
|
913
|
+
length(): number;
|
|
914
|
+
/**
|
|
915
|
+
* Is list empty
|
|
916
|
+
*/
|
|
917
|
+
isEmpty(): boolean;
|
|
918
|
+
/**
|
|
919
|
+
* Is list full
|
|
920
|
+
*/
|
|
921
|
+
isFull(): boolean;
|
|
922
|
+
/**
|
|
923
|
+
* Check if element exists in list
|
|
924
|
+
*/
|
|
925
|
+
has(item: T): boolean;
|
|
926
|
+
/**
|
|
927
|
+
* Get head element data
|
|
928
|
+
* @throws {CollectionIsEmptyException} when head does not exist
|
|
929
|
+
*/
|
|
930
|
+
peek(): T;
|
|
931
|
+
/**
|
|
932
|
+
* Get tail element data
|
|
933
|
+
* @throws {CollectionIsEmptyException} when tail does not exists
|
|
934
|
+
*/
|
|
935
|
+
peekFromStart(): T;
|
|
936
|
+
/**
|
|
937
|
+
* Get list element by index from start
|
|
938
|
+
* @throws {CollectionIsEmptyException} when list is empty
|
|
939
|
+
* @throws {IndexOutOfBoundsException} when given index is out of range
|
|
940
|
+
*/
|
|
941
|
+
peekByIndex(index: number): T;
|
|
942
|
+
/**
|
|
943
|
+
* Remove all elements from list
|
|
944
|
+
*/
|
|
945
|
+
clear(): void;
|
|
946
|
+
/**
|
|
947
|
+
* Get elements as an array
|
|
948
|
+
*/
|
|
949
|
+
getAsArray(): Array<T>;
|
|
950
|
+
/**
|
|
951
|
+
* Add elements to list from array
|
|
952
|
+
* @throws {CollectionIsFullException} when list is full
|
|
953
|
+
* */
|
|
954
|
+
pushFromArray(elements: Array<T>): void;
|
|
955
|
+
/**
|
|
956
|
+
* Reverse list nodes links and swap head with tail
|
|
957
|
+
* @example "4>7>10" will be reversed to "10>7>4"
|
|
958
|
+
*/
|
|
959
|
+
abstract reverse(): void;
|
|
960
|
+
}
|
|
961
|
+
declare class DoubleLinkedNode<T> extends AbstractLinkedNode<T> {
|
|
962
|
+
protected _prev: DoubleLinkedNode<T> | null;
|
|
963
|
+
protected _next: DoubleLinkedNode<T> | null;
|
|
964
|
+
/**
|
|
965
|
+
* Will create empty node
|
|
966
|
+
*/
|
|
967
|
+
constructor(data: T, next?: DoubleLinkedNode<T> | null, prev?: DoubleLinkedNode<T> | null);
|
|
968
|
+
/**
|
|
969
|
+
* Set previous node link
|
|
970
|
+
*/
|
|
971
|
+
set prev(value: DoubleLinkedNode<T> | null);
|
|
972
|
+
/**
|
|
973
|
+
* Get previous node link
|
|
974
|
+
*/
|
|
975
|
+
get prev(): DoubleLinkedNode<T> | null;
|
|
976
|
+
/**
|
|
977
|
+
* @inheritDoc
|
|
978
|
+
*/
|
|
979
|
+
set next(value: DoubleLinkedNode<T> | null);
|
|
980
|
+
/**
|
|
981
|
+
* @inheritDoc
|
|
982
|
+
*/
|
|
983
|
+
get next(): DoubleLinkedNode<T> | null;
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Linear data structure
|
|
987
|
+
* Each node has next and prev sibling
|
|
988
|
+
* Head and tail are linked to each other
|
|
989
|
+
*/
|
|
990
|
+
export declare class DoubleLinkedList<T> extends AbstractLinkedList<T> {
|
|
991
|
+
/**
|
|
992
|
+
* Override types
|
|
993
|
+
*/
|
|
994
|
+
protected _head: DoubleLinkedNode<T> | null;
|
|
995
|
+
protected _tail: DoubleLinkedNode<T> | null;
|
|
996
|
+
/**
|
|
997
|
+
* @inheritDoc
|
|
998
|
+
*/
|
|
999
|
+
constructor(capacity?: number);
|
|
1000
|
+
/**
|
|
1001
|
+
* @inheritDoc
|
|
1002
|
+
*/
|
|
1003
|
+
protected createNode(value: T): DoubleLinkedNode<T>;
|
|
1004
|
+
/**
|
|
1005
|
+
* @inheritDoc
|
|
1006
|
+
*/
|
|
1007
|
+
protected insertNodeBetweenTwoNodesImpl(targetNode: DoubleLinkedNode<T>, leftNode: DoubleLinkedNode<T>, rightNode: DoubleLinkedNode<T>): void;
|
|
1008
|
+
/**
|
|
1009
|
+
* @inheritDoc
|
|
1010
|
+
*/
|
|
1011
|
+
protected deleteNodeImpl(node: DoubleLinkedNode<T>): void;
|
|
1012
|
+
/**
|
|
1013
|
+
* @inheritDoc
|
|
1014
|
+
*/
|
|
1015
|
+
protected popImpl(): void;
|
|
1016
|
+
/**
|
|
1017
|
+
* @inheritDoc
|
|
1018
|
+
*/
|
|
1019
|
+
protected shiftImpl(): void;
|
|
1020
|
+
/**
|
|
1021
|
+
* @inheritDoc
|
|
1022
|
+
*/
|
|
1023
|
+
reverse(): void;
|
|
1024
|
+
}
|
|
1025
|
+
export interface IIterable<T> {
|
|
1026
|
+
iterator(fromIndex?: number): IIterator<T>;
|
|
1027
|
+
}
|
|
1028
|
+
declare class SingleLinkedNode<T> extends AbstractLinkedNode<T> {
|
|
1029
|
+
/**
|
|
1030
|
+
* @inheritDoc
|
|
1031
|
+
*/
|
|
1032
|
+
constructor(data: T, next?: SingleLinkedNode<T> | null);
|
|
1033
|
+
}
|
|
1034
|
+
/**
|
|
1035
|
+
* Linear data structure
|
|
1036
|
+
* Each node has next
|
|
1037
|
+
* Head's next node is tail
|
|
1038
|
+
*/
|
|
1039
|
+
export declare class SingleLinkedList<T> extends AbstractLinkedList<T> {
|
|
1040
|
+
/**
|
|
1041
|
+
* Override types
|
|
1042
|
+
*/
|
|
1043
|
+
protected _head: SingleLinkedNode<T> | null;
|
|
1044
|
+
protected _tail: SingleLinkedNode<T> | null;
|
|
1045
|
+
/**
|
|
1046
|
+
* @inheritDoc
|
|
1047
|
+
*/
|
|
1048
|
+
constructor(capacity?: number);
|
|
1049
|
+
/**
|
|
1050
|
+
* Find previous sibling of given node
|
|
1051
|
+
*/
|
|
1052
|
+
private getPrevNode;
|
|
1053
|
+
/**
|
|
1054
|
+
* @inheritDoc
|
|
1055
|
+
*/
|
|
1056
|
+
protected createNode(value: T): SingleLinkedNode<T>;
|
|
1057
|
+
/**
|
|
1058
|
+
* @inheritDoc
|
|
1059
|
+
*/
|
|
1060
|
+
protected insertNodeBetweenTwoNodesImpl(targetNode: SingleLinkedNode<T>, leftNode: SingleLinkedNode<T>, rightNode: SingleLinkedNode<T>): void;
|
|
1061
|
+
/**
|
|
1062
|
+
* @inheritDoc
|
|
1063
|
+
*/
|
|
1064
|
+
protected deleteNodeImpl(node: SingleLinkedNode<T>): void;
|
|
1065
|
+
/**
|
|
1066
|
+
* @inheritDoc
|
|
1067
|
+
*/
|
|
1068
|
+
protected popImpl(): void;
|
|
1069
|
+
/**
|
|
1070
|
+
* @inheritDoc
|
|
1071
|
+
*/
|
|
1072
|
+
protected shiftImpl(): void;
|
|
1073
|
+
/**
|
|
1074
|
+
* @inheritDoc
|
|
1075
|
+
*/
|
|
1076
|
+
reverse(): void;
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* @inheritDoc
|
|
1080
|
+
*/
|
|
1081
|
+
export declare class IterableSingleLinkedList<T> extends SingleLinkedList<T> implements IIterable<T> {
|
|
1082
|
+
/**
|
|
1083
|
+
* @inheritDoc
|
|
1084
|
+
*/
|
|
1085
|
+
constructor(capacity?: number);
|
|
1086
|
+
/**
|
|
1087
|
+
* List iterator
|
|
1088
|
+
* @throws {CollectionIsEmptyException} when list is empty
|
|
1089
|
+
* @throws {IndexOutOfBoundsException} when given index is out of range
|
|
1090
|
+
*/
|
|
1091
|
+
iterator(fromIndex?: number): IIterator<T>;
|
|
1092
|
+
}
|
|
1093
|
+
export interface IBiDirectIterator<T> extends IIterator<T> {
|
|
1094
|
+
/**
|
|
1095
|
+
* Will do one iteration back and returns prev item value
|
|
1096
|
+
*/
|
|
1097
|
+
prev(): T;
|
|
1098
|
+
/**
|
|
1099
|
+
* Check if next element exists
|
|
1100
|
+
*/
|
|
1101
|
+
hasPrev(): boolean;
|
|
1102
|
+
}
|
|
1103
|
+
export interface IBiDirectIterable<T> extends IIterable<T> {
|
|
1104
|
+
iterator(fromIndex?: number): IBiDirectIterator<T>;
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* @inheritDoc
|
|
1108
|
+
*/
|
|
1109
|
+
export declare class IterableDoubleLinkedList<T> extends DoubleLinkedList<T> implements IBiDirectIterable<T> {
|
|
1110
|
+
/**
|
|
1111
|
+
* @inheritDoc
|
|
1112
|
+
*/
|
|
1113
|
+
constructor(capacity?: number);
|
|
1114
|
+
/**
|
|
1115
|
+
* List iterator
|
|
1116
|
+
* @throws {CollectionIsEmptyException} when list is empty
|
|
1117
|
+
* @throws {IndexOutOfBoundsException} when given index is out of range
|
|
1118
|
+
*/
|
|
1119
|
+
iterator(fromIndex?: number): IBiDirectIterator<T>;
|
|
1120
|
+
}
|
|
1121
|
+
export declare class IllegalStateException extends Error {
|
|
1122
|
+
constructor(message: string);
|
|
1123
|
+
}
|
|
1124
|
+
export declare class IsNotFoundException extends IllegalStateException {
|
|
1125
|
+
constructor(message: string);
|
|
1126
|
+
}
|
|
1127
|
+
export declare class IsAlreadyExistsException extends IllegalStateException {
|
|
1128
|
+
constructor(message: string);
|
|
1129
|
+
}
|
|
1130
|
+
export declare class IllegalArgumentException extends Error {
|
|
1131
|
+
constructor(message: string);
|
|
1132
|
+
}
|
|
1133
|
+
export declare class ValueOutOfRangeException extends IllegalArgumentException {
|
|
1134
|
+
constructor(message: string);
|
|
1135
|
+
}
|
|
1136
|
+
export declare class IndexOutOfBoundsException extends IllegalArgumentException {
|
|
1137
|
+
constructor(message: string);
|
|
1138
|
+
}
|
|
1139
|
+
export declare class CollectionIsEmptyException extends IllegalStateException {
|
|
1140
|
+
constructor(message: string);
|
|
1141
|
+
}
|
|
1142
|
+
export declare class CollectionIsFullException extends IllegalStateException {
|
|
1143
|
+
constructor(message: string);
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* Bubble sorting algorithm
|
|
1147
|
+
*
|
|
1148
|
+
* @description
|
|
1149
|
+
* Time complexity: Best O(n); Avg O(n \^ 2); Worst O(n \^ 2)
|
|
1150
|
+
* @description
|
|
1151
|
+
* Memory complexity: Worst case: O(1)
|
|
1152
|
+
*/
|
|
1153
|
+
export declare const bubbleSort: (arr: Array<number>) => Array<number>;
|
|
1154
|
+
/**
|
|
1155
|
+
* Selection sorting algorithm
|
|
1156
|
+
*
|
|
1157
|
+
* @description
|
|
1158
|
+
* Time complexity: Best O(n \^ 2); Avg O(n \^ 2); Worst O(n \^ 2)
|
|
1159
|
+
* @description
|
|
1160
|
+
* Memory complexity: Worst case: O(1)
|
|
1161
|
+
*/
|
|
1162
|
+
export declare const selectSort: (arr: Array<number>) => Array<number>;
|
|
1163
|
+
/**
|
|
1164
|
+
* Merge sorting algorithm
|
|
1165
|
+
*
|
|
1166
|
+
* @description
|
|
1167
|
+
* Time complexity: Best O(n * log(n)); Avg O(n * log(n)); Worst O(n * log(n))
|
|
1168
|
+
* @description
|
|
1169
|
+
* Memory complexity: Worst case: O(n)
|
|
1170
|
+
*/
|
|
1171
|
+
export declare const mergeSort: (arr: Array<number>) => Array<number>;
|
|
1172
|
+
/**
|
|
1173
|
+
* Insertion sorting algorithm
|
|
1174
|
+
*
|
|
1175
|
+
* @description
|
|
1176
|
+
* Time complexity: Best O(n); Avg O(n \^ 2); Worst O(n \^ 2);
|
|
1177
|
+
* @description
|
|
1178
|
+
* Memory complexity: Worst case: O(1)
|
|
1179
|
+
*/
|
|
1180
|
+
export declare const insertionSort: (arr: Array<number>) => Array<number>;
|
|
1181
|
+
/**
|
|
1182
|
+
* Quick sort algorithm
|
|
1183
|
+
*
|
|
1184
|
+
* @description
|
|
1185
|
+
* Time complexity: Best O(n * log(n)); Avg O(n * log(n)); Worst O(n ^2)
|
|
1186
|
+
* @description
|
|
1187
|
+
* Memory complexity: Worst case: O(1)
|
|
1188
|
+
*/
|
|
1189
|
+
export declare const quickSort: (arr: Array<number>) => Array<number>;
|
|
1190
|
+
/**
|
|
1191
|
+
* Wrapper function that storing the results of calls and returning the cached result when the same inputs occur again
|
|
1192
|
+
*/
|
|
1193
|
+
export declare const memoize: <Key, Value>(fn: FnToMemoize<Key, Value>) => FnToMemoize<Key, Value>;
|
|
1194
|
+
/**
|
|
1195
|
+
* Will find min value in the whole array and return its index
|
|
1196
|
+
*/
|
|
1197
|
+
export declare const getMinIndex: (arr: Array<number>) => number;
|
|
1198
|
+
/**
|
|
1199
|
+
* Will find min value in range between fromIndex and end of array
|
|
1200
|
+
*/
|
|
1201
|
+
export declare const getMinIndexFromIndex: (arr: Array<number>, fromIndex: number) => number;
|
|
1202
|
+
/**
|
|
1203
|
+
* Will swap two items in array
|
|
1204
|
+
* @example swapArrayItems([2,3,5], 1, 2) -> [2,5,3]
|
|
1205
|
+
*/
|
|
1206
|
+
export declare const swapArrayItems: <T>(arr: Array<T>, leftIndex: number, rightIndex: number) => void;
|
|
1207
|
+
/**
|
|
1208
|
+
* Get random number in range
|
|
1209
|
+
*/
|
|
1210
|
+
export declare const randomizeNumberInRange: (min: number, max: number) => number;
|
|
1211
|
+
/**
|
|
1212
|
+
* Round number to given digits after
|
|
1213
|
+
*/
|
|
1214
|
+
export declare const roundNumber: (num: number, digits?: number) => number;
|
|
1215
|
+
|
|
1216
|
+
export {};
|