2023-08-23 15:03:19 +00:00
|
|
|
import {
|
2023-09-12 03:15:20 +00:00
|
|
|
AbstractBinaryTreeNodeProperties,
|
|
|
|
AbstractBinaryTreeNodeProperty,
|
|
|
|
BinaryTreeDeletedResult,
|
2023-10-10 11:55:52 +00:00
|
|
|
BinaryTreeNodeKey,
|
2023-09-12 03:15:20 +00:00
|
|
|
BinaryTreeNodePropertyName,
|
|
|
|
DFSOrderPattern,
|
|
|
|
FamilyPosition,
|
|
|
|
LoopType,
|
|
|
|
NodeOrPropertyName
|
2023-08-23 15:03:19 +00:00
|
|
|
} from '../types';
|
2023-09-22 02:43:16 +00:00
|
|
|
import {AbstractBinaryTreeNode} from '../data-structures';
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-08-29 12:29:53 +00:00
|
|
|
export interface IAbstractBinaryTreeNode<T, NEIGHBOR extends IAbstractBinaryTreeNode<T, NEIGHBOR>> {
|
2023-10-10 13:56:55 +00:00
|
|
|
key: BinaryTreeNodeKey;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 13:56:55 +00:00
|
|
|
val: T | undefined;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
get left(): NEIGHBOR | null | undefined;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
set left(v: NEIGHBOR | null | undefined);
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
get right(): NEIGHBOR | null | undefined;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
set right(v: NEIGHBOR | null | undefined);
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 13:56:55 +00:00
|
|
|
parent: NEIGHBOR | null | undefined;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
get familyPosition(): FamilyPosition;
|
2023-08-23 15:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N>> {
|
2023-10-10 11:55:52 +00:00
|
|
|
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N | null;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
get loopType(): LoopType;
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-10-10 11:55:52 +00:00
|
|
|
get visitedKey(): BinaryTreeNodeKey[];
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
get visitedVal(): Array<N['val']>;
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
get visitedNode(): N[];
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
get root(): N | null;
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
get size(): number;
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
swapLocation(srcNode: N, destNode: N): N;
|
2023-08-28 12:04:43 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
clear(): void;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
isEmpty(): boolean;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 11:55:52 +00:00
|
|
|
add(key: BinaryTreeNodeKey | N, val?: N['val']): N | null | undefined;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 14:39:31 +00:00
|
|
|
addMany(keysOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N['val'][]): (N | null | undefined)[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 14:39:31 +00:00
|
|
|
refill(keysOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N[] | Array<N['val']>): boolean;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 11:55:52 +00:00
|
|
|
remove(key: BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
getDepth(node: N): number;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
getHeight(beginRoot?: N | null): number;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
getMinHeight(beginRoot?: N | null): number;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
isPerfectlyBalanced(beginRoot?: N | null): boolean;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 11:55:52 +00:00
|
|
|
getNodes(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 11:55:52 +00:00
|
|
|
has(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): boolean;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 11:55:52 +00:00
|
|
|
get(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
getPathToRoot(node: N): N[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
getLeftMost(): N | null;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
getLeftMost(node: N): N;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
getLeftMost(node?: N | null): N | null;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
getRightMost(): N | null;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
getRightMost(node: N): N;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
getRightMost(node?: N | null): N | null;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
isSubtreeBST(node: N | null): boolean;
|
2023-08-23 16:01:44 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
isBST(): boolean;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
getSubTreeSize(subTreeRoot: N | null | undefined): number;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
// --- start additional methods ---
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 14:15:01 +00:00
|
|
|
bfs(): BinaryTreeNodeKey[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 14:15:01 +00:00
|
|
|
bfs(nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 14:15:01 +00:00
|
|
|
bfs(nodeOrPropertyName: 'val'): N['val'][];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 14:15:01 +00:00
|
|
|
bfs(nodeOrPropertyName: 'node'): N[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 14:15:01 +00:00
|
|
|
bfs(nodeOrPropertyName: 'count'): number[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 14:15:01 +00:00
|
|
|
bfs(nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 14:15:01 +00:00
|
|
|
dfs(): BinaryTreeNodeKey[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 14:15:01 +00:00
|
|
|
dfs(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 14:15:01 +00:00
|
|
|
dfs(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 14:15:01 +00:00
|
|
|
dfs(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 14:15:01 +00:00
|
|
|
dfs(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 14:15:01 +00:00
|
|
|
dfs(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 15:01:13 +00:00
|
|
|
dfsIterative(): BinaryTreeNodeKey[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-11 10:44:59 +00:00
|
|
|
dfsIterative(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-11 10:44:59 +00:00
|
|
|
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-11 10:44:59 +00:00
|
|
|
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N['val'][];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-11 10:44:59 +00:00
|
|
|
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-11 10:44:59 +00:00
|
|
|
dfsIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 11:55:52 +00:00
|
|
|
levelIterative(node: N | null): BinaryTreeNodeKey[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 11:55:52 +00:00
|
|
|
levelIterative(node: N | null, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
levelIterative(node: N | null, nodeOrPropertyName?: 'count'): number[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
levelIterative(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 11:55:52 +00:00
|
|
|
listLevels(node: N | null): BinaryTreeNodeKey[][];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 11:55:52 +00:00
|
|
|
listLevels(node: N | null, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[][];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
listLevels(node: N | null, nodeOrPropertyName?: 'count'): number[][];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
listLevels(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperty<N>[][];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
getPredecessor(node: N): N;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 11:55:52 +00:00
|
|
|
morris(): BinaryTreeNodeKey[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-10-10 11:55:52 +00:00
|
|
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-21 04:52:17 +00:00
|
|
|
morris(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
2023-08-23 15:03:19 +00:00
|
|
|
|
2023-09-12 03:15:20 +00:00
|
|
|
// --- end additional methods ---
|
|
|
|
}
|