VehiclesFashionRecipesBlogsHuntTravelsSportFunHandmadeITEducation
Mini-Games
x

x
zakruti.com » IT - Software » freeCodeCamp.org
Binary Search Tree - Beau teaches JavaScript

Binary Search Tree - Beau teaches JavaScript

FBTwitterReddit

video description

Rating: 4.0; Vote: 1
A binary search tree is a tree data structure with only two branches for every node. Learn how to implement a binary search tree in JavaScript ES6! - Code: http://codepen.io/beaucarnes/pen/ryKvEQ?editors=0011 - Info: https://en.wikipedia.org/wiki/Binary_search_tree - Beau Carnes on
Date: 2022-03-14

Comments and reviews: 10


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

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

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

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

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

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

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

-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

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

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