
Binary Search Tree - Beau teaches JavaScript
video description
Date: 2022-03-14
Related videos
Comments and reviews: 10
xerxius
Very well explained !
Here is the shorter version of add function if anybody wants a terse code
add(data, node = this.root) --
if (this.root === null) this.root = new Node(data);-
else if (node === null) return new Node(data);-
else if (data === node.data) return; -
else if (data < node.data) node.left = this.add(data, node.left) -- node.left;-
else node.right = this.add(data, node.right) -- node.right;-
-
reply
Very well explained !
Here is the shorter version of add function if anybody wants a terse code
add(data, node = this.root) --
if (this.root === null) this.root = new Node(data);-
else if (node === null) return new Node(data);-
else if (data === node.data) return; -
else if (data < node.data) node.left = this.add(data, node.left) -- node.left;-
else node.right = this.add(data, node.right) -- node.right;-
-
reply
Jay
Cool. Another tip is to try and use while loops instead of recursion for better performance. One way to do this is to say while(node), check your cases, set the node equal to the left or right child. The while loop will terminate on null. This is done for the findMin, findMax functions but not for the add function. As an exercise, see if you can rewrite the add function using a while loop instead.
reply
Cool. Another tip is to try and use while loops instead of recursion for better performance. One way to do this is to say while(node), check your cases, set the node equal to the left or right child. The while loop will terminate on null. This is done for the findMin, findMax functions but not for the add function. As an exercise, see if you can rewrite the add function using a while loop instead.
reply
mo
Thanks for the upload, in my opinion, I think it could have been better and more clear if you built it from scratch while explaining step by step, coz I think a lot of people got a bit overwhelmed when they saw that bunch of code the first moment of the video. but thanks again anyway..
reply
Thanks for the upload, in my opinion, I think it could have been better and more clear if you built it from scratch while explaining step by step, coz I think a lot of people got a bit overwhelmed when they saw that bunch of code the first moment of the video. but thanks again anyway..
reply
Marshall
Can we all appreciate how well he went over this and well he tried to make sure that the depth of this was covered along with walking the viewer through a journey of creating a mental map and understanding of a BST.
reply
Can we all appreciate how well he went over this and well he tried to make sure that the depth of this was covered along with walking the viewer through a journey of creating a mental map and understanding of a BST.
reply
Mote
Is there something weird with the add function on the codepen link? It doesn't seem to have a closing bracket. Maybe it's just me but bst.add(10), for example returns null.
--Not sure why, but prob seems gone now.
reply
Is there something weird with the add function on the codepen link? It doesn't seem to have a closing bracket. Maybe it's just me but bst.add(10), for example returns null.
--Not sure why, but prob seems gone now.
reply
jumpman23nith
What if you want to remove a node but its right node doesn't have a left child? Which node will take the place of the node to be removed? Just wanted to confirm my guess.. It is going to be the right node?
reply
What if you want to remove a node but its right node doesn't have a left child? Which node will take the place of the node to be removed? Just wanted to confirm my guess.. It is going to be the right node?
reply
Mathias
The implementation example you showed just flicked on the switch! oh those wasted hours tearing my hair out, Why oh why didn't my instructors just give us a damned clear example??
reply
The implementation example you showed just flicked on the switch! oh those wasted hours tearing my hair out, Why oh why didn't my instructors just give us a damned clear example??
reply
Constantin
-if (node.left === null) - ... - else if (node.left !== null) -...-. We can remove the 2nd if statement.
I think that -if (!node.left) -...- else -...-- is more readable
reply
-if (node.left === null) - ... - else if (node.left !== null) -...-. We can remove the 2nd if statement.
I think that -if (!node.left) -...- else -...-- is more readable
reply
Amin
is there any way to donate to this guy? i mean i pay for shitty subscriptions already, it's nice knowing your money is going to someone who deserves it for once.
reply
is there any way to donate to this guy? i mean i pay for shitty subscriptions already, it's nice knowing your money is going to someone who deserves it for once.
reply
petrolhead88
You should provide exercises if you post only theory, it is almost useless.
Why you won't write some problems and publish it as a PDF?.
reply
You should provide exercises if you post only theory, it is almost useless.
Why you won't write some problems and publish it as a PDF?.
reply
Add a review, comment
Other channel videos















