Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3d48038

Browse files
committed
update: find min of BST
1 parent ac536a1 commit 3d48038

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

‎src/_DataStructures_/Trees/BST/index.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ class BinarySearchTree {
108108
return root;
109109
}
110110

111+
findMinNode(root) {
112+
/** The minnimum values is the let most leaf node in BST */
113+
if (root.leftChild === null) return root;
114+
return this.findMinNode(root.leftChild);
115+
}
116+
111117
isEmpty() {
112118
return this.root === null;
113119
}
@@ -134,6 +140,11 @@ class BinarySearchTree {
134140
return this.search(this.root, value);
135141
}
136142

143+
findMinimum() {
144+
const minNode = this.findMinNode(this.root);
145+
return minNode.value;
146+
}
147+
137148
remove(value) {
138149
return this.delete(this.root, value);
139150
}
@@ -162,8 +173,12 @@ class BinarySearchTree {
162173
// const search = 18;
163174
// console.log(`Search for ${search}`, bst.searchFor(search));
164175

176+
// const minNode = bst.findMinimum();
177+
// console.log('Minimum value =>', minNode);
178+
165179
// bst.remove(8);
166180
// console.log(bst.traversePreorder());
181+
// console.log(bst.root);
167182

168183
// bst.remove(5);
169184
// console.log(bst.traversePreorder());

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /