Top view of Binary Tree | Bottom view of Binary Tree | Binary Tree Data Structures Java | DSAOne #61

Поділитися
Вставка
  • Опубліковано 9 лис 2024

КОМЕНТАРІ • 66

  • @subhankarpal2800
    @subhankarpal2800 2 роки тому +6

    Now I can say my Nonlinear Data structure journey has been started with Anuj Bhaiya 🙏🙏🙏🙏🙏 Thank You Sir ❣❣❣❣.

  • @raghunath4280
    @raghunath4280 2 роки тому +11

    Nice solution.
    But i found out a little bit optimization for the above solution.
    Consider d= horizontal diameter of the tree.
    Building Treemap takes o(dlogd).
    Instead of TreeMap use HashMap and maintain two static variables i.e., min and max and update the min and max values as
    min=Math.min(min,temp.hd);
    max=Math.max(max,temp.hd);
    for every iteration.
    Now traverse the HM from min to max and add those values to a new ArrayList.
    This will reduce the time complexity from O(n+dlogd) to O(n)

    • @GhostRider....
      @GhostRider.... 2 роки тому

      Bro please provide full solution

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

      You're right i been thinking the same bro , use min max and hashmap

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

      bro this is correct?
      void topView(Node *root, int x, map &m)
      {
      if (root == NULL)
      return;
      if (m.find(x) == m.end())
      {
      m.insert(make_pair(x, root->data));
      }
      topView(root->left, x - 1, m);
      topView(root->right, x + 1, m);
      }

    • @jerrykodes
      @jerrykodes 6 місяців тому

      Nice one!

  • @abdullahirfan3078
    @abdullahirfan3078 2 роки тому +3

    Never knew that this medium level topic is going to be so easy for me
    Thank yoy

  • @Jitendrachouhan1999
    @Jitendrachouhan1999 2 роки тому +6

    You are Such as Good Mentor 🥰 i really inspired your video when did I watch ❤

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

    , vertical order, top view, bottom view, what an explanation ☺☺☺

  • @udaychandu3925
    @udaychandu3925 2 роки тому +2

    Very Clean and Neat Explaination,Sir!

  • @MindsetMotivation75
    @MindsetMotivation75 2 роки тому +1

    Thank you bhaiya , best explanation ever.

  • @ANJALIGUPTA-vq1cv
    @ANJALIGUPTA-vq1cv 2 роки тому +1

    awesome bhaiya, thanks for making coding easier

  • @RepublicDay2023
    @RepublicDay2023 2 роки тому +1

    You are genious dude…!!! Applauses 👌👌👌

  • @amanrathour3176
    @amanrathour3176 2 роки тому +1

    So easily explained 😍. Thanku.

  • @shreysom2060
    @shreysom2060 2 роки тому +1

    Great explaination

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

    amazing with most difficult topic

  • @tech_wizard9315
    @tech_wizard9315 2 роки тому +5

    Can you please provide a 60roamdap of important topics for DSA beginner to crack tech giant's like Microsoft linkedin etc

    • @AnujBhaiya
      @AnujBhaiya  2 роки тому +7

      This is next in line.. will be coming out soon 😄 stay tuned

  • @xerOnn35
    @xerOnn35 2 роки тому +1

    Thanks Sir !

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

    Thank you so much bhaiya mai yhi same glti kar rha tha.... thank you

  • @hangover2.0
    @hangover2.0 8 місяців тому

    for implementing the queue method we can define three variables in class third one to store level and in the if condition we will check using or operator that if the level of incoming node is lesser than the already existing node it will replace the node. Please tell me if something is wrong with this approach . Open to other suggestions.

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

    Thank you bhaiya

  • @prannoyroy5312
    @prannoyroy5312 2 роки тому +1

    Thanks Anuj! Great job bro! 👌

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

    Good Solution!

  • @GhostRider....
    @GhostRider.... 2 роки тому

    Nice explanation bhaiya

  • @anuj_abh
    @anuj_abh 2 роки тому +2

    Few days ago, bhaiya you suggested a youtube channel for learning java from scratch (u told, u also learnt from there) please give that channel link again, I forget that channel name. 🙏🏻

    • @King-xs4tq
      @King-xs4tq 2 роки тому

      Malum pada bhai

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

      @@King-xs4tq ni bhai, agr pta chale to btana

    • @King-xs4tq
      @King-xs4tq 2 роки тому +1

      @@anuj_abh Nahi bhai maine to bhaiya ke course se hi pada tha java lekin beginners ke liye utna fayde ka nahi h. Agar aapko malum padey to bataiyega

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

    Thanks bhya . I am following you

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

    Thank You Bhaiya🙏👌

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

    Maaza aa gaya 😁

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

    This video was helpful!

  • @ShivamVerma-gq2sm
    @ShivamVerma-gq2sm 2 роки тому

    wonderful

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

    Bhaiyaa DevOps par ek video banaiye isme career kaise banaye

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

    loveddddd it

  • @ImranKhan-mc6vf
    @ImranKhan-mc6vf 2 роки тому +2

    Not sure if it is the correct logic for bottom view.
    Consider this example.
    7(0)
    / \
    6 (-1) 2 (1)
    / \ / \
    5 ( -2 ) 1(0) 8(0) 2 (2)
    We have 2 0s at bottom, but the map would hold just 1 zero. So your logic would give -> 5, 8, 2 instead of 5,1,8,2.
    Or am I missing something?

    • @kumarrohit8311
      @kumarrohit8311 2 роки тому +2

      See the video at 1:07. He talks about when two elements with same distance are met, we pick the right side one. Hence, 8 is picked up!

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

      Output will like -> 5, 6, 8, 2, 2

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

    ❤❤❤

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

    what is the time complexity of this solution

  • @madetolaugh3476
    @madetolaugh3476 2 роки тому +1

    Largest BST

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

    Sir background video recorder app se user Jo video record karta hai kya vo video app Wale ke pass bhi store hota hai kya
    Kya ye possible hai ki Jo video hum record karte hain vo app Wale ke pass bhi store hota hai kya

  • @wizardiors
    @wizardiors 2 роки тому +1

    did u have a computer science degree??

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

    Bhaiya, TreeMap nahi use karke, Map ko sort kardein end me to kaam nahi banega ? :( (Not sure how to implement Treemap in javascript)

  • @mastimazawithnature6749
    @mastimazawithnature6749 2 роки тому +1

    Is dsa course me kya sikhne ko milega

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

      You'll learn almost anything there's to learn about Data Structures & Algorithms so that you can crack Top companies technical interviews easily. Many of you have already done it. Best of Luck 🤗

  • @rahulji882
    @rahulji882 2 роки тому +1

    22nd link

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

    many teachers can't even accept their mistakes

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

    ❤️❤️

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

    why we don't take preorder traversal for bottom view , kindly give a tree example where preorder traversal gives wrong answer.

  • @mohakarora8712
    @mohakarora8712 8 місяців тому

    can somebody tell me why are we using level order only?

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

    time complexity?

  • @lakhanshanker6105
    @lakhanshanker6105 2 роки тому +2

    static ArrayList topView(Node root)
    {
    Map map = new TreeMap();
    int i=0;
    util(root,i,map);
    ArrayList ans = new ArrayList();
    for(Map.Entry m : map.entrySet()){
    int x = m.getValue();
    ans.add(x);
    }
    public static void util(Node root, int i, Map map){
    if(root==null)
    return;
    if(!map.containsKey(i)){
    map.put(i,root.data);
    }
    util(root.left,i-1,map);
    util(root.right,i+1,map);
    }
    isme kya galti hai anyone ?

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

      ans.add(x);
      }
      }
      you need to close extra } , :P
      Otherwise check the video again on 04:05, where Anuj Bhaiya explains why normal traversal (preorder) will fail

    • @lakhanshanker6105
      @lakhanshanker6105 2 роки тому +1

      @@pratikvishwakarma1599 bhai wo to thek h pr sare test cases pass nhi ho rhe

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

    Binary code kya hota hai
    Kya isse me kya kr sakta hu

  • @RajatGupta-lq3cb
    @RajatGupta-lq3cb 2 роки тому +2

    Can someone help me. What if we solve it in this way using DFS?
    class Solution
    {
    static int min=0, max=0;
    static ArrayList topView(Node root)
    {
    ArrayList res=new ArrayList();
    Map mp=new HashMap();
    helper(root, mp, 0, 0);
    for(int i=min;i vd)
    {
    mp.put(hd, new Pair(root.data, vd));
    }
    }
    else
    {
    mp.put(hd, new Pair(root.data, vd));
    }
    helper(root.left, mp, hd-1, vd+1);
    helper(root.right, mp, hd+1, vd+1);
    }
    }
    class Pair
    {
    int val, vd;// vd represents vertical distance from root AKA depth.
    public Pair(int a, int b)
    {
    val=a;
    vd=b;
    }
    }

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

      It will be complicated bro but it's your choice how you want to do 😊

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

    Thanks bhiya

  • @mma-dost
    @mma-dost 3 місяці тому

    Thanks bhaiya