It is very difficult to keep a topic simple and yet make it so effective for the audience! You have achieved both! Thank you Vivekanand! This video was very helpful!
@prasannachalgeri71526 жыл бұрын
Vivekanand - Very nice.. I guess if we watch all your videos "many times" then any one could crack any DSA interviews.. There are books in market but they are not as sweet as your explaination.
@aiswaryajami28413 жыл бұрын
Understood the algo in less than 2mins... you are awesome. thank you!!
@rainegreen46874 жыл бұрын
Very clear explanation! This is the first time I watched your video, will surely look for more of these.
@abhishekgautam10635 жыл бұрын
Everything is so nicely explained! Please continue making videos covering maximum topics and fields. Thanks
@prateektripathi1005 жыл бұрын
This guy is better than many of the useless books available in the market....hats off to you
@deepakpai18934 жыл бұрын
I saw a lot of solutions for this question, but yours explained it very well. Thanks.
@pradeepanand52965 жыл бұрын
First time watching... Man, u r awesome
@andreyklysheiko5006 жыл бұрын
in order to print it there's on more step - order by ascending, because if you print as is you will get a, e, f, b, i, j, c, k, d, g, h, l instead of h, d, b, i, j ..... and so on
@sachinkulkarni91084 жыл бұрын
Hi Vivekanand, The video is really nice and easy to follow. Just one question though.... in the algorithm you described, when we deque the nodes, how are we supposed to get their horizontal distance (h.d.) which is needed to update the h.d. of the left and right child nodes. We can't use the hash table mentioned as the key there is the h.d. and the value is the tree node. So, we can't lookup in the hash table with the node as the key. Wouldn't we need another hash table or some other mechanism to query the h.d. of a given node?
@amulyareddyg92904 жыл бұрын
maybe we can use a queue of pairs of .root's hd is 0 .whenever we deque a node from the queue ,we enqueue its children .So while enqueuing left child it's hd will be one less than its parent node (which we just dequed ..so we already know its hd) similarly when we enqueue its right node its hd is one greater than the parent
@Blingblingblingling6 жыл бұрын
video is nicely done. thank you. using any tree traversal should work, filling hash table during traversal. no need for a queue for BFS.
@akshaybangar70706 жыл бұрын
ist's best algo video because you solve problems in easy way.Thanks sir
@vivekgr30014 жыл бұрын
Thanks for excellent explanation! walking through the algorithm line by line!
@sekharbarua8394 жыл бұрын
Vivekanand - How do you remmember all the algo.. It is really nice .. I have followed your video and implement the same using Python..
@chaitu105525 жыл бұрын
your explanation covers everything. easy to understand. Thanks
@saileshverma73533 жыл бұрын
Awesome explanation bhaya
@pawandeepchor896 жыл бұрын
Awesome, you guys are so cool !! Keep going !!
@shreyasmahajan52913 жыл бұрын
@Vivekanand Khyade - Algorithm Every Day bhai tuch aapla dada, thank you great explanation!!]
@aanchalsharma52644 жыл бұрын
U deserves to have lakhs of views Keep going and thanks
@umeshgidnavar81967 жыл бұрын
Thanks for very good explanation. I have added code for the same for other people who want code for this algorithm. Current algorithm calculates sum of vertical column order. If just want to display vertical column order then with simple change in code we can achieve that. Thanks. import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.Queue; public class VerticalTraversalAndVerticalSum { // From root left child will have parent-1 value for horizontal distance and right child will have // parent+1 horizontal distance. Add them in hashmap checking if it is already there in hashmap // then add values or add new entry public static void main(String[] args) { TreeNode root = new TreeNode(1); root.left = new TreeNode(2); root.right = new TreeNode(3); root.left.left = new TreeNode(4); root.left.right = new TreeNode(5); root.right.left = new TreeNode(6); root.right.right = new TreeNode(7); Util.printTreeInOrder(root); System.out.println(); Map inOrderColumnSumMap = new HashMap(); findVerticalSumInorderTraversal(root, 0, inOrderColumnSumMap); System.out.println("Vertical column sum using Inorder traversal: " + inOrderColumnSumMap); Map leverOrderColumnSumMap = new HashMap(); findVerticalSumLevelOrderTraversal(root, leverOrderColumnSumMap); System.out .println("Vertical column sum using Lever order traversal: " + leverOrderColumnSumMap); } private static void findVerticalSumLevelOrderTraversal(TreeNode root, Map leverOrderColumnSumMap) { Queue q = new LinkedList(); q.add(root); Map columnValueMap = new HashMap(); columnValueMap.put(root, 0); while (!q.isEmpty()) { TreeNode current = q.poll(); int currentColumnValue = columnValueMap.get(current); if (leverOrderColumnSumMap.containsKey(currentColumnValue)) { leverOrderColumnSumMap.put(currentColumnValue, leverOrderColumnSumMap.get(currentColumnValue) + current.data); } else { leverOrderColumnSumMap.put(currentColumnValue, current.data); } if (current.left != null) { q.add(current.left); columnValueMap.put(current.left, currentColumnValue - 1); } if (current.right != null) { q.add(current.right); columnValueMap.put(current.right, currentColumnValue + 1); } } } // Using inorder keep adding horizontal distance and add sum to Map private static void findVerticalSumInorderTraversal(TreeNode root, int column, Map columnSumMap) { if (root == null) { return; } if (columnSumMap.containsKey(column)) { columnSumMap.put(column, columnSumMap.get(column) + root.data); } else { columnSumMap.put(column, root.data); } // Left child parent-1 as column value findVerticalSumInorderTraversal(root.left, column - 1, columnSumMap); // Right child parent+1 as column value findVerticalSumInorderTraversal(root.right, column + 1, columnSumMap); } } public class TreeNode { public E data; public TreeNode left; public TreeNode right; public TreeNode(E data) { this.data = data; } @Override public String toString() { return "data: "+data; } } public class Util { public static void printTreeInOrder(TreeNode node){ if(node != null){ printTreeInOrder(node.left); System.out.print("["+node.data+"], "); printTreeInOrder(node.right); } } }
@785_barneetpanda54 жыл бұрын
If you could add the code along with explanation, it helps a lot
@YogeshKumar-px5bd3 жыл бұрын
Why he has so less subscribers just because he's teaching in an old typical way. No way He definitely deserves subscriber and really good content.
@rajeshsingh-mv7zn3 жыл бұрын
Because these are old videos. He stopped uploading regularly and reach went down
@SatishKanaujiyaeb4 жыл бұрын
Very nice maza aa gya !!!
@agniswarbakshi79617 жыл бұрын
nice explanation, thanks for the video..please upload some on dynamic programming too :)
@vivekanandkhyade7 жыл бұрын
Thanks Agniswar......yes i will upload videos on dynamic programming..!
@parthsoni73703 жыл бұрын
Great Explanation! Thanks
@argharoy65714 жыл бұрын
Excellent explanation
@ivyxue64433 жыл бұрын
very good explanation!! Thank you
@MohsinKhan-sg8wq6 жыл бұрын
You Made it very easy to understand using Level order traversal.. Thank you.. But writing code for this approach is more complex because whenever you dequeue an element you need to know the HD value of that node which is not available at the time of getting node from queue. OR I am missing something ?? This can be very easy using recursion.
@saurabhvemuri53235 жыл бұрын
In CPP, You can use queue q; This will store node and its level
@travelogue45667 жыл бұрын
thank so much for nice explanation , great work and keep adding more video .
@mridulmanohar59406 жыл бұрын
Horizontal distance, Hd of each node is stored in the node itself or where? because we need the parent node's HD to compute HD for left or right child node so in a iterative loop it won't work with a local or global variable.
@dewdropk-dl5tv6 жыл бұрын
while insertng in the queue, insert with the hd, (object with node and hd for it)
@saurabhvemuri53235 жыл бұрын
In CPP, You can use queue q; This will store node and its level
@MYUCOZ17 жыл бұрын
You can also do this with Pre Order traversal of tree. No need to use Queue as extra storage. Good explanation.
@every_instant6 жыл бұрын
Pre Order travelsal + Hash will hav reverse vertical results. Therefore, to achieve top down vertical traversal (higher level nodes appear 1st) we need to traverse by level order.
@suchitragiri45464 жыл бұрын
Very nice explained sir!!
@quangluong54134 жыл бұрын
Is this possible to use preorder traversal instead of level-order traversal? My reason is because the algorithm is based on the horizontal distance of the root node to calculate for children node (which is why inorder, postorder are irrelevant)?
@vinodrammohan4 жыл бұрын
Very good explanation. However it would be better if you list the data structures that we would need to create in order to implement this solution. For example, it was not obvious that we need to create a new data structure to store the tree node along with its Hd.
@TheMihirthakkar4 жыл бұрын
Thanks for making this video. It helped me a lot :)
@mdsaif46967 жыл бұрын
Bhaiya code de do...
@ruchimishra28057 жыл бұрын
very nice explanation.keep them coming
@Shashi00124 жыл бұрын
Do hashtables allow storing same keys? as you are using hd as the key but multiple nodes have the same hd.
@saurabhverma34534 жыл бұрын
From where you are getting HD of dequeque nodes. Means when you de-queque B, how did you know that HD value for B is -1. You didn't store it anywhere, you are directly calculating it from diagram, but in programming we need to store it somewhere or not?
@nikhilm42904 жыл бұрын
If you do Level order traversal using DFS, then there you can use HD variable as a parameter in recursion. Just wondering how it can be done in BFS.
@nikhilm42904 жыл бұрын
The idea is to make (node, HD) a pair... www.geeksforgeeks.org/print-a-binary-tree-in-vertical-order-set-3-using-level-order-traversal/
@saurabhverma34534 жыл бұрын
@@nikhilm4290 level order traversal using DFS, what does it mean? DFS is for depth search not level. Can u explain it?
@saurabhverma34534 жыл бұрын
@@nikhilm4290 yeah thats what I commented that we need to store HD value of nodes.
@ok123ut4 жыл бұрын
Amazing explanation!
@ArpitDhamija5 жыл бұрын
there are difficult codes available on google , please upload a simple code here......
@keyurshah52034 жыл бұрын
Nice explaination - easy to implement
@SiddDev2 жыл бұрын
hii,thnks for this easy explanation kindly do upload videos on dynamic programming also ....
@Vj-nu5vx6 жыл бұрын
please upload algorithms for graph
@richa66954 жыл бұрын
What is the most intuitive answer to this question
@vikramlucky924 жыл бұрын
Code for leetcode 314. # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right import collections class Solution: def verticalOrder(self, root: TreeNode) -> List[List[int]]: res = [] if not root: return res seen = {} q = collections.deque() minimum = 0 maximum = 0 q.append([root, 0]) res = [] while q: n = len(q) for i in range(n): node, y_cord = q.popleft() if y_cord in seen: seen[y_cord].append(node.val) else: seen[y_cord] = [node.val] if node.left: q.append([node.left, y_cord - 1]) minimum = min(minimum, y_cord - 1) if node.right: q.append([node.right, y_cord + 1]) maximum = max(maximum, y_cord + 1) for i in range(minimum, maximum + 1): res.append(seen[i]) return res
@arun26cs6 жыл бұрын
yes vivek you are super explainatory!!!!!
@ayaan_faiz7 жыл бұрын
Great Explanation. Understood it properly. +1 Subscriber. Thanks
@successally5 жыл бұрын
Nicely explained thank you sir🙏
@shreeshametkari79637 жыл бұрын
Nice one Sir..
@vivekanandkhyade7 жыл бұрын
Thanks Amol Bhai...kasa aahes??
@smayengbam6 жыл бұрын
Thank you Sir. Well explained. I salute you 👍
@piyushjha72226 жыл бұрын
sir how to update hd and its corresponding pair in map??
@amitpadaliya69165 жыл бұрын
any idea how to put more than one value in hashmap in java
@tatianazihindula87627 жыл бұрын
at 4:43, what if node 'f' had a left child?? its child's horizontal distance could have been -1 too. any comment on this?
@MYUCOZ17 жыл бұрын
Yes
@prashantsrivastava95504 жыл бұрын
good explanation...thnx
@VivekSingh-vi3cd6 жыл бұрын
We have to sort by key to get the final result.
@Amazi0076 жыл бұрын
why not use a TreeMap?
@PrinceKumar-eb8hd6 жыл бұрын
sir, here we don't know the size of hash table so it varies from (n-1) to -(n-1), this increases the space complexity, moreover, u are inserting the values at the end in the hash table which results in the increase in time complexity. instead of inserting values in last we can insert at the beginning of the node. is there any approach i.e any dynamic implementation using doubly linklist
@GauravKawatrakir3 жыл бұрын
is it work for "Vertical Order Traversal of a Binary Tree | leetcode 987' ??
@harryinsin5 жыл бұрын
I don't think there is a strict need for level order traversal. A simple recursive inorder traversal would suffice.
@namrataojha91237 жыл бұрын
Nicely explained !!! Could you please cover some videos on dynamic programming ?
@abhishekmulay7 жыл бұрын
Thank you Vivekanand. This is a really good explanation for this problem. I have one question, why not insert the nodes in a dictionary/map while traversing the tree instead of using Queue?
@every_instant6 жыл бұрын
we need to queue up nodes so that we can traverse by level order. Other traversal algo which dont required queue such as preorder traversal, will yield reverse vertical results
@shrabanakumar77545 жыл бұрын
Sir really helpful videos. I have a request, please categorize the videos which will be helpful to go through based on topics .
@bhupalibaishya21366 жыл бұрын
it's really very nice video and the explanation is so so awesome sir !
@javi20824 жыл бұрын
Hey, the video is nice. Just a suggestion. Please start first with explaining what the question and concept is.
@TheUmar264 жыл бұрын
how to get HD of root in while loop so that can add HD for left and right child ??
@sanaullah-wu4ww4 жыл бұрын
very helpful. Thank you!
@ankitaverma22714 жыл бұрын
This video really helped me..
@karansingh-kp3xg5 жыл бұрын
Whoever asking code, did you ever google "vertical order traversal of binary tree"?
@hellostar30635 жыл бұрын
how to create a hash table
@JithendrakumarK4 жыл бұрын
@@hellostar3063 Since the KEYS we are going to store are unique, we can use unorderdMap here, which stores the unique values and it will not sort either.
@ayushthakur7334 жыл бұрын
Telephone rings at 8:35 😂😂😂😂
@EternalEntity016 жыл бұрын
please upload algorithms for m-way search tree and its different operation. your explanation is very nice.thanking u for this great job
@hussainsaifygaming7 жыл бұрын
Vivekanand your explanation was very good. I would like to know the code implementation of the above algorithm because the one which I have implemented is with the recursion. Want to know both the ways. Thanks in advance.
@muditmanchanda10626 жыл бұрын
can you please mail me
@effy12197 жыл бұрын
very clear drawing
@vivekanandkhyade7 жыл бұрын
Thanks effy..!
@kkjjllable6 жыл бұрын
Where can get the sample code?
@ANJALIGUPTA-vq1cv3 жыл бұрын
u r awesome sir
@nandinichouta41196 жыл бұрын
Can you please let us know what are the time and space complexity
@saurabhvemuri53235 жыл бұрын
TC:O(N), SC:O(N)
@rajeshd73897 жыл бұрын
What is the Time complexity for this ?
@Hiteshkumar-fn8gi7 жыл бұрын
Time complexity O(n)... Space complexity O(n) .. where n is total number of nodes in tree source -> www.geeksforgeeks.org/print-a-binary-tree-in-vertical-order-set-3-using-level-order-traversal/
@ashvinsrivastava73785 жыл бұрын
well done sir
@Mk-pg5jh7 жыл бұрын
can u upload the graph algorithm ?
@vivekanandkhyade7 жыл бұрын
Yes sure Mohan..!
@DeepakPandey7 жыл бұрын
Hi @vivekanand thanks for explanatory videos. Could you please cover trie data structures and there applications. Thanks in advance !
@vivekanandkhyade7 жыл бұрын
Thanks Deepak...video on trie data structure is coming soon...!
@DeepakPandey7 жыл бұрын
thanks @Vivekanand ... great videos..
@veerrajuyeleti85417 жыл бұрын
sir where can we get the code for this
@alqudshuriya7 жыл бұрын
Vivekanand Khyade, thank you for nice explanation.
@vivekanandkhyade7 жыл бұрын
Thanks Arham.
@familyCart6 жыл бұрын
Can anybody please tell me what would be the time and space complexity of this algorithm?
@saurabhvemuri53235 жыл бұрын
TC:O(N), SC:O(N)
@prashantnagrurkar27845 жыл бұрын
Thank you! Sir.
@tarunkr.90415 жыл бұрын
Gave idea now my turn to write code
@abhishekjain88696 жыл бұрын
awesome veere
@zenshyam4 жыл бұрын
The explanation is very good and I am able to understand it too...But i am unable to code that in java....Can someone help me with it.....Thanking you in advance..
@anjurawat92745 жыл бұрын
well explained!!!
@bhupalibaishya21366 жыл бұрын
sir, code please !
@jiangyucara6 жыл бұрын
very clear!
@sahilmotwani93104 жыл бұрын
baba tu jhakas hai
@milimishra64477 жыл бұрын
nicely explained........
@pushpitgill95454 жыл бұрын
thank you brother
@SanTosh-zg2iv5 жыл бұрын
Please find the code here github.com/santoshr1016/WeekendMasala/blob/master/itsybitsy/TreeDS/simple_tree.py
@INSPIRINGNMS7 жыл бұрын
please upload graph algorithms
@vaibhavjain90947 жыл бұрын
sir please make a video on [Print all k-sum paths in a binary tree]
@anushaghosh70544 жыл бұрын
It would have been better if you could attach the codes too
@27-Joshna Жыл бұрын
Yeah
@rakshith35475 жыл бұрын
It would have been better if you had provided the code for your algo