INORDER SUCCESSOR in binary search tree[CODE Explained]

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ม.ค. 2025

ความคิดเห็น • 105

  • @hydraphelhd3291
    @hydraphelhd3291 2 ปีที่แล้ว +3

    The way you just explain everything 20 times over again is amazing. It really engraves the content into my mind. Great video!

    • @tori_bam
      @tori_bam 9 หลายเดือนก่อน

      I didn't understand this until i watched the video. so true! lol

  • @d0minar
    @d0minar 4 ปีที่แล้ว +7

    Probably the only explanation on TH-cam that is perfectly clear. Thank you my friend!

  • @egemen_ozturk
    @egemen_ozturk 2 ปีที่แล้ว

    I can't explain how valuable this video is. Thank you so much. Best explanation in the YT so far.

  • @syednoorullahshah9194
    @syednoorullahshah9194 6 ปีที่แล้ว +7

    awesome explaination.. i thought this topic was my full stop for the DSA course which i'm studying online until i came across ur video.. thank you so much.. i am ready to continue :) you got a new subscriber here #respect

  • @gawarivivek
    @gawarivivek 3 ปีที่แล้ว

    This is the best explanation so far on Inorder Successor. You are a great teacher. Thanks a ton!! :)

  • @dhananajaykrishna8259
    @dhananajaykrishna8259 3 ปีที่แล้ว

    Best explanation ever.... All your videos are lucid and to the point. Keep it up... Thank you

  • @arshad6027
    @arshad6027 2 หลายเดือนก่อน

    only explanation in youtube covering all the cases👍

  • @gauravsinha2077
    @gauravsinha2077 3 ปีที่แล้ว

    This is the best explanation . Awesome!! I wish all teachers were this good India would have been going greats

  • @hailemariamtamirat3125
    @hailemariamtamirat3125 4 ปีที่แล้ว

    What an explanation!! This should how professors teach teach their students. Keep it up! Thanks for uploading this well explained and organized video.

  • @gurjarc1
    @gurjarc1 6 ปีที่แล้ว

    Very nice explanation. you are one the few guys who try to explain how to think. Awesome.

  • @ankitshaw5375
    @ankitshaw5375 4 ปีที่แล้ว

    Thank you sir .Your explanations are best and i have learned a lot from you.Keep making videos like this.

  • @mmorales0113
    @mmorales0113 3 ปีที่แล้ว

    Best explanation on the web. Thanks!!

  • @tushargoel2220
    @tushargoel2220 6 ปีที่แล้ว +2

    Can you please do a series of algorithm questions for interview prep in a week. Sort of like things you absolutely need to know

  • @sunnyjain630
    @sunnyjain630 6 ปีที่แล้ว

    easy and lucid way of teaching.......!thanks

  • @abirhossainrohan8067
    @abirhossainrohan8067 5 ปีที่แล้ว +1

    sir explanation is really great

  • @linonator
    @linonator 2 ปีที่แล้ว

    This was a really good explanation. Thanks a lot

  • @ayaramzy6815
    @ayaramzy6815 3 ปีที่แล้ว

    u r amazing .. hope you land the best companies

  • @jaitehkaba8753
    @jaitehkaba8753 4 ปีที่แล้ว

    Way better than my fucking CS class at a "top" American University. He is so composed, I love it and absorbing everything .

  • @ibrahimshaikh3642
    @ibrahimshaikh3642 5 ปีที่แล้ว

    Very helpful, especially explanation with example

  • @nomanakhtar9763
    @nomanakhtar9763 4 ปีที่แล้ว

    One of the best explanation

  • @TharaMesseroux1
    @TharaMesseroux1 3 ปีที่แล้ว +1

    Thank you, Vivekanand! We appreciate you!

  • @m.mubashar786
    @m.mubashar786 3 ปีที่แล้ว

    very nice explaining sir....You rocked

  • @채서영-d4l
    @채서영-d4l 5 ปีที่แล้ว

    BEST explanation I've ever seen

  • @DOCtorActoAntohich
    @DOCtorActoAntohich 4 ปีที่แล้ว

    Thank you, this was the best material on the topic

  • @chandanagp3960
    @chandanagp3960 7 ปีที่แล้ว

    Thank you very much for the great explanation in all your videos..keep going

  • @NareshKumar-dw9xp
    @NareshKumar-dw9xp 5 ปีที่แล้ว

    Best explanation as always. Keep it up 👍

  • @therealltrader2346
    @therealltrader2346 4 ปีที่แล้ว

    very great explanations sir

  • @ArpitDhamija
    @ArpitDhamija 5 ปีที่แล้ว +1

    hi sir, can you please make more algorithms videos on trees, linked list, graphs, and some other important algorithms for interviews

  • @sumitghewade2002
    @sumitghewade2002 4 ปีที่แล้ว

    Thanks a lot for explaining so beautifully.

  • @sourabhsachdeva12
    @sourabhsachdeva12 4 ปีที่แล้ว

    Explanation work is done well but the boundary case if we have to find successor of maximum node in tree will not be handled by this algo

  • @satheshbm92
    @satheshbm92 4 ปีที่แล้ว +1

    Amazing explanation, That was a tough one :)

  • @17ANP
    @17ANP 5 ปีที่แล้ว +1

    Amazing explanation!
    Just a quick question:
    The time complexity of the solution shall be O(height) but should the space complexity be also O(height) => Recursive calls to search for the target node for BST?

  • @cricket9560
    @cricket9560 5 ปีที่แล้ว

    sir what if the user given a node which is a leaf node what will be the algo for this condition??

  • @9900shreyas
    @9900shreyas 4 ปีที่แล้ว

    Great Explanation. Respect!

  • @cindy0092
    @cindy0092 6 ปีที่แล้ว +2

    what about the case where target is 105? how to check if that is the last node of the tree?

    • @learningwithkashiftufail8990
      @learningwithkashiftufail8990 2 หลายเดือนก่อน

      If you never find a node that is a left child, then there is no successor.
      This means the node started with is the largest node in the tree.

  • @travellertripper4129
    @travellertripper4129 4 ปีที่แล้ว +1

    awesome Sirji!

  • @shivasri4112
    @shivasri4112 4 ปีที่แล้ว

    You are the best 🍁

  • @anjurawat9274
    @anjurawat9274 4 ปีที่แล้ว

    this video honestly deserves like

  • @PritamKumar-mr5dv
    @PritamKumar-mr5dv 4 ปีที่แล้ว

    best video i ever seen.....

  • @ShreyaSingh-vr9qi
    @ShreyaSingh-vr9qi 4 ปีที่แล้ว

    What if inorder succesor does not exist, suppose given node is root node and there is no right subtree for it.

  • @newanurag
    @newanurag 7 ปีที่แล้ว +1

    If we have to find the inorder successor of last node i.e. 105, then can we assume that if there is no left turn happened during the search path of node 105 then there is no successor. Kindly suggest.

    • @abuibrahym1182
      @abuibrahym1182 6 ปีที่แล้ว

      Yes there is no successor for 105

  • @hayatabadcomputeracademy4516
    @hayatabadcomputeracademy4516 4 ปีที่แล้ว

    Thanks from your explanation, which is easy to understand, a confusion is here how to find the in order successor for 36 in the above example? please help me it is much urgent for me.

  • @souvikdas7200
    @souvikdas7200 6 ปีที่แล้ว +1

    Sir what will be the output for the value 105? Here I was getting garbage value but tried to solve by means of some logic but problem is not fixed. Will you please discuss that? Thanks again.

    • @mrvenom5088
      @mrvenom5088 6 ปีที่แล้ว +1

      It should be null. Perhaps if the node is the maximum node in a bst then its successor will always be a null.

  • @anshumanjain6368
    @anshumanjain6368 4 ปีที่แล้ว

    nice explanation. thank you.

  • @elijaheinstein160
    @elijaheinstein160 7 ปีที่แล้ว

    Awesome explanation ! Thanks !

  • @ronaldweasly561
    @ronaldweasly561 2 ปีที่แล้ว

    from case 2, i do from bottom, so i start looking its successor from the key (37) than i compare it with parent and another node, final result is same 40

  • @monishajv7571
    @monishajv7571 6 ปีที่แล้ว

    Excellent Explanation

  • @rahulchudasama9363
    @rahulchudasama9363 4 ปีที่แล้ว

    awesome explaination

  • @swornimbaral9176
    @swornimbaral9176 6 ปีที่แล้ว

    Vivekanand sir would you please explain the time complexity of the algorithm also?

  • @ShivangiSingh-wc3gk
    @ShivangiSingh-wc3gk 7 ปีที่แล้ว

    If we had a parent pointer could we just do if(current node == left child of parent) then return that for case 2?

    • @paullee1171
      @paullee1171 7 ปีที่แล้ว

      Yeah I was thinking the same thing. If we had a pointer where if (currentNode TAG == 0) then just return that Link which would be the Successor, i.e. the Parent

    • @foo.1396
      @foo.1396 6 ปีที่แล้ว

      May be.

  • @abbasikov
    @abbasikov 7 ปีที่แล้ว

    You are given a list of projects and a list of dependencies ( which is a list of pairs of projects, where the second project is dependent on the first project). All of a project's dependencies must be built before the project is. Find a build order that will allow the projects to be built. if there is no valid build order, return an error.
    Input:
    projects: a, b, c, d, e, f
    dependencies: (a,d), (f,b), (b,d), (f,a), (d,c)
    Output: f, e, a, b, d, c

    • @KKV148
      @KKV148 7 ปีที่แล้ว

      Read about Topological Sorting using Stack, that would help you.

  • @MTB_Bay_Area
    @MTB_Bay_Area 2 ปีที่แล้ว

    Excellent, thank you.

  • @kabboghosh1853
    @kabboghosh1853 5 ปีที่แล้ว +1

    awesome sir

  • @agyatanonymous3995
    @agyatanonymous3995 6 ปีที่แล้ว

    Not a single dislike! Awesome!

  • @dhawalpatel3310
    @dhawalpatel3310 7 ปีที่แล้ว

    Hi vevekanand, thanks for such a wonderful explanation. You mentioned that tree cannot be reversely traversed, means backtracking. But we can achieve the same using recursion. Please let me know your thoughts on that.

  • @sachinshet6285
    @sachinshet6285 6 ปีที่แล้ว

    Sir, please use duster, rubbing the marker ink through your fingers may cause skin problems.

  • @kirankumarmv2771
    @kirankumarmv2771 4 ปีที่แล้ว

    HI Vivek,
    Can you please post the code for deletion of a node from BST?

  • @AnkitSoni-vm5od
    @AnkitSoni-vm5od 7 ปีที่แล้ว

    sir upload an video on dynamic problem;- Given arrival and departure times of all trains that reach a railway station, find the minimum number of platforms required for the railway station so that no train waits.

  • @bisuk1983
    @bisuk1983 6 ปีที่แล้ว

    very good explanation

  • @sumitnaik1990
    @sumitnaik1990 7 ปีที่แล้ว

    Like array tutorial do have any tutorial for Strings related question

  • @KnowledgeGuide859
    @KnowledgeGuide859 6 ปีที่แล้ว

    Hi Vivekananda,
    Can you please upload the video for finding all nodes at a distance k from a target node

    • @HIMANSHUCHHABRA9304
      @HIMANSHUCHHABRA9304 6 ปีที่แล้ว

      Run BFS it gives you the shortest natural distance from starting node, keep track of the distance, you can use DFS too but BFS will be easier

    • @KnowledgeGuide859
      @KnowledgeGuide859 6 ปีที่แล้ว

      HIMANSHU CHHABRA thanks . I will try it out.

  • @asokanramasamy2087
    @asokanramasamy2087 7 ปีที่แล้ว

    Nice explanation!!
    What will be the inorder successor for 105 in this example?

    • @khaledsaleh4238
      @khaledsaleh4238 6 ปีที่แล้ว

      Successor means the next higher value right? so for 105 there is no successor as this is the max value of that tree.

    • @mitcho426
      @mitcho426 6 ปีที่แล้ว

      if store pointer is null that means there was no left turns made, thus no inorder successor.

  • @foo.1396
    @foo.1396 6 ปีที่แล้ว +1

    10:19
    Great Explanation tho. (Y)

  • @muhsin98
    @muhsin98 2 ปีที่แล้ว

    Thanks 🙏 😊

  • @ajvindersingh6835
    @ajvindersingh6835 3 ปีที่แล้ว

    Thank u sir ♥️

  • @krishnodas6678
    @krishnodas6678 2 ปีที่แล้ว

    can I achieve this through recursion

  • @muzamilmehraj2529
    @muzamilmehraj2529 ปีที่แล้ว

    what about if it is an alphabets

  • @aungthiha9443
    @aungthiha9443 4 ปีที่แล้ว +1

    Thank u sir

  • @PraveenKumar-ft2kr
    @PraveenKumar-ft2kr 6 ปีที่แล้ว

    Thank you 😀😁

  • @meditationandrelaxationmus741
    @meditationandrelaxationmus741 5 ปีที่แล้ว

    Can you please show how to convert roman number to number was a interview question..

  • @prinkakumari8018
    @prinkakumari8018 5 ปีที่แล้ว

    please make video on red-black tree.

  • @tommykebede8895
    @tommykebede8895 6 ปีที่แล้ว

    nice explanation
    can we also use stack ?

    • @princebaweja4752
      @princebaweja4752 5 ปีที่แล้ว

      yeah sure...but without using stack u r able to solve this....then why do u want to use stack..

  • @AdeshPaul
    @AdeshPaul 5 ปีที่แล้ว

    Many Thanks

  • @theprshntaggrwl
    @theprshntaggrwl 4 ปีที่แล้ว

    you can ask me in comments, and I will never reply.. because he has not replied to any of the comment.

  • @thinkindependently138
    @thinkindependently138 7 ปีที่แล้ว

    I would appreciate if you can show your code for case 2. Thank you.

    • @vivekanandkhyade
      @vivekanandkhyade  7 ปีที่แล้ว

      yes sure...i have written the code on board ...but did not explain...will make a video on code explanation

  • @sumanthkumarkhajjayam6025
    @sumanthkumarkhajjayam6025 6 ปีที่แล้ว

    can you do video on
    splay trees

  • @vishalkumarchoudhary9433
    @vishalkumarchoudhary9433 6 ปีที่แล้ว

    16:30 also say that first untraversed parent

  • @MohitSingh-em1nk
    @MohitSingh-em1nk 6 ปีที่แล้ว

    Thanks sir

  • @harshbobby1911
    @harshbobby1911 4 ปีที่แล้ว

    Sir is video ka code kha milegea
    Muje code cahhiye sir pls

  • @prajakta_patil
    @prajakta_patil 5 ปีที่แล้ว

    thanks

  • @rahulraj28raj
    @rahulraj28raj 3 ปีที่แล้ว

    bhai ek request hai apse please hindi me bol liya kijiye..english teak se explain nai kr pa rhe ho ap

  • @reassume4826
    @reassume4826 6 ปีที่แล้ว

    Gem.

  • @sachinbhalla14
    @sachinbhalla14 6 ปีที่แล้ว

    Where is The Source Code

  • @sachinbhalla14
    @sachinbhalla14 5 ปีที่แล้ว

    This Logic is Not Working in all Cases

  • @payalsagar1808
    @payalsagar1808 4 ปีที่แล้ว

    wuah😃

  • @kansiram5340
    @kansiram5340 7 ปีที่แล้ว

    sir upload graph

  • @harriskhawar7901
    @harriskhawar7901 5 ปีที่แล้ว

    are you single? ;)

  • @preetijavali6595
    @preetijavali6595 9 วันที่ผ่านมา

    IHi Thank you very much for the video. It was very nice explaination. would you be able to post the code? I coded based on your explaination . 19/24 testcases are passing.
    Here is my code.
    public TreeNode inorderSuccessor(TreeNode root, TreeNode p) {
    if (root == null || (root.left == null && root.right == null)) {
    return null;
    }
    successor = null;
    prev = null;
    prev = findP(root, p);
    System.out.print(" p is " + p.val);
    // System.out.print("p.right val is " + p.right.val);
    if (p.right != null) {
    // min in the right subtree
    successor = minNode(root.right, p);
    } else {
    successor = findSucc(root, p);
    }
    return successor;
    }
    private TreeNode findP(TreeNode root, TreeNode p) {
    if (root == null || root.val == p.val) {
    prev = root;
    if(prev!=null){
    r=prev.right;
    }
    return prev;
    }
    findP(root.left, p);
    if (root.val == p.val) {
    prev = root;
    if(prev!=null){
    r=prev.right;
    }
    }
    return findP(root.right, p);
    }
    private TreeNode findSucc(TreeNode root, TreeNode p) {
    TreeNode s = null;
    while (root.val != p.val) {
    if (p.val < root.val) {
    s = root;
    root = root.left;
    } else {
    root = root.right;
    }
    }
    return s;
    }
    private TreeNode minNode(TreeNode root, TreeNode p) {
    if (root != null && root.left != null) {
    while (root.left != null) {
    root = root.left;
    }
    }
    return root;
    }

  • @shrabanakumar7754
    @shrabanakumar7754 4 ปีที่แล้ว

    very good explanation