Binary Tree - Constructor | Data Structure and Algorithms in Java

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 พ.ย. 2024

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

  • @VanBhardwaj
    @VanBhardwaj 3 ปีที่แล้ว +28

    Why is this channel so underrated?? You are an amazing teacher. I love how you enjoy every bit of it while teaching. I've been binge watching your playlists for around 5 hours at 2X today. I miss learning like this. Thanks for the efforts, Sir! :)

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว +7

      Glad to know that you liked the content and thank you for appreciating. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem. If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
      Keep learning and keep loving Pepcoding😊

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

      Bhai yahi sawal muzi bhi padta hai har roj

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

    awesome! Thank you so much, there are very less tutorials on net which focus ds on java

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว +2

      Glad it was helpful!

  • @keshavbadhekar
    @keshavbadhekar 3 หลายเดือนก่อน

    one more correction in the code. whenever we are checking if(arr[idx]!=null), add one more check that if idx

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

    Thank you so much Sir the way you teach in a calm manner is so soothing and I just love your content thank you may God bless you

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

    last one week se confuse or frustrated ghum reha tha Btree ke liye or yeha mere doubt solve hogye..........waah ........... ye hota hai asli content bakki toh bas ad krte rehte hai

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

    Thank You So Much Sumeet Sir...............................🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

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

    you are amazing sir & your way of teaching & explaination is superb thankyou so much sir😍🤩

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

    Thanku sir
    you makes the things easy
    It is my first time i learnt binary tree
    and it was awesome to learn from you

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

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @rajamanoj1918
    @rajamanoj1918 2 ปีที่แล้ว +1

    Sir, can you please tell me if there are any issues if I use this code. Thanks in advance
    static int idx = 1;
    public static Node constructTree(Node root, int[] arr){
    if(root.data == -1){
    return null;
    }
    Node l = new Node(arr[idx++],null,null);
    root.left= constructTree(l,arr);
    Node r = new Node(arr[idx++],null,null);
    root.right= constructTree(r,arr);
    return root;
    }

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

    sir coding blocks mai prateek bhaiya se padha tha and aapne extra class li thi attend nahi kar paaya tha . mujhe nahi pata tha aap itna awsome padhate ho.

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

      Koi nh beta, ab yha se pdd lo. If you like our efforts, will you like to review us here - g.page/Pepcoding/review?rc

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

      @@Pepcoding done sir

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

    How to create a binary tree non recursively using linked list and stack ? inputs to be taken from user. Hope you will reply

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

    Excellent

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

    you are gifted!

  • @40_it_hardeepsingh50
    @40_it_hardeepsingh50 2 ปีที่แล้ว +1

    please can you give c++ codes also

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

    Gazab explanation sir

  • @jatinbhatoya8420
    @jatinbhatoya8420 2 ปีที่แล้ว +1

    public static class Pair {
    Node node;
    int state;
    public Pair(Node node, int state) {
    this.node = node;
    this.state = state;
    }
    }
    public static Node takeInput(Integer arr[]) {
    if (arr.length = 3) st.pop();
    } else {
    Node nn = new Node(arr[i]);
    if (st.peek().state == 1) st.peek().node.left = nn;
    else if (st.peek().state == 2) st.peek().node.right = nn;
    st.peek().state++;
    if (st.peek().state >= 3) st.pop();
    st.add(new Pair(nn, 1));
    }
    }
    return root;
    }

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

    Sir one thing I want to ask
    Can we take user input for left and right nodes of BINARY TREE

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

    sir apki trees ki level 2 ki playlist hai to plz share your link nahi mil rahi playlist mujhe

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

    sir why don t we use linked list in constructing trees ,becoz in arrays memory is wasted a lot?

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว +2

      you can use linked list

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

    Just wanted to know....does this method work only for BST ?

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

      Nahi beta, thora alg h BST ka.

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

      @@Pepcoding iss method se hum sirf pre order traversal ki help se tree construct kr skte hain na sir?

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

    Sir please upload the question set of trees on the pepcoding website. There are no questions of trees available.

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

      hanji, abhi content pichle 3 din se nya nahi bna hai. ye old upload ho rha hai. wo question bhi dalte hain soon

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

      @@Pepcoding Ok sir. Very helpful videos. Thank you sirr!!

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

      We are glad. Keep watching.

  • @Rohan-rz2qn
    @Rohan-rz2qn 2 ปีที่แล้ว

    Sir cpp me NULL nahi kr sakte toh kya karen usme

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

      java use kare

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

    Sir ye opps bahut prblm create ker rha hai sangh nhi aa rha hai

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

      Class object, constructor, this bs itna hi use hora h ye main oops thori h uper layer h.

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

      @@anjneykumarsingh4461 ha bro aa gya sab maine khud se meditate kiya to ekdum clear ho gya

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

    did anyone actually try to write the code and see if it works? cause it clearly doesn't! the array index needs to be incremented even when we are setting null.
    please at least mention the correction in the comment section.

    • @sounak_dey
      @sounak_dey 3 ปีที่แล้ว +6

      idx++
      has been done outside of the if-else statement, so it gets incremented in both the cases.
      This code works fine for me.
      please at least double-check before ranting!

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

      its done already...it has to be done just once...its better to do it outside if else.....for easier tracking rather than doing it individually for both if part and else part..

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

      - Make arr[0] as the root node and push in the stack with flag=1
      - int i=0 // to traverse in the preorder path array
      - while the stack is not empty:
      - For stack top element
      - If flag =1
      - i++
      - increment the flag value of the stack top node
      - If arr[i] is not null then
      - connect arr[i] to the left of the stack top node
      - push pair(arr[i], 1) to the stack
      - else if flag = 2
      - i++
      - increment the flag value of the stack top node
      - If arr[i] is not null then
      - connect arr[i] to the right of the stack top node
      - push pair(arr[i], 1) to the stack
      - else if flag = 3 then pop the stack