Binary search tree - Implementation in C/C++

Поділитися
Вставка
  • Опубліковано 3 лют 2014
  • See complete series on data structures here:
    • Data structures
    In this lesson, we have implemented binary search tree in C/C++. We have written a simple program to create a binary search tree of integers and search an element in it.
    See source code here:
    gist.github.com/mycodeschool/...
    Lesson on dynamic memory allocation:
    • Pointers and dynamic m...
    For practice problems and more, visit: www.mycodeschool.com
    Like us on Facebook: / mycodeschool
    Follow us on twitter: / mycodeschool

КОМЕНТАРІ • 604

  • @ahmeddeghady4510
    @ahmeddeghady4510 4 роки тому +1405

    I'm a simple man, I see recursive function, I panic.

  • @HollowPiero
    @HollowPiero 10 років тому +735

    You make me understand in 18 min what my teacher couldn't in 2 hours. Very Good.

    • @mycodeschool
      @mycodeschool  10 років тому +125

      Thanks :)

    • @pradeepkumaryadav9641
      @pradeepkumaryadav9641 6 років тому +6

      yes this videos are brilliant

    • @chaudharyadityakumar6149
      @chaudharyadityakumar6149 6 років тому +10

      bro your r awesome.Why your not making new videos.I am in graduation and I am studying programming from 9 class ..I have come across many teachers but you are amazing. You can be one of the best programming teachers on youtube.

    • @zacharyhe5719
      @zacharyhe5719 6 років тому +2

      that's the real thing

    • @chaudharyadityakumar6149
      @chaudharyadityakumar6149 6 років тому +2

      bro i recently find out that the guy is dead

  • @solomonleo3025
    @solomonleo3025 3 роки тому +70

    7 years later....
    Teachers at clg:- Still sucks at DSA
    mycodeschool:- Still rules at DSA

  • @simpleffective186
    @simpleffective186 4 роки тому +24

    this guy is the best teacher ever and you can't even find his name on the channel. Thank you for your work, humble Animesh Nayan.

  • @nguaial8490
    @nguaial8490 8 років тому +172

    You are much better than most of cocky PhD professors who needs to learn how to write neatly and speak slowly.
    Most of professors are trying to show off how smart they are. So arrogant ...

    • @AliRazaiamaliraza
      @AliRazaiamaliraza 7 років тому +6

      You should respect your teachers, no matter how they are and what they do... -_-

    • @elvisdurmishi9893
      @elvisdurmishi9893 7 років тому +72

      Ali Raza no you shouldnt,respect is earned,if they don't know how to teach then they should just quit and stop wasting everyones time

    • @daliamohamed2858
      @daliamohamed2858 7 років тому +32

      why should i ? i paid money to learn if they r bad they should quit and stop wasting my time !
      or to do researching staff far away from teaching n wasting time !

    • @sujoymitra1012
      @sujoymitra1012 5 років тому

      Ali Raza u r right, u should respect ur teachers, no matter what they know or teach, and most importantly how they teach but in some cases if a teacher boasts about his knowledge in collg and that doesn't quite seem nice off course, that may be wrong on the teacher's part irrespective of whether the knowledge the teacher has is right or wrong.

    • @TheseEyesSeeDarknessClearly
      @TheseEyesSeeDarknessClearly 5 років тому +9

      Idiot. @@AliRazaiamaliraza

  • @MikeAllaway
    @MikeAllaway 9 років тому +281

    Your videos are brilliant. Very clearly explained and thorough. They will help many people and you should be proud of your great work

    • @mycodeschool
      @mycodeschool  9 років тому +41

      Mike Allaway Thanks a lot :)

    • @robinfr93
      @robinfr93 9 років тому +7

      I second what Mike said!!

    • @GGlearn
      @GGlearn 10 місяців тому

      best teacher ever

  • @Panaxis
    @Panaxis 6 років тому +20

    In 18 minutes I just learned way more than I did in class since January. Thank you so much! I cant wait to watch your other videos!

  • @shivachandrachary
    @shivachandrachary 9 років тому +41

    Omg!, I couldn't have asked for a better explanation. It felt like I coded the whole algorithm myself. Thanks!!

  • @abhijeetjain8591
    @abhijeetjain8591 7 років тому +164

    rather than just saying "thank you" in comments , we should also turn off adblocker while watching these awesome videos !

    • @gericapo8739
      @gericapo8739 5 років тому +1

      Fair

    • @shyam5631
      @shyam5631 4 роки тому +1

      He is dead.

    • @ekashto
      @ekashto 4 роки тому

      @@shyam5631
      How do you know?

    • @shyam5631
      @shyam5631 4 роки тому +1

      @@ekashto he was a popular person and also he was a red coder.

    • @vighneshk509
      @vighneshk509 4 роки тому +5

      @@shyam5631 dude his partner passed away not him there were two guys

  • @chuanyu8813
    @chuanyu8813 4 роки тому +12

    The best video I have seen until now for explaining data structures and algorithms. Fantastic! Clean and concise!

  • @veereshranjan3519
    @veereshranjan3519 4 роки тому +4

    The explanation about BST was splendid but this is a master piece because you not only made the concept clear but also implementation in the actual program.. hats off

  • @modguy9894
    @modguy9894 Рік тому +7

    8 years gone by and it still is more valuable than the class lectures

  • @inclinedscorpio
    @inclinedscorpio 5 років тому +425

    *Could you please teach my teacher ?????*

  • @austinbvi
    @austinbvi 5 років тому +27

    You're an angel! I'm binging the entire playlist prepping for an interview.

    • @shivamdhir640
      @shivamdhir640 3 роки тому

      how did the interview go ?

    • @austinbvi
      @austinbvi 3 роки тому +4

      @@shivamdhir640hmm I did a few that season and don’t remember which that comment was referencing but overall went like 4 for 6 offer-wise-this playlist is great, I’d crank out leetcode problems related to the topic alongside the videos

  • @abhishiekmahajan9103
    @abhishiekmahajan9103 5 років тому +5

    You make it so interesting ,this 18 minutes were shortest in my life.

  • @pkj6962
    @pkj6962 3 роки тому

    He had a great sense in making videos. He made video in the way students who just search the keyword and don't follow the data structures courses.

  • @jonathanlim2269
    @jonathanlim2269 9 років тому +4

    Great explanation, clear, concise with good linking to previously learnt concepts both as a reinforcer as well as a reminder for those who have lost touch them them

  • @madjayhawk
    @madjayhawk 6 років тому +5

    You are an excellent teacher. Very organized with perfect graphics.

  • @AngoraKat11
    @AngoraKat11 7 років тому

    I am glad I stumble upon this video to understand BST. Thank you and keep up the good work!

  • @LaTiNScOrPiOn33
    @LaTiNScOrPiOn33 9 років тому +12

    I haven't even started this video and I already know it will be amazing due to your previous videos. Thanks for the helpful video!

  • @VaLeEBP
    @VaLeEBP 8 років тому +10

    I really appreciate your work mister, you help me out on many of my programming problems with this videos, thank you so much :)
    Saludos desde Tijuana B.C. México

  • @johnhurley8918
    @johnhurley8918 7 років тому

    Thanks to this playlist, I've been reviewing the content of an entire college coarse so far in one day. Pay attention kids. I need to know these concepts for my job interview tomorrow.

    • @vidzpk5144
      @vidzpk5144 6 років тому

      I know it's late but did you get the job? and did they ask about Data Structures?

  • @rohankumarshah5679
    @rohankumarshah5679 2 роки тому

    the idea of pause and play in recursion is lit, great job!!

  • @pcpardon
    @pcpardon Місяць тому

    Even though, You are long gone, your work and legacy still inspires me. Even today, when I wanted have quick refresh on my basics, I would still visit here. May you attain nibbana.

  • @justcallmeRISHI
    @justcallmeRISHI 4 місяці тому +1

    Great work Sir, RIP legend, still revising this material.

  • @yashasvibajpai4702
    @yashasvibajpai4702 5 років тому +2

    Sad to feel that this legend is no more in this world!!!!
    He will still remain eternal on UA-cam and help everyone forever!!!!

  • @stealurwife2489
    @stealurwife2489 2 роки тому

    im here 8 years later and i cant thank you enough

  • @nick1f
    @nick1f 6 років тому

    You make incredibly good tutorials, thank you so much for sharing them with us.

  • @tannerbarcelos6880
    @tannerbarcelos6880 5 років тому

    super good explanation! I was like "what the heack is a pointer reference' but now i get it. the new node being dynamically created is basically a pointer to a node so when calling insert privately, that is the pointer passed in as reference. Makes more sense after thinking about it more.

  • @digitalproductsbusiness226
    @digitalproductsbusiness226 Рік тому

    sir awesome i didnot understand the recursion from last 2 months in trees but your video is just miracle for me now i understand how the recursion is work in tree step by step keep it up sir

  • @pallavivanarse1685
    @pallavivanarse1685 3 роки тому

    Very good explanation with good clarity of binary search tree implementation ...I never see such good explanation anywhere ... I really appreciate the person behind this channel .. thanks for providing such nice videos

  • @user-oy5yj7ic5h
    @user-oy5yj7ic5h 4 роки тому

    Haven't learned C/C++ before but got it thoroughly. Thanks !!!!!!!

  • @TheGamer720x
    @TheGamer720x 9 років тому

    The most amazing explanation with proper example+animation. Cheers !! Helped a lot !! Thanx !

  • @priyabalakrishnan4093
    @priyabalakrishnan4093 10 років тому +2

    Had been waiting for this implementation video!!! Thank you!!!

  • @wilacademy8916
    @wilacademy8916 7 місяців тому

    Sir, a thousand of thankyou. i love you sir. i'm now preparing for my next term in computer engineering major. i'm so very happy now im study with the best code channel.

  • @squirrelgaming4028
    @squirrelgaming4028 7 років тому +1

    thx for everything you've made everything much simplier to understand ,you're brilliant sir

  • @LetTheWritersWrite
    @LetTheWritersWrite 6 років тому +1

    Fantastic lesson. I just want to point out that the addressing can be simplified so much by making a class instead in C++ that will save the pain of referencing addresses and whatnot.

  • @1234CDAB
    @1234CDAB 8 років тому +1

    You are such a great presenter. Thank you, keep up the good work

  • @edwarddeitner3006
    @edwarddeitner3006 6 років тому +4

    Unbelievable, I am really bad in English but I understand almost everything what you explain in this language, which is pretty strange for me. It is like Einstein said: If you cant explain it easy enough you do not understand it well enough.
    And you understand it absolutely, so your explanations get great!

  • @SuperBhavanishankar
    @SuperBhavanishankar 8 років тому

    great to have a class on this, that benefited me, which my college can't provide. thanx a lot!

  • @_captainfalc0n
    @_captainfalc0n 9 років тому +3

    That was soo clearly explained. Thank You.

  • @manushreev6573
    @manushreev6573 3 місяці тому

    A very clear and precise video lecture. I was searching for this type of video. Thank you

  • @jonathonvandergriff2299
    @jonathonvandergriff2299 9 років тому

    Excellent coverage -- this is better than I had back in college.

  • @mawsn
    @mawsn 3 роки тому

    I wish I could like this video more than once, pure gold!

  • @usufarif
    @usufarif 6 років тому

    Excellent discussion on Data Structures, great detail and crisp content. Thanks. Yusuf Arif

  • @MisterNorthernCanuck
    @MisterNorthernCanuck 8 років тому

    You make so much more sense then my teacher, many thanks

  • @elvegaalberto
    @elvegaalberto 8 років тому +2

    Your tutorials are so easy to understand. Great job :] and Thanks :)

  • @ab3l588
    @ab3l588 3 роки тому +1

    Great explanation- the play and pause symbols really help! Thanks a lot :)

  • @Saradomin65
    @Saradomin65 7 років тому

    You're a great teacher tbh. My teacher teaches us only how to do the BST tree and just leaves us to do the codes on our own without using the internet :(

  • @manojpandey7517
    @manojpandey7517 4 роки тому +11

    3:08 A self-note;
    Any object created in dynamic memory/heap can only be accessed through pointers.

  • @abkedare
    @abkedare 6 років тому

    Best data structure tutorial I have ever seen

  • @offchan
    @offchan 9 років тому +38

    9:45 You could pass pointer by reference and that would do the job best.
    void insert(BstNode*& root) is the best way to pass a pointer that you want to changes its actual address.
    Normally, if you use BstNode*, you are passing pointer by value which means you can change the dereferenced data the pointer is pointing to but you are actually copying the address of the pointer so changing the address of the root inside function won't affect the actual address of root in main.
    Summary: Pass pointer by reference *& so you don't need to return the changed address to the caller. Passing pointer as a form of pointer like you do also does the job but I think it's too confusing and look superfluous.

    • @andrethomazjr.1845
      @andrethomazjr.1845 5 років тому +1

      thanks man... I love you

    • @aditya6542
      @aditya6542 4 роки тому +1

      But wouldn't it require to create a temporary pointer variable because the function is changing the address in root. I know this reply is far apart, 5 years to be precise. I am currently studying this, read your comment wondered about it

    • @offchan
      @offchan 4 роки тому +2

      @@aditya6542 BstNode*& internally works similar to BstNode**. It means that it should consume the same memory. It's just that the syntax is easier to understand. Here's how to use it:
      BstNode* root = NULL;
      Insert(root,15);
      void Insert(BstNode*& root, int data) {
      if (root == NULL) {
      root = GetNewNode(data);
      }
      }
      I don't remember the syntax quite well because I haven't written in C++ for long now. But it should be something along that line.

    • @aditya6542
      @aditya6542 4 роки тому +1

      @@offchan Thanks a lot for taking time to explain me. I just tried call by reference method suggested by you and it worked like a charm and the code is now even more readable.

    • @mohammedjakhirhussain8699
      @mohammedjakhirhussain8699 4 роки тому

      @@offchan hey I tried code and works very well but, I have another doubt in this code, if you notice at 16:16 the root is currently pointing to address 500. but what if we want to insert 21 at left side of 20(address 300).please help I am so confused.

  • @kikakky
    @kikakky 8 років тому

    It's really helpful for my final exam!! Thanks for your hard work! ;)

  • @unsaturated8482
    @unsaturated8482 7 років тому

    you're videos always helped me
    thank you. very much

  • @sagar1287
    @sagar1287 4 роки тому

    dil khush ho gya bhai aapki video dekhkar
    dil se thankyou

  • @manishkanyal4003
    @manishkanyal4003 5 років тому

    Video is great and explained every concept clearly. This video is helping ne for preparing for my exams.Thanku codeschool for making such an awesome video tutorials.

  • @dimitardzorlev6283
    @dimitardzorlev6283 7 років тому +1

    rest in peace.
    you are the best.
    You teach great.

  • @abexoxo
    @abexoxo 7 місяців тому

    Thank you sir. You have a very clear step-by-step manner explanation of the BST design. [prayer]

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd 5 років тому +1

    Perfect Video Ever On BST...Such a GlassClear Explanation...Just wanted to add here that instead of using a separate function GetNode we can manage the node creation in struct itself as below :
    struct Node
    {
    int data;
    Node* left , *rigth;
    Node(int data){
    this->data = data;
    left = right = NULL;
    }
    };
    So instead of calling method we need to do simply new Node(data);

  • @mashable8759
    @mashable8759 7 років тому

    BEST EXPLANATION, Better than all the teachers :)

  • @ismughal38
    @ismughal38 5 років тому

    we learn it here in minutes because our teachers spent hours to make base for this............very good video

  • @narayananrenganathan765
    @narayananrenganathan765 5 років тому

    Great, you make me understand my basic doubts.

  • @mumtahinaparvin7668
    @mumtahinaparvin7668 3 роки тому

    your implementation is better than my University teacher,thank you

  • @ashutoshkhairnar
    @ashutoshkhairnar Рік тому

    Thank you so much for your detail explanation.

  • @ashishkumarg5
    @ashishkumarg5 9 років тому

    very lucid, concise and clear... (:thumbs up:) ... Great work

  • @backdoorguy1
    @backdoorguy1 5 років тому

    Sir, you are doing an excellent job........
    kudos to you

  • @asadanees781
    @asadanees781 4 роки тому +1

    Really Great explanation better than my professor.
    Awesome

  • @JJLiu920
    @JJLiu920 3 роки тому

    hey i just found you, and this is crazy, but here's my like and my subscribe, because i have a feeling that you are going to save my entire module.

  • @Mari22R
    @Mari22R 7 років тому

    Thank you so much!! You are the best professor

  • @Napkinholdin
    @Napkinholdin 2 роки тому

    Nicely explained, thanks for sharing!

  • @lituhalder
    @lituhalder Рік тому

    i could not leave this vedio without giving thanks to you

  • @saraswatirathore3933
    @saraswatirathore3933 2 роки тому

    Sir I really appreciate you effort to make us clarified

  • @evilordxw
    @evilordxw 8 років тому +1

    I'd just like to say LOVED IT. THAXXXXXX

  • @MrOpxr
    @MrOpxr 9 років тому

    Very very good explanation. i finally figured it out.

  • @mohammad9934faizan
    @mohammad9934faizan 8 років тому +6

    Hey there , thanx for uploading videos. They help our group very much in understanding the complex concepts in a very easy manner. And we want a complete playlist on algorithms like the playlist of data structure that you have made.. can you please help us??

  • @poorvikaithal3380
    @poorvikaithal3380 6 років тому

    Your videos are very helpful.Thank you so much sir.

  • @Renan-st1zb
    @Renan-st1zb 8 років тому

    You are AMAZING! MANY Thanks! from Brazil :)

  • @denysehuezo4364
    @denysehuezo4364 8 років тому

    You are an amazing teacher ! thank you soo much!

  • @mariyamamreen439
    @mariyamamreen439 2 роки тому

    Thnkuu so much sir ❣️😍😍😍method of teaching is brilliant I have seen many videos on topic trees but even any single video not help me like ur video 💞💞💞again thankuu so much GOd bless uh

  • @suchonprasert5857
    @suchonprasert5857 3 роки тому

    IN 2020, You still the best teacher bro,ur teach so good

  • @neiwarecruz3519
    @neiwarecruz3519 Рік тому

    Thanks for your great effort. Great teacher!!

  • @yagmursoykan7893
    @yagmursoykan7893 2 роки тому

    Finally got it, thanks a lot

  • @vidhansharma6650
    @vidhansharma6650 Рік тому

    Lovely lesson..... very clearly explained thankyou

  • @radmehrvosoughi
    @radmehrvosoughi 5 місяців тому +1

    How simple man, thanks god we have India

  • @wvk86
    @wvk86 3 роки тому

    Very detailed explanation. Appreciate

  • @daoanhtuandao8106
    @daoanhtuandao8106 7 років тому

    your video is very useful . very clearly explained . I hope everybody seeing too .

  • @wojciechkus3010
    @wojciechkus3010 Рік тому

    10:23 double pointer part saved me thank you so much

  • @atulsharma8726
    @atulsharma8726 5 років тому

    thanks, finally i can say i understand recursion stuff in trees

  • @coldsummersky69
    @coldsummersky69 8 років тому

    This was beautiful, thank you very much

  • @gauravbansal5746
    @gauravbansal5746 9 років тому +5

    simplicity at its best

  • @DulajPasqual
    @DulajPasqual 9 років тому +3

    LEGEND !! Thanks so much

  • @RajaSekharpraveen
    @RajaSekharpraveen 10 років тому

    haw....... what a video remove all confusions in mind in single shot with in 20mins u rocks good video

  • @ediccartman7252
    @ediccartman7252 7 років тому

    Thanks a lot for the clear and detailed explanations and let me correct you a little bit. You always say, that in C we can't write, say , , but always . And the point is that you can. You have to write just once - in your definition of struct. And then after closing curly brace just write BSTNode and semicolone at the end. Since then you can write a short form - just BSTNode....blabla

  • @sarthakvaish2520
    @sarthakvaish2520 3 роки тому +1

    Best 18 min on trees

  • @jaded3404
    @jaded3404 4 роки тому +11

    there should be a button for salutation. like is not enough to express my gratitude

  • @muhammedimdaad
    @muhammedimdaad 2 роки тому

    I felt returning and updating the root nodes after every insertion could be improved. So here is my code of using pointer to pointers. BTW this series is the best content out there.
    void Tree::insert(Node **rootPtr, int elem)
    {
    Node*& root = *rootPtr; //root is an alias to what is pointed by rootPtr, now instead of using *rootPtr, can use root
    if (root == NULL)
    {
    root = getNode(elem);
    cout

  • @sneakpeek886
    @sneakpeek886 7 років тому

    Amazing explanation !

  • @tilakrathore9920
    @tilakrathore9920 7 років тому

    very good explanation, very clear, thanks

  • @waterfallw
    @waterfallw 8 років тому

    very good and concise. Thank you, good sir.

  • @LakshmikanthAyyadevara
    @LakshmikanthAyyadevara 4 роки тому

    Really great demonstration sir thanks a lot