Although I was in Vietnam, I do not know much about English, but you preach is easy to understand . Easier to understand than the Vietnamese . Fantastic !! Thank you very much.
I really really liked that video, because this tutorial provides"recursion method" as well as"Non recursion method" .. Thanks for that beautiful effort 💞.. from Pakistan...
Thank you very much for your efforts. If i get a programer job thanks to this videos i will make a donation as soon as i can. You are way better than my profesors. Keep up the good work.
Superb video..I have a doubt In the recursive approach,what happens to the paused function,wont they give an error return statement missing? because for the paused functions there is nothing below return FindMin(root->left); .........and return type of the function is int!
when you say root can be used as a local variable, I tried the following code snippet. #include struct node { int data; struct node *next; }; void change_data(struct node *root) { root->data = 7; } int main() { struct node *root; root = (struct node*)malloc(sizeof *root); root->data = 5; change_data(root); printf(" root data:%d",root->data); } With your logic, changing root->data in change_data should not change the root in main function. however the output of this function is 7 not 5. Can you explain the same?
Indeed, the answer you get is expected one. Because you are modifying the same chunk of the memory. You pass to the method change_data() an address(which is the reference to the malloced memory) that you keep at **root(pointer to pointer root), and this address is assigned as a value of the **root(pointer to pointer) that you have in change_data which is not equivalent to the **root in main. From the output of the following snippet, you will notice that **root in main() and change_data() is different, however the address they keep is the same. Hope, it helps. #include #include struct node { int data; struct node *next; }; void change_data(struct node *root) { printf("change: * %p ", root); printf("change: **%p ", &root); root->data = 7; } int main() { struct node *root; root = (struct node*)malloc(sizeof *root); root->data = 5; change_data(root); printf("main: * %p ", root); printf("main: **%p ", &root); printf(" root data:%d",root->data); }
+Manali Bhutiyani TL;DR answer: To get the result you are looking for, your function change_data(struct node *root) should return type struct node*. Then in your main, change to: root = root->data=5 That way, your main function is assigned to the address of the newly changed node.
The only thing I do not like about this implementation is that negative integers can be stored in this tree, so returning -1 when the root is NULL creates a conflict. Instead, I think it would be better to throw an exception when the root is null. Does anyone have a better suggestion?
we don't need to use return in the last line, we can directly call the function, is it that using return reduces stack frame from growing as the last function ends before calling the new function
Can someone provide all the possible operations (insert, delete, search, height, print infix , prefix and post fix order) with recursion in single program. Please use "root" as global variable...don't want to return pointer every time. struct node * root = NULL in global scope is must.
im confused ...if root->left ==NULL ..why wouldnt it go to the first if ( root ==null) ..instead of going to else if (root-left ==null) how will he reconize it ..isnt it a local variable !
bro u return -1 if the tree is empty but think if the tree is not empty and the minimum value in tree is also -1 then it will return -1 so how can u manage this condition in main function.
i think O(log(n)) for iterative, because we are dividing are problem by half at each step and may be same in recursion. Instead of big-O we can use theta as well because we are sure that it is the left most/right most element for min/max elements.
I'd think to add another pointer ( let's call it Prev ) and go recursively through the whole left subtree till you find the leaf as he did in this video and just return Prev -> data instead; Hope this helps!
Yes it will definitely worked for all type of binary tree. As Left and Right skewed tree are also Binary tree as they have atmost 2 child actually one child except the leaf node which do not have a child node . So in case of skewed tree to find min in right skewed the first condition will itself true so we return root data as it is. Same in case of finding max in left skewed tree . Hope it helps !!
Although I was in Vietnam, I do not know much about English, but you preach is easy to understand . Easier to understand than the Vietnamese . Fantastic !! Thank you very much.
Dũng Nguyễn Hoàng Anh Love to Vietnam :)
Dũng Nguyễn Hoàng Anh me too.
I really really liked that video, because this tutorial provides"recursion method" as well as"Non recursion method" ..
Thanks for that beautiful effort 💞.. from Pakistan...
Doing the god's work really
:D - really funny dude!
Thank you very much for your efforts. If i get a programer job thanks to this videos i will make a donation as soon as i can.
You are way better than my profesors. Keep up the good work.
Saša Škvorc Thanks a lot and all the best to you :)
I am devouring your course
please make videos for AVL TREE , THREADED ,B-TREE .
SW Engineer for 7 years ...Computer Science graduate ...but understanding DSA concepts clearly now !! Thanks much !!
You r a great teacher! Keep it up mate!
Superb tutorials. What about creating a video on deleting from a BST?
Owen Parkinson Yeah, I will create one on deleting node from BST. :)
Great tutorials dude.. could you please upload a video on finding permutations of a string in c?
the best tutorials!!! awsm work......plz prepare such a sereis for AVR Cprogramming...
Can u pl tell its complexity?!
Superb video..I have a doubt
In the recursive approach,what happens to the paused function,wont they give an error return statement missing? because for the paused functions there is nothing below return FindMin(root->left); .........and return type of the function is int!
I have decided to give you a Nobel Prize!!
Why isn't the condition for while loop is not current!=null and y is it current->next!= Null?
amazing explanation
Thanks a ton Sir Kindly upload some videos on Balancing trees and AVL trees.
How to call FindMin() function from main function? Which argument should I pass in FindMin() function?
pass the address of the root node
when you say root can be used as a local variable, I tried the following code snippet.
#include
struct node
{
int data;
struct node *next;
};
void change_data(struct node *root)
{
root->data = 7;
}
int main()
{
struct node *root;
root = (struct node*)malloc(sizeof *root);
root->data = 5;
change_data(root);
printf("
root data:%d",root->data);
}
With your logic, changing root->data in change_data should not change the root in main function. however the output of this function is 7 not 5.
Can you explain the same?
Indeed, the answer you get is expected one. Because you are modifying the same chunk of the memory. You pass to the method change_data() an address(which is the reference to the malloced memory) that you keep at **root(pointer to pointer root), and this address is assigned as a value of the **root(pointer to pointer) that you have in change_data which is not equivalent to the **root in main. From the output of the following snippet, you will notice that **root in main() and change_data() is different, however the address they keep is the same. Hope, it helps.
#include
#include
struct node
{
int data;
struct node *next;
};
void change_data(struct node *root)
{
printf("change: * %p
", root);
printf("change: **%p
", &root);
root->data = 7;
}
int main()
{
struct node *root;
root = (struct node*)malloc(sizeof *root);
root->data = 5;
change_data(root);
printf("main: * %p
", root);
printf("main: **%p
", &root);
printf("
root data:%d",root->data);
}
+Manali Bhutiyani TL;DR answer: To get the result you are looking for, your function change_data(struct node *root) should return type struct node*.
Then in your main, change to:
root = root->data=5
That way, your main function is assigned to the address of the newly changed node.
Thanks, great vid!
You are awesome! :)
The only thing I do not like about this implementation is that negative integers can be stored in this tree, so returning -1 when the root is NULL creates a conflict. Instead, I think it would be better to throw an exception when the root is null. Does anyone have a better suggestion?
That's right. But any suggestions on what we could do if we know that the B.S.T can have negative values? :)
You could return the minimum value of the Integer class. How you get that value depends on your language (i.e. Java = Integer.MIN_VALUE)
@@goodToBeLost XDDDD
Very clean and easy to understand! Thanks!
we don't need to use return in the last line, we can directly call the function, is it that using return reduces stack frame from growing as the last function ends before calling the new function
Can someone provide all the possible operations (insert, delete, search, height, print infix , prefix and post fix order) with recursion in single program.
Please use "root" as global variable...don't want to return pointer every time.
struct node * root = NULL in global scope is must.
im confused ...if root->left ==NULL ..why wouldnt it go to the first if ( root ==null) ..instead of going to else if (root-left ==null) how will he reconize it ..isnt it a local variable !
bro u return -1 if the tree is empty but think if the tree is not empty and the minimum value in tree is also -1 then it will return -1 so how can u manage this condition in main function.
There is an assumption in this example that he described - "Tree is storing only positive numbers"
i find it quite blank to test it
anyone know?
what is the time complexity of iterative and recursion approach
i think O(log(n)) for iterative, because we are dividing are problem by half at each step and may be same in recursion. Instead of big-O we can use theta as well because we are sure that it is the left most/right most element for min/max elements.
great work sir. :-)
To find the maximum or minimum element we have to provide the pointer to the root node no? how is it done?
How do we make sure that current -> left will actually traverse left and not right side ?
int FindMin(BstNode* root) {
if (root == NULL) return -1;
if (root->left) return FindMin(root->left);
else return root->data;
}
To find the maximum or minimum element we have to provide the pointer to the root node no? how is it done?
Beautifully explained. Thank you so much.
how to find the next min???
I'd think to add another pointer ( let's call it Prev ) and go recursively through the whole left subtree till you find the leaf as he did in this video and just return Prev -> data instead;
Hope this helps!
Very well explained
Good video man TXH a lot :P
Please come back sir, we need you
Can I get a complete C# code for this
thank u🤩
thank you
why the root in main doesn't change when we are passing the address of root in Findmin()???
bcz we are passing root pointer by reference so function will have its own copy of root pointer, not affecting the original
So the minimum for this problem will be 2?
Very nice explanation
Will it work for a right screwd tree where min element is root itself?
Yes it will definitely worked for all type of binary tree.
As Left and Right skewed tree are also Binary tree as they have atmost 2 child actually one child except the leaf node which do not have a child node .
So in case of skewed tree to find min in right skewed the first condition will itself true so we return root data as it is.
Same in case of finding max in left skewed tree .
Hope it helps !!
this code won't work for all cases
Great video
thanks chachu
thank you very much, it helps me a lot!!
My man.
seriously awesome videos ..could u plz upload a video on graphs..
Harmanpreet Kaur Yeah, I am a bit slow.. I am not getting the time. But Graph is next on my list. Expect some videos on Graph in August.
3:14,4:11,5:34
Thank u brother
I am in love with your videos...awesome
And I am in love with you
sdf
I miss your videos sir. We all need a teacher like you. #respect
kindly make a video on insert a node in bst