Binary Tree Inorder Traversal | Leetcode | JavaScript

preview_player
Показать описание
Hey everyone, In this video we will understand Binary Tree Inorder Traversal.
We will also understand the Recursion Call Stack.

Do watch this video till end.
If this video was helpful, give it a thumbs up and subscribe to my channel for more such videos. 🔔

Other Video links -

Lazy Load Image -
Performance Optimisation -
Shopping Cart -

#binarytree #inorder #leetcode #javascript
Рекомендации по теме
Комментарии
Автор

Happy Independence Day everyone 🇮🇳
Don't forget to like share and subscribe 😊
Thank you for watching ✌
-AI

akashingole
Автор

thanks Akash sir You sloved my problem I'm really thanksful to you here
class Node {
constructor(value) {
this.value = value;
this.left = null;
this.right = null;
}
}
class Tree {
constructor() {
this.root = null;
}
isTreeEmpty() {
return this.root === null;
}
makeTree(value) {
let newNode = new Node(value);
if (this.root === null) {
this.root = newNode;
} else {
this.insertNode(this.root, newNode);
}
}
insertNode(root, newNode) {
if (root.value > newNode.value) {
if (root.left === null) {
root.left = newNode;
} else {
this.insertNode(root.left, newNode);
}
} else {
if (root.right === null) {
root.right = newNode;
} else {
this.insertNode(root.right, newNode);
}
}
}

searchnodetree(root, find){

if(root === null){
return false;
}else if(root.value === find){
return true;
}else if(root.value>find){
return this.searchnodetree(root.left, find);
}else{
return this.searchnodetree(root.right, find);
}
}

searchnodetree2(root, find){
if(root === null){
console.error("root not found...!");
}else if(root.value === find){
console.log("value found...", true);
}else if(root.value>find){
this.searchnodetree2(root.left, find);
}else{
this.searchnodetree2(root.right, find);
}
}

preOrder(root){
// console.info(root);
if(root !== null){
console.warn(root.value);
this.preOrder(root.left);
this.preOrder(root.right);
}
}
}

let bst = new Tree();

bst.makeTree(11);
bst.makeTree(9);
bst.makeTree(5);
bst.makeTree(10);
bst.makeTree(20);
bst.makeTree(12);
bst.makeTree(40);

bst.preOrder(bst.root);


I was not understanding that null case and you explained it very clearly


Sir if possible can you share me your contact number or if not not possible to sharing number can you just share me your insta so that I can ask question to you ??? in Dm

Palavi_s
Автор

a thorough explanation. Would you explain it in iterative way? Thank you!

tonyhuynh