the inner while loop has to break after assigning the element to the specified position, otherwise it will be an infinite loop without break. but i should say very well explained
@@armeenhossain665 While(1) means the condition is true and the loop will go on (infinite loop) until there is a break. In while(condition), condition is reduced down to either 0 or 1. 0 means false and 1 means true.
Hello Vivekanand! Thanks for the helpful video. If you have not already done so, can you make a video on how to construct an AVL tree as well as how to remove from and rebalance it in code? Again thank you very much and keep up the good work!
Once we attach a node to the left or right of its parent , we break from the loop..... It should be as follows:- while(1) { if(q->value value) { if(p->left == NULL) { p->left = q; break; ----------------------------------------------- // here is the break condition. } else p = p->left; } else if(q->value > p->value) { if(p->right == NULL) { p->right = q; break; --------------------------------------------------------------// here is the break condition } else p = p->right; } }
can you please modify the video with adding the break; statement. I was also wondering that how do we exit from the while loop then I read this comment ! Thank you !
How can I construct a binary search tree with the optimized depth to the minimum possible according to the number of nodes? I've made a algorithm to optimize this. I've tested with a random binary tree with 5000 nodes and as result I earned a depth of 15, but, by the math, the minimum depth should be 12.
Not possible. Duplicate values are not allowed in BST, because you cannot decide whether to make the duplicate value, the left child or the right child of the original value. That is why duplicate values are not allowed.
sir while(1) is an infinite loop and there is no any termination condition I think the inner while loop should have the condition like this while(q!=NULL) { if(q->valuevalue) { if(p->left==NULL) { p->left=q; q=NULL; } else{ p=p->left; } } else { if(p->right==NULL) { p->right=q; q=NULL; } else { p=p->right; } } }
yes you are right. and if you replace q=NULL in your code by "break ; " , it will be even better. Hey friend thanks for communicating. May at that time due to space constraint on board , i have not written that. Thanks a lot bro.
If anybody wondering where the break should be. It has to be just after the line(s) p->left = q and p-> right=q.
Thanks
God bless you
वेरी नाइस एक्सप्लानेशन... कीप इट अप !
the inner while loop has to break after assigning the element to the specified position, otherwise it will be an infinite loop without break. but i should say very well explained
Great one..very helpful for b.tech students
did you forget to break the while loop?
Hi , can you explain me what is meant by while(1)?
there should be a break inside while at null check. He probably forgot
@@armeenhossain665 While(1) means the condition is true and the loop will go on (infinite loop) until there is a break. In while(condition), condition is reduced down to either 0 or 1. 0 means false and 1 means true.
Nice explanation Sir
Good explanation as always. Do you have a video about binary tree rotation?
Crystal clear concept👌
Superb sir
i wasn't able to recall the trick thanks for valuable video
Ur videos are so helpful thank u
Very helpful. thanks man
Sir..thnk u
very helpful thank you so much
super understanding ... sir
Whenever we are assigning the pointer in the while loop we need to break
Thank u!
Dear Sir, should there be a continue after executing statements in else p=p->left; continue and similarly in the other else statements?
can you make the video of "Construction of a binary tree from in-order, pre-order traversals"?
Hello Vivekanand! Thanks for the helpful video. If you have not already done so, can you make a video on how to construct an AVL tree as well as how to remove from and rebalance it in code? Again thank you very much and keep up the good work!
very soon Kobee..!
Alright, thanks sir!
could you please explain how we could jump out of the while loop, since it is always 1. Thanks
Once we attach a node to the left or right of its parent , we break from the loop..... It should be as follows:-
while(1)
{
if(q->value value)
{
if(p->left == NULL)
{
p->left = q;
break; ----------------------------------------------- // here is the break condition.
}
else
p = p->left;
}
else if(q->value > p->value)
{
if(p->right == NULL)
{
p->right = q;
break; --------------------------------------------------------------// here is the break condition
}
else
p = p->right;
}
}
can you please modify the video with adding the break; statement. I was also wondering that how do we exit from the while loop then I read this comment ! Thank you !
Sir, I also want videos regarding avl tree operations and some advanced data structures like tries,suffix trees and sting permutation algorithms
very soon i will upload the videos...!
Nice man
Is there a way to get a copy of the BST code in Python?
Nice Video Sir. In Laravel Nestedset how can i get total Left count & Right count from a node. please help.
Please sir can you upload video for coverage and conductance metrics in graph theory.
How can I construct a binary search tree with the optimized depth to the minimum possible according to the number of nodes?
I've made a algorithm to optimize this. I've tested with a random binary tree with 5000 nodes and as result I earned a depth of 15, but, by the math, the minimum depth should be 12.
Create BST using linked list as well as in recursive way
thanku sir :)
good
Sir, please look into this.
It is a program to print preorder, inorder and postorder traversals for t testcases.
I'm getting wrong output.
Given i/p:
1 //num of testcaces
5 //num of arr elements
3 2 4 1 5 //arr elements
Expected o/p:
3 2 1 4 5 //pre
1 2 3 4 5 //in
1 2 5 4 3 //post
My o/p:
3 1 4 5 //pre
1 3 4 5 //in
1 5 4 3 //post
#include
using namespace std;
struct node {
int data;
node *lt,*rt;
};
void preorder(node *root) {
if(root==NULL)
return;
coutlt);
coutrt);
cout>n;
for(int i=0;i>p->data;
p->lt=NULL;
p->rt=NULL;
if(i==0)
root=p;
else {
q=root;
while(1) {
if(p->data > q->data) {
if(q->rt==NULL) {
q->rt=p;
break;
}
else
q=q->rt;
}
else {
if(p->lt==NULL) {
q->lt=p;
break;
}
else
q=q->lt;
}
}
}
}
preorder(root);
cout
Sir could u plz teach how to create binary tree ...It's algorithm
Can u work recursive binary search tree
sir please make video on merge and quick sort with code
plz upload vidseo sir if binary search tree contain symbol also like * + -
Sir if two elements having same values given then how to construct
Not possible. Duplicate values are not allowed in BST, because you cannot decide whether to make the duplicate value, the left child or the right child of the original value.
That is why duplicate values are not allowed.
Could you plz explain binary search tree using linked list
Marathi manus na bhava tu? 😀
sir while(1) is an infinite loop and
there is no any termination condition I think the inner while loop should have the condition like this
while(q!=NULL)
{
if(q->valuevalue)
{
if(p->left==NULL)
{
p->left=q;
q=NULL;
}
else{
p=p->left;
}
}
else
{
if(p->right==NULL)
{
p->right=q;
q=NULL;
}
else
{
p=p->right;
}
}
}
yes you are right. and if you replace q=NULL in your code by "break ; " , it will be even better. Hey friend thanks for communicating. May at that time due to space constraint on board , i have not written that. Thanks a lot bro.
Vivekanand Khyade - Algorithm Every Day mention not sir !!!
sir i serach in git hub ur videos not appeared(this video)
Sir you forgot to break the while loop
Can anyone explain the line p = p->left
The left node of the node p.
The node p has two nodes (left and right). p-> left points to the left node of p.
Sir explain the function plz
Tree traversal programs
Wrong code
To see the full code I will have to create a id in github.com can't you write the full code here in video?
Time consuming