It is such a relief brushing up things watching your videos one night before interviews :)
@xVermyy5 жыл бұрын
Ayyy I'm in the exact same position lol
@Masa-lo4uw4 жыл бұрын
same here
@rahuldevmishra45587 жыл бұрын
At 7:08 - The third way - I think the variable currentCount is not necessary. The currentCount holds the count of elements present in the next level. We can get the same value from queue.size() when the levelCount becomes 0 i.e. once the levelCount becomes 0, the only elements present in the queue would belong to the next level. As you clearly explained, as long as levelCount is not 0, remove the element from the queue and add it's children. Once the levelCount becomes 0, then reset the levelCount to queue.size(). I was able to code this without using the currentCount. And thanks a lot for the video.
@amishashahpatel4 жыл бұрын
This is really very helpful. This will in fact help solving many problems like Populating Next Right Pointers in Each Node. Thank you so much!
@vgrunert7 жыл бұрын
Excellent tutorials. Keep up the good work. They really help.
@CEngineer20108 жыл бұрын
Around Time 13:27, you forgot Q1.pop and Q2.pop within your inner two while loops. Thank you for posting. Without popping the values from the queue within the two loops. It will create an infinite loop.
@dibyajyoti_ghosal4 жыл бұрын
great explanation, it's sad that you don't make videos anymore, maybe apple is not letting you. But your dp contents can be re-uploaded with more explanation on how to approach problems.
@ankishbansal4205 жыл бұрын
Thanks Tushar, you are very helpful as always.
@ANANDJULU6 жыл бұрын
Before addinga null, we need to make sure 1. we get null returned from queue and also 2. queue is not empty Else it will go in an infinite loop.
@yamanshiekhdeia47785 жыл бұрын
Dudeeee! you're a national treasure!
@basedmangoes33798 жыл бұрын
Awesome video as always. Keep up the good work man.
@abdallaelmedani89334 жыл бұрын
Great stuff. Thank you so much for making this video.
@daspradeep7 жыл бұрын
in the first 2 q approach, code can be made simpler by swapping the queues such that you are always operating on the same q
@tusharroy25257 жыл бұрын
Yes that's a good idea too.
@DarshanWashimkar9 жыл бұрын
Why do you need two queue and so many complications? BFS will print desired output. For example, use one queue, visit node(print node), put left and right child in the queue,...pop node from queue.....repeat the process until your queue is empty.
@debabhishek8 жыл бұрын
+Tushar Roy even if you want line by line the regular BFS will work.. and I Q is enough.. let me write sudo code. ( and you dont need a delimeter too). let me me write sudo code put root in Q.[ Q has 1 elment root] while ( Q is not empty) { // outer loop int loop_run=Q.size(); for ( i=0;i<loop_run;i++){ // inner loop current node = Q.enqueue(); if ( current_node.left !=null) Q.addelement( curent_node.left); if ( current_node.right !=null) Q.addelement( curent_node.right); print current_node; } // inner loop ends System.out.println(" " ); // look when inner loop ends you have printed 1 level .. // and other level elelements are in Q.so next for loop will print next level. } // outer loop ends * this is very similar to your third approach. ( I have not seen it before commenting it)
@shubhamvadhera8 жыл бұрын
+Tushar Roy It can be done using one queue only. Take the size of queue at every iteration and dequeue until current size.
@shivanimall38209 жыл бұрын
Thank you for the videos. They really help. Can you also make one to find the depth of a node in a binary tree?
@shivanimall38209 жыл бұрын
+Shivani Mall Or would this approach work? while finding the height of a tree, instead of reaching the leaf we reach the desired node and return from there.
@shivanimall38209 жыл бұрын
***** Thank you. That helps!!
@shivanimall38209 жыл бұрын
Also, do you have a video on finding a circular loop in a singly linked list? I am having troubles understanding a part of it.
@skariaroy59886 жыл бұрын
Why can’t you create an array of the same size as the queue and map each tree element to the array like we do in heap. If there is no element we can put null. Then just print from the array by skipping all Nulls?
@sumitchohan94737 жыл бұрын
It will make more sense if you use word "enqueue" and "dequeue" instead of "push" and "pop" when you work with queues. With this no need to specify if you intend to add/remove them from front/rear.
@kaivulya3 жыл бұрын
Greaaaatttt!
@CraftandDogs5 жыл бұрын
this is smart approach! Thanks \0/
@shobhitranjan39574 жыл бұрын
coding in python there is no poll() fun what should i do?
@HemaLathadaksnamurthymyfamily4 жыл бұрын
Is this same as creating a linked lists of all nodes at each depth for a binary tree??
@annastakanova11155 жыл бұрын
thanks so much!
@alfabinomial61836 жыл бұрын
sir i didnt understand that you said the time complexity is O(n) but this function is working with inner loop ..could you please explain !! i think its O(n^2)
@נדבסלמן-ט2מ8 жыл бұрын
Amazing great algorithms
@neelamchahal92995 жыл бұрын
nice t-shirt
@SatyendraJaiswalsattu8 жыл бұрын
great...
@magicodabola106 жыл бұрын
Thanks for the vid but you are using stacks and not queues. When you say pop and push it's functions of stacks, in queues it's called dequeue and enqueue. Also the "pop" that you are referring to is the LIFO type, which is stacks of course..
@rashmimishra30319 жыл бұрын
Hi Tushar, could you please explain backtracking too.
@rashmimishra30319 жыл бұрын
***** Hi Tushar sorry for confusion. I asked you to explain backtracking in general.
@xjsnjkil20706 жыл бұрын
I HIT THE LIKE BUTTON BECAUSE YOU ARE A SEAHAWKS FAN.
@ThexAzox8 жыл бұрын
ya me chantaron el rojo men :,v
@VuongGiia6 жыл бұрын
how about C++??
@vishalmishra19377 жыл бұрын
is it similar to bfs
@SahilSharma-ir7ix6 жыл бұрын
@EternalGlory66 жыл бұрын
arkadaşlar lütfen aramızda para toplayıp hocama bilgisayar alalım adam kodu tahtaya yazıyor :'(
@AdityaFingerstyle7 жыл бұрын
Using a recursive function void display(node* Ptr) { if(Root == NULL) { cout left); cout data right != NULL) display(Ptr->right); } }