File tree 1 file changed +15
-0
lines changed
src/_DataStructures_/Trees/BST
1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,12 @@ class BinarySearchTree {
108
108
return root ;
109
109
}
110
110
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
+
111
117
isEmpty ( ) {
112
118
return this . root === null ;
113
119
}
@@ -134,6 +140,11 @@ class BinarySearchTree {
134
140
return this . search ( this . root , value ) ;
135
141
}
136
142
143
+ findMinimum ( ) {
144
+ const minNode = this . findMinNode ( this . root ) ;
145
+ return minNode . value ;
146
+ }
147
+
137
148
remove ( value ) {
138
149
return this . delete ( this . root , value ) ;
139
150
}
@@ -162,8 +173,12 @@ class BinarySearchTree {
162
173
// const search = 18;
163
174
// console.log(`Search for ${search}`, bst.searchFor(search));
164
175
176
+ // const minNode = bst.findMinimum();
177
+ // console.log('Minimum value =>', minNode);
178
+
165
179
// bst.remove(8);
166
180
// console.log(bst.traversePreorder());
181
+ // console.log(bst.root);
167
182
168
183
// bst.remove(5);
169
184
// console.log(bst.traversePreorder());
You can’t perform that action at this time.
0 commit comments