Binary tree: Level Order Traversal
HTML-код
- Опубликовано: 11 мар 2014
- See complete series on data structures here:
• Data structures
In this lesson, we have discussed level order traversal algorithm for binary tree.
See source code here:
gist.github.com/mycodeschool/...
For practice problems and more, visit: www.mycodeschool.com
Like us on Facebook: / mycodeschool
Follow us on twitter: / mycodeschool
6 years later, and this still helped understand. Concepts are truly timeless!
10 years for me now lol
man, I have a PhD in CS, your work is outstanding, it's a great effort to make things clear and accessible to anyone
BTW why are you watching this
😂 curious to know
@@betrp 😂💯
Add friend me 🥲
just had to tell us about your PhD didnt you
You are doing god's work, seriously...This is the only place I've learned sorting algorithms, trees, linked lists, everything related to my syllabus. I should be paying you instead of my college :P
Sad but true.
His code is so much cleaner than anything in the books.
LOL. Donate generously to mycodeschool.
I totally agree. Thanks for this. I will be donating - wish I could get my tuition refunded and donate it here.
Man even 4 years later this is the best playlist on DS.
@@adityaojha2701 true its the best in the entire world wide web and even among university prof
I've grown to be a fan of your videos - they're my first stop for any question or concept I need to clarify on programming!
Jonathan Lim Thanks a lot :)
why do we need current in this example ? :)
@@mycodeschool Have you guys moved somewhere? Where is the website? There are not new videos from the past three years as well :(
@@schizophrenicleo3036 From the comment sections and the news, I learned that the creator of this channel died in a road accident :(
He's famous in programming community as Humble Fool
@@sravanthkumarchintalacheru1359 Oh , I am sorry. Didn't know that. He was indeed making wonderful videos though.
I remember watching your video in linked list for my data structure assignment as a freshman, now I am already studying CS master in the US and start watching your video again for preparing coding interviews!
Sir, you're awesome! very clear explanation and easy to follow!
You are the best teacher with a perfect tone of gifted voice and providing clear explanations about what is happening in memory. These fundamentals would be stamped into our memory easily. Please keep up the great job extending videos to new topics.
Next Lesson: - Binary tree traversal: Preorder, Inorder, Postorder
+mycodeschool okay babu
GOD bless you , you are the best teacher i have ever seen :) great attitude, clear explanation and organized material :)
Poyo Boy - A pointer variable always stores an address. For the definition of Node in this lesson, if I have a pointer to current node in a variable named current, then current will give me the address of that node ,,, current->left will give me address of left child and current->right will give me address of right child. Did you watch previous lessons on tree in this series? They should make things clear for you. Data structures: Introduction to Trees
Do we use stack for other binary tree traversal algorithm: PreOder,InOder,PostOder?
void PreOrder(struct Node *root){
if(root)//If root != NULL
{
printf("%d ",root->data);
PreOrder(root->left);
PreOrder(root->right);
}
}
yes bro we are using stack(implicitly) .but ,it takes place in application memory stack
I always check your videos for a quick, concise and clear explanation of anything I want to learn. Your channels the channel I check for first when I search youtube for tech videos. Thank you very much
Your channel has officially earned my trust. I will recommend anyone interested in basic data structures to come here.
dude you are really good in teaching. i went through almost all your videos now i feel really confident in these topics
This video is almost 9 years ago, but still this video it is the best explaination for level order traversal...(for me)
Thank you so much sir...
Excellent, this was extremely helpful to visually see the level order traversal. I have been having trouble with other examples visually seeing what was happening and this cleared it up greatly. Thank you!
Incredibly helpful! The theoretical lesson was excellent. The code walkthrough was hard to follow, but you did such a good job at teaching with diagrams that the walkthrough wasn't necessary.
Sir I cant thank enough ,You made me understand all the concepts and I will promote your channel in whatever way I can. Thank you
I work in C# and this is the first time that I got a clear understanding about Level_Order_Traversing. Brilliant work.
How the Fu*k should I print this, I understand all things that is taught in this video but I don't know how it will print the elements
@@madanmohan5661 Don't use curse words in educational videos
wow, this guy is huge with explanation... keep it up. have been looking for explanation for this but I think i discovered more than i wanted... bless you guy
Truly ... Thank You. I love your visual , they always help me understand the concepts.Clear and understandable. Awesome!
Again, your explanations have the right depth and keeps complete ! Thank you for the great content!🤓
I am shocked by seeing the explanation of code because it is crisp and neat and also easily understandable. Great work sir.Hope you to add Data structures interview questions on trees and linked lists with code
You got a really thorough knowledge, and you are getting way low audience than you deserve. i m trying to tell most of my friends to refer to your channel.
until now i seen many videos over the youtube but no one was capable to teach in easy and mannerful way then this,founded the bestest video after learning from many .THAnK you man.
How should I print this, I understand all things that is taught in this video but I don't know how it will print the elements
Great video! Very usefull even after 9 years! Code explanation was so good, I had no problems in implementing it into JS and I dont even know any other programming language. Thank you Sir for your work!
it's big art of having such kind of wonderful explanation.. this remember me all MIT university video...
Naming the enqueued as discovered nodes and dequeued as visited nodes makes it much more intuitive, thanks.
mycodeschool is the best.
youre really a kind hearted person. thanks for making such a nice and decent video.
i want to like all you videos dude they are really upto mark
I really wish that u taught at my university. My professor uploaded a bunch of code and told us to go figure it ourselves and that was his genuius idea of teaching.
One of the best explanation's out there!
My prof took 53 minutes. You took 38 seconds.
Thanks a lot man :)
Incredible quality of videos, amazing work!
Bro you are doing a great job :) I am learning computer science just from videos. Thank you very much.
Concise and well explained. You're amazing!
I bet, anyone cannot find better teaching elsewhere, whether be it paid course or at university :), I am rarely a fan of someone but I've been your and your channel's fan for quite a long time :)
I love your videos! All very easy to comprehend and understand. Thank you very much.
I plunged into the way you explained. Love it.
Your videos are great sir it clearly explains what is there and helped me a lot
Thank you sir
Thank you very much
This is called best and awesome way of teaching some one. You really deserve 1000 Million likes. :)
Guys u r doing an awesome job.... wish it all happened a decade back...
Another great video from MyCodeSchool .Thank You for your existence.
How should I print this, I understand all things that is taught in this video but I don't know how it will print the elements
Can't thank you enough for this playlist!
WOW nice tutorial
+ thank you for the 21:9 format
the video fits on my ultrawide screen perfectly
Great job, your videos are awesome and your presentation method is very clear.
I also love you like many others. after you explain the topic it look so easy and simple.
This helped me tremendously. Thank you very much. Great work!
You are the best! Thanks for so clear explanation
Thank you thank you thank you. Your explanation is so amazing. That helps me a lot
These guys are crazy amazing, You guys deserve a Turin prize!
Awesome ...simple and yet so advanced!
& here is your new folwr....concise and well explained. You're amazing! thankyou : )
sir seriously this presentation is greatly awesome.. i really learn too much..
thanks 😊😙☺
Super clear explanation of this!
videos are really helpful...they helped me a lot....thankyou sir and keep sharing this...
Best explanation by far still after 8 years
Thank for the high level quality of the content .. keep doing ;)
xplaining very lucidly snd clearing the doubts
great class! tks!
in 10:35, the max num of nodes in the deepest level is (n+1)/2, not n/2.
Just noticed because I`m using a fixed size queue, so I had to calculate the max.
Tom Lobato he said at least
9 years later, this is still, gold!
The best explanation ever, thanks a lot!
Thank You so Much! The best explanation ever!
Man you are great! Your videos saved my life! Thanks a lot :)
just awesome.. u r better than all the professors out here :)
Thank you so much. Great source of learning.
thank you very much again.. mycodeschool rocks.. i'm your biggest fan.. :)
Seriously, do you have a patreon or a donation link. I want to show my appreciation for what you've done for me by posting these videos
Victor Oben he's at Google/Microsoft now
Disable adBlocks for his videos and if possible click on advertiser links.
He died in road accident
@@JackSparrow-bx8oo Nah, that's not him. His friend, co-founder of mycodeschool died in a road accident.
You make it all so simple :) Thankyou so much
Wow , mind blowing explanation , thank you so much
Amazing way of explaining :)
thank you
شكرا لك وجزاك الله خيرا
Really your are the best, every time I try to understand a concept you rock it. I hope you rest in peace you did very well
This man is still alive actually one of the founders of MyCodeSchool Harsha S aka Humblefool has passed away. The man behind this voice, Animesh Nayan, is currently working at Google. You can search his name on Linkedin.
Really sorry to say, RIP hamblefool.
So why Nayan is no longer uploading videos, we miss his videos 😔
How should I print this, I understand all things that is taught in this video but I don't know how it will print the elements
Great explanations ! it's sad to see that the website is offline :( hopefully you moved on to some other great stuff
You saved me one more time.
Thanks
This is actually mind blowing
this is the the best way to learn new things .
code in C:
include
include
include
include
define MAX 10
struct BstNode{
int data;
struct BstNode* left;
struct BstNode* right;
};
BstNode* arr[MAX];
int front = -1, rear = -1;
bool isEmpty(){
return (front == -1 && rear == -1) ? true : false;
}
bool isFull(){
return (rear+1)%MAX == front ? true : false;
}
void enQueue(BstNode* x){
if(isFull()){
printf("queue is full
");
return;
}
if(isEmpty())
front = rear = 0;
else
rear = (rear+1)%MAX;
arr[rear] = x;
}
void deQueue(){
if(isEmpty()){
printf("queue is empty
");
return;
}
else if(front == rear)
front = rear = -1;
else
front = (front+1)%MAX;
}
BstNode* getNewNode(int d){
BstNode* newNode = (BstNode*)malloc(sizeof(BstNode));
newNode->data = d;
newNode->left = newNode->right = NULL;
return newNode;
}
BstNode* Insert(BstNode* root, int d){
BstNode* newNode = getNewNode(d);
if(root == NULL){
root = newNode;
}
else if(d data){
root->left = Insert(root->left, d);
}
else
root->right = Insert(root->right, d);
return root;
}
void levelOrder(BstNode* root){
if(root == NULL) return;
enQueue(root);
while(!isEmpty()){
BstNode* current = arr[front];
deQueue();
printf("%d ", current->data);
if(current->left != NULL) enQueue(current->left);
if(current->right != NULL) enQueue(current->right);
}
}
int main(){
BstNode* root = NULL;
root = Insert(root,5);
root = Insert(root,10);
root = Insert(root,15);
root = Insert(root,7);
root = Insert(root,3);
root = Insert(root,20);
root = Insert(root,25);
root = Insert(root,21);
levelOrder(root);
return 0;
}
Legendary.. Simply Legendary 👍🏻
This was very clear, thank you!
Very clean explanation🙂
Amazing work mate
Great
Its very helpful for beginners.
Kudos ! Your video lectures are precise & lucid. Really helpful. Thanks a lot. (: thumbs up :)
Could you please share videos on various algorithms implementing various design paradigm viz. Greedy, Divide & Conquer, Dynamic programming.
Very well explained.
you are the best....wish u have uploaded more videos
Very easy explanation! Thanks!
How the Fu*k should I print this, I understand all things that is taught in this video but I don't know how it will print the elements
Amazing explanation, Superb job #mycodeschool
So good..........keep up good things man!
thanks a lot, simple and clear
Superb!! thanks for helping :)
love your videos...Thanks a lot!!
Legendary explanation
Great great great explanation! Thank you sir!
How the Fu*k should I print this, I understand all things that is taught in this video but I don't know how it will print the elements
Amazing explanantion !
thank you for your help
Very helpful!
Awesome, thanks!
Thank you so much for your lectures :))))
thank you sir,its so helpful
Very good tutorial. thank you
Well Presented.! :D
Thanks for the video.
I refer ur videos for any doubts ... and seriously u guys should start planning to charge .... :)