You can just keep track of even and odd levels. If the level is even pop the nodes from the back, add left and right to the front, otherwise pop the nodes from the front, and add left and right to the back. I think it's easier to think of this way, but your ways work too :)
@gauravkumarjaiswal82243 жыл бұрын
Thanks for this video...quite an easy explanation for all 3 approaches....
@DarshanWashimkar9 жыл бұрын
Thanks for the video Tushar. I think all 3 solutions are essentially same because the time and space complexity are same for all of them. Of course, it is always good to know the multiple approaches.
@subhrakabasi90162 жыл бұрын
All the 3 programs have nested while loops, so the time complexity should be O(n^2), in your github page it says O(n)
@kushal19972 жыл бұрын
Just because its nested doesnt mean we are traversing same elements multiple times right. Look at how many time we traverse a same element. Its just once so hence O(n)
@Null_pointer_exceptn9 жыл бұрын
thanks , deque way is good, didnt know abt it.
@madhukiranattivilli23213 жыл бұрын
Space complexity has to be O(2^h). How is it O(n)? (h: tree height) I mean... the max number of items in stack or queue, is from the final tree level. If it is a perfect binary tree, and if tree height is h, final level wud have 2^h nodes. We can also say this as N/2 nodes. O(N/2) is treated as O(N) -- may be Tushar is taking this way But O(2^h) feels more accurate -- as we want to use Big-O to represent worst case situation. Please comment
@muhaiminislam59317 жыл бұрын
Great videos man. For the growth of your channel I would suggest look into sound quality and lighting
@bchilakala9 жыл бұрын
Awesome explanations. Thanks for the videos. If you have time please do more dynamic programming videos.
@kalpanameena98544 жыл бұрын
Add code explination for rest two methods also, it will be very helpful.
@ameyacm7 жыл бұрын
Thanks Tushar! Very helpful.
@SHRIWALANKIT12348 жыл бұрын
Awesome Explanation
@mahadevpujari22688 жыл бұрын
if time permits upload more videos on data structure,well explained.
@ayushiajit57738 жыл бұрын
Thank you ...ur videos help me a lot :)
@sarthakrohilla81247 жыл бұрын
There will be no peace in this world until hatred exists.
@shikharchaudhary69844 жыл бұрын
interesting techniques.
@shivaniamehta98516 жыл бұрын
Sir, how should this be implemented using recursion?
@vivekgr30014 жыл бұрын
Perfect!
@saumyaaggarwal33595 жыл бұрын
wonderful!!!
@100_bindusai84 жыл бұрын
:-) Thank U😀
@srinivaspochincharla40985 жыл бұрын
Hello, I implemented the two stack technique logic for the question on leetcode. It throwing time limit exceeded.
@ChandraShekhar-by3cd4 жыл бұрын
What will be Time and Space Complexity of this Approach using Two STACK. Could someone pls explain? Thanks
@nishchaytomar98444 жыл бұрын
O(n) because we are visiting and operating every node only once.
@vigneshwaranr6804 жыл бұрын
I have one doubt. In the second approach( 1 deque) you have pushed NULL as a limiter first. NULL in an integer deque is equal to 0. So if tree has a node with data part 0, will also act as a limiter. How to overcome this ?
@anupreetsihra92294 жыл бұрын
null is not an integer
@pranayreddy63373 жыл бұрын
Well why would you create an integer deque? How can you access other elements with i.e children with integer values in deque?
@talalnabulsi70718 жыл бұрын
Would this also work with two queues instead of two stacks?