Dear Friends, If you like our content and would like us to continue making great content for you, please spread the word about IDeserve. A share/appreciation from you on social network would mean the world to us! Also, do like our Facebook page: facebook.com/IDeserve.co.in :) Thanks, -Team IDeserve.
@TheGreatOne4287 жыл бұрын
your code is not going to work because you are not passing the value of index to the function
@DivyanshuBansal7 жыл бұрын
int index is declared globally, so it will work.
@urge-bull5 жыл бұрын
First i was thinking this question is tough...but when i saw your tutorial in comment section of geekforgeeks i found it was the easiest question on trees.Thanks to you... i was surely clear after watching this videos that what i have to do to approch solution.
@IDeserve5 жыл бұрын
You are welcome Ritik!
@divjose905 жыл бұрын
Mind blown. Best explanation and visualization on Recursive call I have come across till date. Keep it up! Looking forward to more videos.
@IDeserve5 жыл бұрын
Thanks Divya!
@saisrikar79876 жыл бұрын
Can anyone else be more clearer than this!!! What an explanation!!!..Loved it!!..Hope u make more videos!!!
@IDeserve6 жыл бұрын
Thank you so much for your kind words Sai 😀
@viralmehta25423 жыл бұрын
appreciate the efforts to explain in such such great details!!
@IDeserve3 жыл бұрын
Thanks Viral!
@learnsharegrow72945 жыл бұрын
Algorithm made easy with this video. Thanks.
@IDeserve5 жыл бұрын
Thanks Waseem!
@piyushsharma16385 жыл бұрын
Easiest way of explanation, thanks for making clear.
@IDeserve5 жыл бұрын
Thanks Piyush for your kind words!
@socialkeviv54444 жыл бұрын
I loved the serialise logic. ThankYou IDeserve. deserialise can be easy, something like below. Pseudocode // start=0; end=arr.length-1; deserialise(arr, start, end) { if(arr[left]==-1) return null; mid=start+(end-start)/2; new node root root->info=arr[start]; root-left= deserialise(arr, start +1, mid); root-right=deserialise(arr, mid+1, end); return root; } //
@abhishekkeer15204 жыл бұрын
what a explaination .thanks IDeserve ,you deserve more like.
@IDeserve4 жыл бұрын
Thanks Abhishek!
@AviatorBro4 жыл бұрын
Clear and precise explanation. Thank you
@IDeserve4 жыл бұрын
Thanks Amartya!
@akhilbhardwaj77334 жыл бұрын
tough question , but explained nicely
@hydara.r.70035 жыл бұрын
My GOD what an excellent Explanation!
@IDeserve5 жыл бұрын
Thank you so much for your kind words Hydar!
@humanbeing4964 жыл бұрын
great job explaining. appreciate it.
@IDeserve4 жыл бұрын
Thanks!
@ahmedrbii3464 жыл бұрын
@@IDeserve Why did you stop downloading videos on your channel? The last video was downloaded was in 2016
@congdoan20066 жыл бұрын
It's such an thorough explanation. However for the base case ( i.e. step 1 ), "index == array.size()" test is not needed because "index" only reaches the array size when all the function calls complete and return ( i.e. after the very first function call returns ).
@MuhammadH5 жыл бұрын
how can you do this without using a global variable index (stateless) ?
@shubhamchopra55185 жыл бұрын
pass index also in the recursive call.
@BB313074 жыл бұрын
Hi there! All the way from GFG. so i was getting this Segmentation fault without this line "pre_index %= Arr.size();". For multiple test case the new_index starts from previous value. So that's the reason we are adding this line! So, is that so or anything else. Just wanted more info.
@preetisaroha31185 жыл бұрын
Nice explanation!! Thanks for your efforts.
@IDeserve5 жыл бұрын
Thanks Preeti!
@MyLifeMyWorld085 жыл бұрын
Excellent explanation indeed !
@IDeserve5 жыл бұрын
Thanks Jitendra!
@jakubfraczek12083 жыл бұрын
Thanks, helped me a lot!
@SushilRakhonde6 жыл бұрын
There is bug in this programme, if condition in the deserialize method, if index greater than equal to array.size() then you should return immediately, else will throw exception
@SR-we1vl4 жыл бұрын
Well Delimiter used to identify "null" should be used as some random character in place of -1, cuz it will fail in case of negative numbers, viz. tree containing -1 as the value of the Tree node.
@ytuser6595 жыл бұрын
Brilliant! Thank you!
@rahuljha80388 жыл бұрын
you guys are doing great job ........ please make a video to merge n sorted linked list using heap with code in c++
@IDeserve8 жыл бұрын
Thanks Ravi :) As per your request, we will soon create a video on the requested topic. We would really appreciate if you could spread the word about IDeserve in your college and to your colleagues. Also please check out our website at: www.ideserve.co.in It has features like Algorithm Visualization, Learn Together and many more coming soon. Please check it out and leave us a comment there! Thanks, -Team IDeserve.
@rahuljha80388 жыл бұрын
yeah sure
@IDeserve8 жыл бұрын
Thanks Rahul.
@dangahng99114 жыл бұрын
Excellent!
@siddheshshirsat69048 жыл бұрын
In the deserialize() implementation, is there a way to not have variable index as global (or static to the method)? Having global variables might put the limitation of not being able to run the method concurrently in different threads.
@MrAditya49977 жыл бұрын
You can just remove the first element of the array after processing it. So element at 0 index at any time should be current element to process. No need to keeping track of index variables (if you can modify the given array)
@justinejose51116 жыл бұрын
Pass idx as an argument and pass it by reference, so that it will keep updating. (Talking about C++)
@JJ-Bond5 жыл бұрын
so this deserialization uses index as a global variable to keep track of the states, do u know if there's a way that can avoid this? thanks
@ashwani63605 жыл бұрын
you can use a queue instead of array; and the base case will be to return NULL when queue is empty or q.front()==-1
@prabhakarp98615 жыл бұрын
Thought we need atleast two traversals inorder + (pre-order / postoder) to serialising the exact tree. May be i am missing something
@JJ-Bond5 жыл бұрын
good stuff starts at 10:36
@aashitaramteke67264 жыл бұрын
Great!!!!!!!!!!!!
@IDeserve4 жыл бұрын
Thanks Ashita!
@arpit350077 жыл бұрын
Will this approach work if there are duplicates in the tree.
@3hurricane4mark76 жыл бұрын
Awesome! Walking the tree is the best way to understand recursive algorithm. I notice that by using -1 to denote null, and your code does not show value comparision, I assume it could only work for positive integers.
@prashantbhanarkar32808 жыл бұрын
proof of correctness for serialization?
@RAVIKUMAR-ef4wo6 жыл бұрын
what an explanation!!!
@IDeserve6 жыл бұрын
Thank you so much for your kind words Ravi!
@rajranjan7508 жыл бұрын
Is this solution correct My Approach If we make array reperesentation of a tree then we know that for any index the left child will be at 2*index and the right child will be at 2*index+1 so public static void serializeTree(TreeNode node,int[] arr,int index){ if(node==null){ return; } arr[index]=node.data; serializeTree(node.left, arr, 2*index); serializeTree(node.right, arr, 2*index+1); } public static TreeNode deserializeTree(int[] arr,TreeNode node,int index){ if(arr[index]==0){ return null; } node = new TreeNode(arr[index]); node.left=deserializeTree(arr, node, 2*index); node.right=deserializeTree(arr, node, 2*index+1); return node; }
@Kriishna477 жыл бұрын
I GUESS THIS WILL WORK OF COMPLETE BINARY TREE, BUT NOT FOR binary tree.
@ZiiiP21427 жыл бұрын
Raj Ranjan That idea should work as well.
@adicool006 жыл бұрын
What if the node is a negative value?
@uploder2475 жыл бұрын
Use generics then and add a character X when value is not present. You can send both preorder and inorder to construct the tree back.
@virendrasinghbais90288 жыл бұрын
very helpful. thankx
@tonyriddle76463 жыл бұрын
im having segmentation fault... anyone ? which line? /* A binary tree node has data, pointer to left child and a pointer to right child struct Node { int data; Node* left; Node* right; }; */ void preorder(Node *root, vector& res){ if(root == nullptr){ res.push_back(-1); return; } res.push_back(root->data); // cout data left, res); preorder(root->right, res); } vector serialize(Node *root){ //Your code here if(root == nullptr) return {-1}; vector res; preorder(root, res); return res; } /*this function deserializes the serialized vector A*/ int dserial = 0; Node* deSerialize(vector &A){ if(dserial == A.size() || A[dserial] == -1){ dserial++; return nullptr; } Node *root; root->data = A[dserial]; dserial++; root->left = deSerialize(A); root->right = deSerialize(A); return root; }
@tonyriddle76463 жыл бұрын
never mind ...found the error this should be the statement... Node *root = new Node(A[dserial]); I didnt know i can do that with struct too...
@ZiiiP21427 жыл бұрын
Awesome
@IDeserve7 жыл бұрын
Thanks Ádám for your kind words :) We would really appreciate if you could spread the word about IDeserve in your college and to your colleagues. Also please check out our website at: www.ideserve.co.in It has features like Algorithm Visualization, Learn Together and many more coming soon. Please check it out and leave us a comment there! Thanks, -Team IDeserve.