Find min and max element in a binary search tree

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024

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

  • @dungnguyenhoanganh4188
    @dungnguyenhoanganh4188 10 лет назад +113

    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.

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

      Dũng Nguyễn Hoàng Anh Love to Vietnam :)

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

      Dũng Nguyễn Hoàng Anh me too.

  • @FarhanAli-km5id
    @FarhanAli-km5id 3 года назад

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

  • @aswin2pranav
    @aswin2pranav 8 лет назад +52

    Doing the god's work really

  • @sasaskvorc594
    @sasaskvorc594 10 лет назад +19

    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.

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

      Saša Škvorc Thanks a lot and all the best to you :)

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

    I am devouring your course

  • @Gameplay-pq6hk
    @Gameplay-pq6hk 8 лет назад +7

    please make videos for AVL TREE , THREADED ,B-TREE .

  • @priyaravindran4337
    @priyaravindran4337 4 года назад +4

    SW Engineer for 7 years ...Computer Science graduate ...but understanding DSA concepts clearly now !! Thanks much !!

  • @ኢትዬ
    @ኢትዬ 5 лет назад +2

    You r a great teacher! Keep it up mate!

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

    Superb tutorials. What about creating a video on deleting from a BST?

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

      Owen Parkinson Yeah, I will create one on deleting node from BST. :)

  • @arunanshupadhi
    @arunanshupadhi 10 лет назад +6

    Great tutorials dude.. could you please upload a video on finding permutations of a string in c?

  • @ridershubham
    @ridershubham 10 лет назад +4

    the best tutorials!!! awsm work......plz prepare such a sereis for AVR Cprogramming...

  • @Gurl975-b9o
    @Gurl975-b9o 10 месяцев назад +1

    Can u pl tell its complexity?!

  • @jonsnow9246
    @jonsnow9246 7 лет назад +2

    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!

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

    I have decided to give you a Nobel Prize!!

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

    Why isn't the condition for while loop is not current!=null and y is it current->next!= Null?

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

    amazing explanation

  • @prestoX
    @prestoX 6 лет назад +2

    Thanks a ton Sir Kindly upload some videos on Balancing trees and AVL trees.

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

    How to call FindMin() function from main function? Which argument should I pass in FindMin() function?

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

    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?

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

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

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

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

  • @ivannav
    @ivannav 6 лет назад +3

    Thanks, great vid!

  • @sumved123
    @sumved123 10 лет назад +4

    You are awesome! :)

  • @ryklin1
    @ryklin1 8 лет назад +7

    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?

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

      That's right. But any suggestions on what we could do if we know that the B.S.T can have negative values? :)

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

      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)

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

      @@goodToBeLost XDDDD

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

    Very clean and easy to understand! Thanks!

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

    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

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

    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.

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

    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 !

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

    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.

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

      There is an assumption in this example that he described - "Tree is storing only positive numbers"

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

    i find it quite blank to test it
    anyone know?

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

    what is the time complexity of iterative and recursion approach

    • @SHIVANSHTHAKUR-cd6lv
      @SHIVANSHTHAKUR-cd6lv 3 года назад

      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.

  • @aliiqbal380
    @aliiqbal380 8 лет назад +3

    great work sir. :-)

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

    To find the maximum or minimum element we have to provide the pointer to the root node no? how is it done?

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

    How do we make sure that current -> left will actually traverse left and not right side ?

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

    int FindMin(BstNode* root) {
    if (root == NULL) return -1;
    if (root->left) return FindMin(root->left);
    else return root->data;
    }

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

      To find the maximum or minimum element we have to provide the pointer to the root node no? how is it done?

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

    Beautifully explained. Thank you so much.

  • @malathalaqrabawi7839
    @malathalaqrabawi7839 7 лет назад +3

    how to find the next min???

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

      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!

  • @MyStar970
    @MyStar970 5 месяцев назад

    Very well explained

  • @denisr.8248
    @denisr.8248 6 лет назад +1

    Good video man TXH a lot :P

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

    Please come back sir, we need you

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

    Can I get a complete C# code for this

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

    thank u🤩

  • @techwithmeareg
    @techwithmeareg 4 месяца назад

    thank you

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

    why the root in main doesn't change when we are passing the address of root in Findmin()???

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

      bcz we are passing root pointer by reference so function will have its own copy of root pointer, not affecting the original

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

    So the minimum for this problem will be 2?

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

    Very nice explanation

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

    Will it work for a right screwd tree where min element is root itself?

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

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

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

    this code won't work for all cases

  • @ShivamKendre-fc3su
    @ShivamKendre-fc3su 3 года назад

    Great video

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

    thanks chachu

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

    thank you very much, it helps me a lot!!

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

    My man.

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

    seriously awesome videos ..could u plz upload a video on graphs..

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

      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.

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

    3:14,4:11,5:34

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

    Thank u brother

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

    I am in love with your videos...awesome

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

    sdf

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

    I miss your videos sir. We all need a teacher like you. #respect

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

    kindly make a video on insert a node in bst