Serialize & Deserialize A Binary Tree - Crafting Recursive Solutions To Interview Problems

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024
  • Code & Problem Statement @ backtobackswe....
    Free 5-Day Mini-Course: backtobackswe.com
    Try Our Full Platform: backtobackswe....
    📹 Intuitive Video Explanations
    🏃 Run Code As You Learn
    💾 Save Progress
    ❓New Unseen Questions
    🔎 Get All Solutions
    Question: Given a root node for a binary tree, serialize the binary tree into a string representation. Deserialize that same string representation into a tree identical to the original tree given.
    The key is to understand what our fundamental operation/job is in each call to the function.
    Our fundamental job is to encode/materialize a single node/int value.
    Compiler Design Phases: www.geeksforge...
    ++++++++++++++++++++++++++++++++++++++++++++++++++
    HackerRank: / @hackerrankofficial
    Tuschar Roy: / tusharroy2525
    GeeksForGeeks: / @geeksforgeeksvideos
    Jarvis Johnson: / vsympathyv
    Success In Tech: / @successintech
    ++++++++++++++++++++++++++++++++++++++++++++++++++
    Elements of Programming Interviews problem 10.13

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

  • @BackToBackSWE
    @BackToBackSWE  5 лет назад +21

    Table of Contents:
    The Problem Introduction 0:00 - 0:55
    Drawing A Parallel 0:55 - 3:19
    Deciding How To Traverse & Encode The Tree 3:19 - 4:05
    Let's Begin Crafting .serialize() 4:05 - 4:25
    Flashback 4:25 - 7:34
    Crafting .deserialize(): How Do We Track State? 7:34 - 12:29
    Can You Visualize This In Your Brain? 12:29 - 13:28
    That's All 13:28 - 14:19
    Wrap Up 14:19 - 14:59
    The code for this problem is in the description. Fully commented solely for teaching purposes.

    • @atanxellos2160
      @atanxellos2160 4 года назад +2

      Great video! Thank you a lot!
      Really liked how you described step-by-step thinking, including incorrect direction and small tips (like a queue).
      Also, noticed a mistake on deserialization code:
      ruclips.net/video/suj1ro8TIVY/видео.html
      Both pointers point to the left node, instead of left and right.

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

      ok

  • @ousmand742
    @ousmand742 4 года назад +163

    When Im stuck on a problem I say a silent prayer that BackToBack SWE has covered it on video

  • @CollectConnectDots
    @CollectConnectDots 4 года назад +3

    This world needs a teacher like you. I would suggest that you do a full time teacher and teach the next generation on how to approach the problem and think about the solution.

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

    Pls come back, you'll get this channel to 10 million ,who cares about 100k. Anyways hope ur doing good and ur one of the best teachers I've ever known!!

  • @ahmadkhaled4233
    @ahmadkhaled4233 5 лет назад +54

    thx Bro

    • @BackToBackSWE
      @BackToBackSWE  5 лет назад +6

      nice!!

    • @lilley2595
      @lilley2595 4 года назад +2

      ممكن اعرف ايه المصادر اللي درستها للمقابله

    • @BackToBackSWE
      @BackToBackSWE  4 года назад +5

      @@lilley2595 Indeed.

    • @ahmadkhaled4233
      @ahmadkhaled4233 4 года назад +5

      @@lilley2595
      Before the interview I started revising some object oriented programming from GeeksForGeeks, then I solved some SQL problems from HackerRank.
      Regarding Data structures and Algorithms u need to revise the main concepts like: linear data structures, trees, graphs and sorting. watch Back To Back SWE videos it's so simple, then you can do more practice on leetcode!

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

    I like it when the codes just pop out when you are coming out with the idea

  • @Max-zf5ot
    @Max-zf5ot 5 лет назад +3

    You are absolutely amazing. I have been going through several DS/Algo tutorials but the effort you put in making things simple and understandable is simply remarkable. At this moment, what's the deficit between the contents of your course vs the contents available in this channel?

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

      The course will be me posting materials (2-4 videos a week) and all my technical content will be there for the next 6 months or so. I'm posting more often, in more detail, & helping students in the fb group

  • @AidenLeeyong
    @AidenLeeyong 5 лет назад +32

    I really liked that you also explained mental barriers like this. I appreciate it.

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

    Your first null check in serialise is very important. I missed the delimiter while returning X and spent time finding what was wrong. So X, is very important:)

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

    One of the best explanation. One request, please make a video on "How to picturise a recursion solution". Recursive solution are easy when you see them,but to think of those solution by yourself is not that easy. Thanks in advance

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

    Its already 99.5k, dude u r close to 100k subs. Keep up the good work, well deserved!

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

      Yeah, what a ride. The internet is to be thanked.

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

      @@BackToBackSWE Ben, just a suggestion for your later videos, explain iterative solution also. I did this question with recursion and level order traversal, that way you can teach more than one concept in a question.

  • @malihaislam711
    @malihaislam711 5 лет назад +49

    Ben, your explanations are amazing! Every time I get stuck doing a problem, I just pray that you have a video on how to solve it because none of the other RUclips videos stick as well as yours do. Thank you so much for this!

  • @cornorange7622
    @cornorange7622 3 года назад +2

    Thanks a lot for the video! I am still confused by one thing, there is leetcode questions like "Construct Binary Tree from Inorder and Postorder Traversal", which means you need two serialized data array (inorder and postorder) to decide how a tree is built right? Could you please explain a bit on this? Thank you!

    • @chaupham1186
      @chaupham1186 2 года назад +1

      The difference here is that we add extra "nulls" when generating the order, allowing each tree we rebuild later on is unique. In the problem you said, there is no "null" in there, thus we need 2 orders to build the tree. For example, with preorder [1,2,3], there may be some trees that can be reconstructed, but if we add "null" to have a preorder of [1,2,3, null, null, null, null], we can only build a unique tree.

  • @saigundlapalli3548
    @saigundlapalli3548 5 лет назад +13

    I would be very interested in seeing you do a mock interview through one of these videos. Maybe grab a friend and interview each other and see how that pans out for content

    • @BackToBackSWE
      @BackToBackSWE  5 лет назад +2

      Yeah haha, Ive though of this and may do a few this Fall. I'm launching a course & will shift all my focused teaching there and may get more creative here on the channel.

  • @BikasKatwalK
    @BikasKatwalK 4 года назад +2

    Really good explanation.
    A bit confused, the serialize function, is it really a pre-order? As I see after returning from a node we are appending the left and right value to the root. It's the way you are returning that that looks like pre-order String. But instead, it is post-order traversal, right?
    Below is the per-order to return same string as yours:
    private void serializeHelper(TreeNode root, StringBuilder sb){
    if(root == null){
    sb.append("X,");
    return;
    }
    sb.append(root.val).append(",");
    serialize(root.left, sb);
    serialize(root.right, sb);
    }

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

      I don't remember the code tbh - I'd answer if I did but fast replying to comments

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

    Man, you might not the best in technical problem, but you must the be the best to articulate them! Great job. I hope(and i believe!) you can go a long way in any big name company or may become a professor in college.

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

    Superb explanation, thankyou so much

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

    You forgot to mention postorder. In languages like Rust postorder can be cleaner solution due to ownership/borrowing model. Btw could be nice if you also provide optimisation for this solution to make serialised string more compact.

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

    Great Explanation. I understood the concept very well.
    Thank You so much for the series of videos, it really helps a lot.
    Just a small correction in the serialize method - Just add extra separator "," after the leftSubtree as well.
    While returning, make the change in the code as: return root.val + "," + leftSubtree + "," + rightSubtree;
    Because if you don't add the extra "," and try to solve the leet code problem, it will give you the error for bad input String "XX3" as it won't be able to deserialize it to Integer value while creating the node.

  • @raghavgovil7665
    @raghavgovil7665 5 лет назад +8

    Hey! Thanks a ton for this video!
    Also, I was wondering whether we could use the level order traversal to serialize our tree?

    • @utsavprabhakar5072
      @utsavprabhakar5072 5 лет назад +1

      we Could . i mean yeah once we get the level, we dont know the parent of the level. we could try accessing thru smart indexing . lets say level x has 2 values. then level x+1 will have 4.
      [1]
      [2,3]
      [4,5,6,7]
      so if we are on level 2, we have 2 on index 0 and 3 on index 1.
      the children of 2(index 0) would be 0*2+0(0) and 0*2+1(1)
      the children of 3(index 1) would be 1*2+0(2) and 1*2+1(3).
      this could be a way to store. but becuase its a 2d array structure, i think a single q would be better altho the space would be same as every node appears once only.

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

      Yes you can

  • @Yagamilight19383
    @Yagamilight19383 5 лет назад +1

    What will you say if the interviewer asks you that why use PreOrder why not BFS or inorder? What are we supposed to answer?

  • @BasharAlkhalili
    @BasharAlkhalili 5 лет назад +2

    At first I used complex serialization with braces and commas and had to write my own string generator and parser. I also used index tracking when decoding.
    The code worked, but the performance was abysmal!
    Turns out that all of this could be avoided:
    - A comma for separation is enough for serialization,
    - str.split(',') is enough to turn the string into a list of tokens for de-serialization, and
    - deque(tokens) is great to hold the values. Left-popping the deque does away with the index tracking.
    Not only the code is much smaller, but the performance shot up to the 85% percentile. Genius!
    Thank you Ben.

  • @vivekkaul8445
    @vivekkaul8445 5 лет назад +2

    You need to use leftSerialized and rightSerialized instead of leftSubtree and rightSubtree

  • @fpv_am
    @fpv_am 5 лет назад +1

    I have not watched till solution yet, I feel so stupid, this is my thoughts.
    We can have not symetric tree, that's our problem, because we need to get string, which can be deserialized back, so we need to have a pattern, but what we can do with nodes that have not pair node in other side of the tree? There are 2 ways, detect them in our serialization function and put whitespase or something else at string, to make clear that there are no node.
    Or we can copy our tree and make it simetrical and put something which will indicate for deserializer that some X node does not exist .This is bad idea.

  • @TheAnilmaddala
    @TheAnilmaddala 5 лет назад +1

    Awesome video as always. Just curious, how do you synchronize what your about to say and the code/text overlay (which is added post recording) ?

    • @BackToBackSWE
      @BackToBackSWE  5 лет назад +2

      I just shoot with a loose vision for how I will edit it later. At every point in recording I have a visualization of where I am in the lesson running my head as well as where I want to go, what things I can pop in, etc.
      It is funny, there are so many tricky nuances because once it is shot...it is shot...you can't put yourself in a position where you need to "undo" what you said or wrote.
      The video is made with the end in mind, so the planned editing drives how the lesson takes shape.

  • @abhilakshsharma1275
    @abhilakshsharma1275 4 года назад +2

    When queue becomes empty and poll method returns null. calling equals() method on null will throw NullPointerException. So how this case is being handled in the code I couldn't understand. Could anyone explain this please ?

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

      I'd answer but I'm rapid replying to comments, I saw this and don't remember the code

  • @Revitalish
    @Revitalish 2 года назад +1

    so hard to understand what is actually happening in every step when you're not painting it on the board (like you did in the reversed linked list problem).. trees+recursion are tough to grasp

  • @sihatafnan5450
    @sihatafnan5450 3 года назад +2

    The way you try to emulate our thought process in our brain is amazing.

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

    I like ur ways explanation. Starting from scratch. Keep it up

  • @blasttrash
    @blasttrash 5 лет назад +2

    Put pewdiepie vs t-series in the title of your video.
    or maybe make a mini javascript game about pewdiepie vs t-series to get few subs faster. Essentially use whats trendy like what Jarvis did. One problem though is that you might lose track of what you are doing just like jarvis.
    on the other hand you can do more collabs like you did with gaurav.

    • @BackToBackSWE
      @BackToBackSWE  5 лет назад +2

      hahaha, yeah I know, I watched the Jarvis ascent to fame and took note of all the little things he did (once that 1 vid blew up he doubled down on that content type). But that's the problem...I want to stay informational too...like this whole project started because of a deeper purpose and I can't sell that out for growth (even if these videos are less scalable attention-wise).
      And yeah, collabs are a thing too. Yeah.

  • @trudyandgeorge
    @trudyandgeorge 4 года назад +2

    I just subbed. I've never before subbed when asked, it always sounds needy and annoying but somehow your totally genuine plea got me like "yeah, this dude needs subs"
    Great video mate. Keep it up

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

    3:19 pre-order traversal - DFS (null return/node/defer)
    Lintcode :www.lintcode.com/problem/serialize-and-deserialize-binary-tree/description
    BFS solution: www.jiuzhang.com/solution/binary-tree-serialization/#tag-highlight-lang-python

  • @doggo660
    @doggo660 5 лет назад +2

    Leetcode difficulty ratings make 0 sense. I've done problems where they're hard and I thought they were easy and vice-versa.

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

      yeah, difficulty is relative to absolute complication & the person themselves

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

    Can anybody explain me why the deserialisation code won't always generate a left skewed tree?

  • @atulmalakar
    @atulmalakar 5 лет назад +3

    OMG !
    Brilliant Explanation.
    And I keep saying this in every video of yours, can't help myself !

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

    Isn't the queue being passed to every recursive call kind of global state?

  • @naveenkothamasu
    @naveenkothamasu 5 лет назад +3

    IMO, level order (bfs) is more intuitive as we can work with queue in both the methods

  • @andrewcrenwelge5592
    @andrewcrenwelge5592 5 лет назад +4

    This was immensely helpful for clarifying my confusion on the details when I was trying to implement this myself. I really like how you walk through your thought process step by step. Thank you!

  • @shubhamsingh-gb5zh
    @shubhamsingh-gb5zh 3 года назад +2

    Ben, your explanations are amazing! Every time I get stuck doing a problem, I just pray that you have a video on how to solve it because none of the other RUclips videos stick as well as yours do. Thank you so much for this!

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

      Seriously. Copy pasting another comment 🤦🏻‍♂️

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

    There isn't really an explanation here as to why 'preorder' is chosen to serialize compared to the other traversals. How do we know preorder will work when deserializing compared to inorder, for example?

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

      it was arbitrary, anything can be used as long as it is reversible

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

      @@BackToBackSWE That's exactly my question, how do you know it's reversible and that it works?

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

    I think after the first deserializeHelper recursive call, the nodesLeft will be reduced to an empty queue. Where am I wrong?

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

      I dont remember

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

      @@BackToBackSWE I know where I'm wrong, whenever a null (or X) is polled from the queue, deserializeHelper will return instead of further reducing the queue. Thanks for your awesome video!

  • @TheDEMMX
    @TheDEMMX 4 года назад +2

    I remember I have seen a problem on leetcode that asked to deserialize a tree based on pre-order and in-order traversal. Looks like in-order does not really give us anything, and simply pre-order or post-order is enough to deserialize. Why would there be a variation of the problem that gives us an in-order serialization as well?

  • @kapilchhipa2143
    @kapilchhipa2143 5 лет назад +2

    nicely explained i have become fan of u.

  • @D-Daws
    @D-Daws 5 лет назад +2

    Such a high quality and complete video. The text animations really helped solidify my understanding of the solution.

  • @PankajC
    @PankajC 5 лет назад +3

    Thanks for explaining the thought process behind every step in the solution. A lot of youtubers and websites just give you the solution but in a real interview you have to express your thought process and it is more important than the actual solution. Please keep covering the thought process in your future videos too. You're doing a great job!

  • @chiranjeevipippalla
    @chiranjeevipippalla 3 года назад +1

    Problem + Fun + Solution = BackToBack SWE 👌

  • @kipa_chu
    @kipa_chu 5 лет назад +2

    Thanks, make a donation portal, maybe you can get financial help while doing this stuff.

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

      I have a Patreon but stopped promoting it. I want to focus on building products for this project for the 2nd half of 2019.

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

    I can only say thank you!!

  • @darod6098
    @darod6098 4 года назад +2

    Ben, you're incredible at explaining problems. I hope I would see this video before march 2019 when I failed an interview that was about this, but this year is going to be different!
    By the way, you did not say the Time Complexity and Space Complexity of this algorithm. If I am not wrong, it is O(N) time complexity (N = numbers of nodes of the tree) and O(H) complexity (H = height of the tree, number of levels) because of the recursion stack.
    Best wishes!

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

      thanks

    • @Paul-jx6tl
      @Paul-jx6tl 4 года назад

      why is it O(h)? I understand that recursion will take up to O(h) memory, but you have to recreate the entire tree (algorithms calls new TreeNode for every node), so it's complexity should be O(n), where n is the number of nodes. Please correct me if I'm wrong !

    • @Paul-jx6tl
      @Paul-jx6tl 4 года назад

      hmm.. or you're just talking about the additional space complexity?

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

    In the beginning you said you are going to do a Preorder traversal but i believe what you did was postorder traversal

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

      We visit node left right I believe (did this a while back) which is a preorder traversal.

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

      You serialize the left node first than right node and then merged root.val with it i am not sure how it is preorder. May be i am missing something

  • @uncaged3076
    @uncaged3076 3 года назад +1

    Glad that you achieved and surpassed your 100k goal. Thanks for your videos

  • @darod6098
    @darod6098 5 лет назад +3

    Hi there. Just to say that this question was asked to me in an interview in a big N. Thanks for your work, you are absolutely the best!

  • @wentingsong9435
    @wentingsong9435 5 лет назад +1

    What's the difference between Serialize and Deserialize BST and Serialize and Deserialize BST in terms of the strategy?

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

      what do you mean?

    • @wentingsong9435
      @wentingsong9435 5 лет назад +1

      @@BackToBackSWE Sorry, typo, I mean Serialize and Deserialize BST and Serialize and Deserialize Binary Tree

    • @BackToBackSWE
      @BackToBackSWE  5 лет назад +1

      @@wentingsong9435 Should there be a difference, what optimizations could be done for a BST? I'm thinking too, not sure what an ordering property brings to the table to beat O(n) time...since we must touch all nodes to uncover their value.

  • @NubmerSeven
    @NubmerSeven 5 лет назад +3

    Amazing stuff dude, already recommending to friends :)

  • @ashishkumarchoubey5592
    @ashishkumarchoubey5592 3 года назад +1

    Oh man! You are simply great

  • @danni6113
    @danni6113 5 лет назад +2

    Your explanation is so clean and easy to understand! New subscriber here ;)

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

    Here is the complete code.
    public class Codec {
    // Encodes a tree to a single string.
    public String serialize(TreeNode root) {
    return serializeHelper(root);
    }
    public String serializeHelper(TreeNode root) {
    if(root == null) {
    return "X";
    }
    String left = serializeHelper(root.left);
    String right = serializeHelper(root.right);
    return root.val + "," + left + "," + right;
    }
    // Decodes your encoded data to tree.
    public TreeNode deserialize(String data) {
    Queue queue = new LinkedList();
    queue.addAll(Arrays.asList(data.split(",")));
    return deserializeHelper(queue);
    }
    public TreeNode deserializeHelper(Queue nodesLeft) {
    String value = nodesLeft.poll();
    if(value.equals("X")) {
    return null;
    }
    TreeNode node = new TreeNode(Integer.valueOf(value));
    node.left = deserializeHelper(nodesLeft);
    node.right = deserializeHelper(nodesLeft);
    return node;
    }
    }

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

    And here you are in < 3 years you have > 100K subscribers. You guys are awesome!
    Edit: I am considering paid subscription is everything is explained in java?

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

    Wait, isn't the queue of node values global state?

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

    this is a very clever code where we are doing a bottom-up approach of pre-order traversal....from just looking, it will be like we are trying to do a post-order, but the way we combine string in serialize(..) is actually pre-order bottom up style.

  • @NISHANTKUMAR-mr8zj
    @NISHANTKUMAR-mr8zj 3 года назад

    Whenever I search for a problem, at the end I add "Back To Back SWE" if I don't get the video I start hating the problem. I wish if there were all the solutions that we need, recorded by you.

  • @Chaitra.Rai.
    @Chaitra.Rai. 4 года назад +1

    I just found this video and this channel, can't believe I did not come across this ever. I was stuck bad time and its a treasure, and the way you explained everything totally worth it! Thank you!

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

    well i guess the hardest part to imagine the recursion it's when you think you should compare the left or right node with the root on each time but with the representation of 1,2,x,x,3,4,x,x,5,x,x this representation where we find the x will stop the propagation to left node leading to right node thanks for the explanation

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

    This was fucking awesome, man. Interviewer will go crazy if explained like this in actuall interview. Respect Man!

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

    Hi, I want to serialize and deserialize a graph. The function serialize should give me a vector of integers and the deserialize should accept this. The graph can have cycle. Does anyone have any idea?

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

    Why can't we use the string array instead of the queue?

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

      We can do it however we can make work

  • @VigneshDhakshinamoorthy
    @VigneshDhakshinamoorthy 3 года назад +1

    You are awesome, and I see that you hit your 100k Mark! Cheers brother. Here is to a million!

  • @b9944236
    @b9944236 11 месяцев назад

    Wow, after watching your explain then I can solve this question by myself.
    Thanks a lot !

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

    You probably should have said "Another one" instead of "Next one" ))
    - Please describe Queue structure.
    - First comes and after that another one and Another One, and Another One, and Another One.....

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

    Why are we using a delimiter? Isn't a string essentially a character array and we can use an index to extract each character in the string? Somebody please explain? Why can't I store the string in a queue instead? 😭

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

    So this then should also work if you'd do a post-order or in-order traversal right? It seems to be that the key is that both serialization / deserialization need to have the same traversal.

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

    if it is an empty root, are we still returning NULL_SYMBOL + DELIMITER?

  • @abhishekprasad6691
    @abhishekprasad6691 5 лет назад +1

    Great use of data structures. Generally, the first instinct is to use a global state and when that is thwarted, I usually get flustered. This approach showed me a different way to tackle solutions. Also optimizations cz the global state would probably just add to the memory usage.

  • @pratyushpanda1985
    @pratyushpanda1985 5 лет назад +1

    Isn't this Post-Order traversal? You are recursive going all the way to left, then right and only then extracting the value of the node.

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

      Did I say that? I was speaking from the code: github.com/bephrem1/backtobackswe/blob/master/Trees%2C%20Binary%20Trees%2C%20%26%20Binary%20Search%20Trees/SerializeDeserializeBinaryTree/SerializeDeserializeBinaryTree.java#L37 - maybe I misspoke

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

    Its interesting how you don't even have to check that the queue is not empty, because your string will always end with an X

  • @9429963654
    @9429963654 5 лет назад +2

    Wow! That was so very well done. A lot of tutorials just say that "Use a Queue" and mostly don't explain "WHY". You sir, did that part and you did it beautifully! Good Luck and I hope you hit 100K subs soon! ♥️

    • @BackToBackSWE
      @BackToBackSWE  5 лет назад +1

      Haha thanks and yeah, it'll happen with time. I'm impatient.

    • @9429963654
      @9429963654 5 лет назад +1

      @@BackToBackSWE haha, cover yourself with more problems and you won't have the time to think about the sub count ;)

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

      @@9429963654 😏😏

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

    when is a video coming through?

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

    thank you so much for this tutorial. super clear and was able to solve that problem on leetcode right away.

  • @mohammednadeem333
    @mohammednadeem333 5 лет назад +1

    I really like your approach of thinking to the problem and decomposing it into steps. Thank you very much. Please keep posting such videos especially on dynamic programming which is kind off little hard. Thanks again for helping the society!!!!!! :)

  • @大盗江南
    @大盗江南 3 года назад

    There is one similar questions about binary search tree. We dont need to include null . You guys can check.it out.

  • @hassankazmi5443
    @hassankazmi5443 5 лет назад +2

    Keep up the great work my man, doing all of us of a great favor! Spread the knowledge!

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

    Create heap kind of array join with comma then create a string separated with comma easiest way to serialize and deserialize

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

    If you just represent the tree as an actual array you could just serialize the array, job done lol

  • @bibliophileanki
    @bibliophileanki 5 лет назад +1

    Great video and crisp explanation. Understood the serialization, but still trying to comprehend the deserialization. New subscribre here!! Keep up the good work.

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

    Thankx buddy, your way of explanation is awesome. Thanks once again.

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

    Clear explanation, I like it so much, can I transfer it to other websites, so that more people can see.

  • @emilyhuang2759
    @emilyhuang2759 4 года назад +2

    9:59 how is it considered as passing around state?

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

      rapid replying to comments, can't look into this I am sorry

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

    Congrats ! You acheived your goal

  • @avokadotropical3362
    @avokadotropical3362 5 лет назад +1

    In the serialize function, I think you are not actually assigning the numbers? or am I missing some point? I mean you say that the output is "1,2,X,X ... " but you don't really add in the numbers. Thanks for the vid btw, very well explained

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

    He doesn't even need to write anything, visualization does the work. Legend.

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

    Just watching this video first time, hearing you say you want 100k subscribers in a year or two, seeing the video came out 2 years ago, and seeing 188k subscribers made me happy for you

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

      Thank you, glad you liked it 😀
      Do check out backtobackswe.com/platform/content
      and please recommend us to your family and friends 😀

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

    Very clear and nice explanations dude ! You rock ! You just got a subscriber

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

    Are you doing post order traversal while creating the string during serailization?

  • @psn999100
    @psn999100 5 лет назад +1

    Thanks a ton !. One day you're gonna make a ton of money making these videos that you'd want to quit your FANG job.

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

      Hahahaha, I didn't start for that & it's be a struggle finding a way to make this work...eh...it's a pipe dream

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

    This is pure gold

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

    is there any way to communicate with you ?

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

    Congrats on 100K! Pretty big achievement on your end - big resume flex too haha

    • @BackToBackSWE
      @BackToBackSWE  4 года назад +2

      thanks - I have no interest in creating a good looking resume. I only want to make legitimate things in the world that are very large and help people.

  • @habtamuassegahegn4283
    @habtamuassegahegn4283 5 лет назад +1

    thanks for answering dont forget to add about 2-3 trees...........keep it up men its good is better from other explanations

  • @shen-yusun7683
    @shen-yusun7683 4 года назад +1

    Thank you very much! Subscribed! Also the face on 8:08 is epic

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

      What did I do - I'd prefer to not know

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

    Thank you for the video. Explanation is really good