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

Комментарии • 316

  • @tweede5555
    @tweede5555 3 года назад +28

    6 years later, and this still helped understand. Concepts are truly timeless!

  • @jeppojeps
    @jeppojeps 6 лет назад +204

    man, I have a PhD in CS, your work is outstanding, it's a great effort to make things clear and accessible to anyone

  • @slayerq3
    @slayerq3 8 лет назад +314

    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

    • @AlexanderMcNulty92
      @AlexanderMcNulty92 7 лет назад +30

      Sad but true.
      His code is so much cleaner than anything in the books.

    • @nikhilbalwani2285
      @nikhilbalwani2285 5 лет назад +9

      LOL. Donate generously to mycodeschool.

    • @vincentlavello3499
      @vincentlavello3499 4 года назад +3

      I totally agree. Thanks for this. I will be donating - wish I could get my tuition refunded and donate it here.

    • @adityaojha2701
      @adityaojha2701 4 года назад +13

      Man even 4 years later this is the best playlist on DS.

    • @abdelrhmanahmed1378
      @abdelrhmanahmed1378 3 года назад

      @@adityaojha2701 true its the best in the entire world wide web and even among university prof

  • @jonathanlim2269
    @jonathanlim2269 9 лет назад +115

    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!

    • @mycodeschool
      @mycodeschool  9 лет назад +19

      Jonathan Lim Thanks a lot :)

    • @amateurbeginner7538
      @amateurbeginner7538 7 лет назад

      why do we need current in this example ? :)

    • @schizophrenicleo3036
      @schizophrenicleo3036 4 года назад +1

      @@mycodeschool Have you guys moved somewhere? Where is the website? There are not new videos from the past three years as well :(

    • @sravanthkumarchintalacheru1359
      @sravanthkumarchintalacheru1359 4 года назад +1

      @@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

    • @schizophrenicleo3036
      @schizophrenicleo3036 4 года назад

      @@sravanthkumarchintalacheru1359 Oh , I am sorry. Didn't know that. He was indeed making wonderful videos though.

  • @chia-juchen8246
    @chia-juchen8246 6 лет назад +14

    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!

  • @pitchaiahsoma5295
    @pitchaiahsoma5295 9 лет назад +9

    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.

  • @mycodeschool
    @mycodeschool  10 лет назад +63

    Next Lesson: - Binary tree traversal: Preorder, Inorder, Postorder

    • @rohit2761
      @rohit2761 8 лет назад +9

      +mycodeschool okay babu

    • @amateurbeginner7538
      @amateurbeginner7538 7 лет назад +9

      GOD bless you , you are the best teacher i have ever seen :) great attitude, clear explanation and organized material :)

  • @mycodeschool
    @mycodeschool  10 лет назад +28

    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

    • @truongvanloc8275
      @truongvanloc8275 10 лет назад

      Do we use stack for other binary tree traversal algorithm: PreOder,InOder,PostOder?

    • @truongvanloc8275
      @truongvanloc8275 10 лет назад

      void PreOrder(struct Node *root){
      if(root)//If root != NULL
      {
      printf("%d ",root->data);
      PreOrder(root->left);
      PreOrder(root->right);
      }
      }

    • @ramk9953
      @ramk9953 7 лет назад +1

      yes bro we are using stack(implicitly) .but ,it takes place in application memory stack

  • @sr3281
    @sr3281 9 лет назад +3

    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

  • @AlexanderMcNulty92
    @AlexanderMcNulty92 7 лет назад +1

    Your channel has officially earned my trust. I will recommend anyone interested in basic data structures to come here.

  • @nitinjaiman
    @nitinjaiman 10 лет назад +5

    dude you are really good in teaching. i went through almost all your videos now i feel really confident in these topics

  • @Srinivasssssss
    @Srinivasssssss 6 месяцев назад +1

    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...

  • @sunnysidesounds
    @sunnysidesounds 9 лет назад +2

    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!

  • @jamisongriffith6308
    @jamisongriffith6308 2 года назад +1

    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.

  • @noumanmalik960
    @noumanmalik960 6 лет назад

    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

  • @jcvandermerwe5311
    @jcvandermerwe5311 3 года назад +3

    I work in C# and this is the first time that I got a clear understanding about Level_Order_Traversing. Brilliant work.

    • @madanmohan5661
      @madanmohan5661 Год назад +1

      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

    • @lanternarasu6061
      @lanternarasu6061 Год назад

      @@madanmohan5661 Don't use curse words in educational videos

  • @eddyateye810
    @eddyateye810 Год назад +3

    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

  • @jessg7144
    @jessg7144 5 лет назад +1

    Truly ... Thank You. I love your visual , they always help me understand the concepts.Clear and understandable. Awesome!

  • @camillesatoshi8393
    @camillesatoshi8393 Год назад

    Again, your explanations have the right depth and keeps complete ! Thank you for the great content!🤓

  • @harikrishna-io8sc
    @harikrishna-io8sc 5 лет назад

    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

  • @vishalraghav8982
    @vishalraghav8982 7 лет назад +19

    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.

  • @laveshchanchawat6983
    @laveshchanchawat6983 2 года назад

    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.

    • @madanmohan5661
      @madanmohan5661 Год назад

      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

  • @martini9388
    @martini9388 11 месяцев назад

    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!

  • @sachinos
    @sachinos 8 лет назад

    it's big art of having such kind of wonderful explanation.. this remember me all MIT university video...

  • @vaibhavtiwari6540
    @vaibhavtiwari6540 2 года назад

    Naming the enqueued as discovered nodes and dequeued as visited nodes makes it much more intuitive, thanks.

  • @looppp
    @looppp 8 лет назад +19

    mycodeschool is the best.

  • @likithareddy4627
    @likithareddy4627 6 лет назад

    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

  • @HK-no9wm
    @HK-no9wm 6 лет назад

    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.

  • @ritikpatel3286
    @ritikpatel3286 5 лет назад +1

    One of the best explanation's out there!

  • @Contemelia
    @Contemelia 3 года назад +1

    My prof took 53 minutes. You took 38 seconds.
    Thanks a lot man :)

  • @axelramirezlinarez7449
    @axelramirezlinarez7449 5 лет назад

    Incredible quality of videos, amazing work!

  • @MrNiceone99
    @MrNiceone99 7 лет назад

    Bro you are doing a great job :) I am learning computer science just from videos. Thank you very much.

  • @CautiousCrow
    @CautiousCrow 8 лет назад +1

    Concise and well explained. You're amazing!

  • @ardhyakumar2539
    @ardhyakumar2539 6 лет назад +1

    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 :)

  • @goldymarizlunesa8719
    @goldymarizlunesa8719 7 лет назад

    I love your videos! All very easy to comprehend and understand. Thank you very much.

  • @MJ-zs5jv
    @MJ-zs5jv 8 месяцев назад

    I plunged into the way you explained. Love it.

  • @TangiralaVenkat
    @TangiralaVenkat 8 лет назад +1

    Your videos are great sir it clearly explains what is there and helped me a lot
    Thank you sir
    Thank you very much

  • @26411bapul
    @26411bapul 6 лет назад

    This is called best and awesome way of teaching some one. You really deserve 1000 Million likes. :)

  • @honeyshihtzu9675
    @honeyshihtzu9675 8 лет назад

    Guys u r doing an awesome job.... wish it all happened a decade back...

  • @sa25078
    @sa25078 2 года назад

    Another great video from MyCodeSchool .Thank You for your existence.

    • @madanmohan5661
      @madanmohan5661 Год назад

      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

  • @austinbvi
    @austinbvi 5 лет назад +1

    Can't thank you enough for this playlist!

  • @vithushanjegatheeswaran5317
    @vithushanjegatheeswaran5317 7 лет назад

    WOW nice tutorial
    + thank you for the 21:9 format
    the video fits on my ultrawide screen perfectly

  • @hhammash
    @hhammash 7 лет назад

    Great job, your videos are awesome and your presentation method is very clear.

  • @vijay6877
    @vijay6877 4 года назад

    I also love you like many others. after you explain the topic it look so easy and simple.

  • @josnoordzij6802
    @josnoordzij6802 3 года назад +1

    This helped me tremendously. Thank you very much. Great work!

  • @MCrown
    @MCrown 5 лет назад +4

    You are the best! Thanks for so clear explanation

  • @memofahood4543
    @memofahood4543 10 лет назад

    Thank you thank you thank you. Your explanation is so amazing. That helps me a lot

  • @mursalinhabib1156
    @mursalinhabib1156 3 года назад

    These guys are crazy amazing, You guys deserve a Turin prize!

  • @jeetsharma1292
    @jeetsharma1292 3 года назад +2

    Awesome ...simple and yet so advanced!

  • @snehill7275
    @snehill7275 2 года назад

    & here is your new folwr....concise and well explained. You're amazing! thankyou : )

  • @kunalsoni7681
    @kunalsoni7681 4 года назад

    sir seriously this presentation is greatly awesome.. i really learn too much..
    thanks 😊😙☺

  • @dawkinsjh
    @dawkinsjh 8 лет назад +1

    Super clear explanation of this!

  • @nigannayak2139
    @nigannayak2139 7 лет назад

    videos are really helpful...they helped me a lot....thankyou sir and keep sharing this...

  • @anonnona6940
    @anonnona6940 Год назад

    Best explanation by far still after 8 years

  • @MegaPaloma1988
    @MegaPaloma1988 5 лет назад +1

    Thank for the high level quality of the content .. keep doing ;)

  • @bilalbashir8361
    @bilalbashir8361 7 лет назад

    xplaining very lucidly snd clearing the doubts

  • @TomLobato
    @TomLobato 6 лет назад +1

    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.

  • @ajaygunalan1995
    @ajaygunalan1995 7 месяцев назад

    9 years later, this is still, gold!

  • @Cassandra81552
    @Cassandra81552 6 месяцев назад

    The best explanation ever, thanks a lot!

  • @daboren1547
    @daboren1547 4 года назад

    Thank You so Much! The best explanation ever!

  • @andreaolexova2621
    @andreaolexova2621 9 лет назад

    Man you are great! Your videos saved my life! Thanks a lot :)

  • @paragkarguppikar9006
    @paragkarguppikar9006 9 лет назад

    just awesome.. u r better than all the professors out here :)

  • @premalathak6748
    @premalathak6748 9 лет назад

    Thank you so much. Great source of learning.

  • @rbsupercool
    @rbsupercool 10 лет назад +9

    thank you very much again.. mycodeschool rocks.. i'm your biggest fan.. :)

  • @11m0
    @11m0 6 лет назад +34

    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

    • @kyssl
      @kyssl 6 лет назад +4

      Victor Oben he's at Google/Microsoft now

    • @theFifthMountain123
      @theFifthMountain123 5 лет назад +1

      Disable adBlocks for his videos and if possible click on advertiser links.

    • @JackSparrow-bx8oo
      @JackSparrow-bx8oo 3 года назад +2

      He died in road accident

    • @anveshreddypinnapareddy3552
      @anveshreddypinnapareddy3552 3 года назад +2

      @@JackSparrow-bx8oo Nah, that's not him. His friend, co-founder of mycodeschool died in a road accident.

  • @roliverma4483
    @roliverma4483 3 года назад

    You make it all so simple :) Thankyou so much

  • @tapanachary2348
    @tapanachary2348 4 года назад

    Wow , mind blowing explanation , thank you so much

  • @AwaraGhumakkad
    @AwaraGhumakkad 2 года назад +1

    Amazing way of explaining :)

  • @freedomformysyria
    @freedomformysyria 6 лет назад

    thank you
    شكرا لك وجزاك الله خيرا

  • @hossamtolba948
    @hossamtolba948 4 года назад

    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

    • @ishanpand3y
      @ishanpand3y 4 года назад

      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.

    • @hossamtolba948
      @hossamtolba948 4 года назад

      Really sorry to say, RIP hamblefool.
      So why Nayan is no longer uploading videos, we miss his videos 😔

    • @madanmohan5661
      @madanmohan5661 Год назад

      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

  • @zoumzoumzou
    @zoumzoumzou 5 лет назад +1

    Great explanations ! it's sad to see that the website is offline :( hopefully you moved on to some other great stuff

  • @elishaalibakhsh7393
    @elishaalibakhsh7393 3 года назад

    You saved me one more time.
    Thanks

  • @jonathanharoun5247
    @jonathanharoun5247 3 года назад

    This is actually mind blowing

  • @ashwinimishra4097
    @ashwinimishra4097 5 лет назад

    this is the the best way to learn new things .

  • @amateurbeginner7538
    @amateurbeginner7538 7 лет назад +7

    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;
    }

  • @HeyMr.OO7
    @HeyMr.OO7 11 месяцев назад

    Legendary.. Simply Legendary 👍🏻

  • @danielarodriguez1967
    @danielarodriguez1967 2 года назад

    This was very clear, thank you!

  • @San_Jan_
    @San_Jan_ 3 года назад

    Very clean explanation🙂

  • @dir3mad
    @dir3mad 8 лет назад

    Amazing work mate

  • @mukeshjangidwwe
    @mukeshjangidwwe 8 лет назад

    Great
    Its very helpful for beginners.

  • @ashishkumarg5
    @ashishkumarg5 9 лет назад +2

    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.

  • @GauravSingh-ku5xy
    @GauravSingh-ku5xy 2 года назад

    Very well explained.

  • @MiddleClassTalk
    @MiddleClassTalk 6 лет назад

    you are the best....wish u have uploaded more videos

  • @jasneetsinghanand6761
    @jasneetsinghanand6761 3 года назад

    Very easy explanation! Thanks!

    • @madanmohan5661
      @madanmohan5661 Год назад

      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

  • @amit5051088
    @amit5051088 7 лет назад

    Amazing explanation, Superb job #mycodeschool

  • @CHIchangching
    @CHIchangching 10 лет назад

    So good..........keep up good things man!

  • @breakunknown
    @breakunknown 2 года назад

    thanks a lot, simple and clear

  • @srichetaruj2590
    @srichetaruj2590 8 лет назад +1

    Superb!! thanks for helping :)

  • @JayasooryanKVpnr
    @JayasooryanKVpnr 9 лет назад

    love your videos...Thanks a lot!!

  • @ivlog4955
    @ivlog4955 5 лет назад

    Legendary explanation

  • @danishuddin9752
    @danishuddin9752 2 года назад

    Great great great explanation! Thank you sir!

    • @madanmohan5661
      @madanmohan5661 Год назад

      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

  • @henrikrynauw244
    @henrikrynauw244 3 года назад

    Amazing explanantion !

  • @berna031
    @berna031 2 года назад +1

    thank you for your help

  • @kautukraj
    @kautukraj 4 года назад +1

    Very helpful!

  • @KelseyHrubes
    @KelseyHrubes 9 лет назад +1

    Awesome, thanks!

  • @AnirudhSinghTomarBME
    @AnirudhSinghTomarBME 4 года назад

    Thank you so much for your lectures :))))

  • @nandini-ec5xl
    @nandini-ec5xl 6 лет назад

    thank you sir,its so helpful

  • @rar000000000
    @rar000000000 8 лет назад

    Very good tutorial. thank you

  • @guptayash4
    @guptayash4 9 лет назад

    Well Presented.! :D
    Thanks for the video.

  • @honeyshihtzu9675
    @honeyshihtzu9675 8 лет назад

    I refer ur videos for any doubts ... and seriously u guys should start planning to charge .... :)