Tree Traversal Spiral Order

  Рет қаралды 43,719

Tushar Roy - Coding Made Simple

Tushar Roy - Coding Made Simple

Күн бұрын

Пікірлер: 31
@xVermyy
@xVermyy 5 жыл бұрын
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 :)
@gauravkumarjaiswal8224
@gauravkumarjaiswal8224 3 жыл бұрын
Thanks for this video...quite an easy explanation for all 3 approaches....
@DarshanWashimkar
@DarshanWashimkar 9 жыл бұрын
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.
@subhrakabasi9016
@subhrakabasi9016 2 жыл бұрын
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)
@kushal1997
@kushal1997 2 жыл бұрын
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_exceptn
@Null_pointer_exceptn 9 жыл бұрын
thanks , deque way is good, didnt know abt it.
@madhukiranattivilli2321
@madhukiranattivilli2321 3 жыл бұрын
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
@muhaiminislam5931
@muhaiminislam5931 7 жыл бұрын
Great videos man. For the growth of your channel I would suggest look into sound quality and lighting
@bchilakala
@bchilakala 9 жыл бұрын
Awesome explanations. Thanks for the videos. If you have time please do more dynamic programming videos.
@kalpanameena9854
@kalpanameena9854 4 жыл бұрын
Add code explination for rest two methods also, it will be very helpful.
@ameyacm
@ameyacm 7 жыл бұрын
Thanks Tushar! Very helpful.
@SHRIWALANKIT1234
@SHRIWALANKIT1234 8 жыл бұрын
Awesome Explanation
@mahadevpujari2268
@mahadevpujari2268 8 жыл бұрын
if time permits upload more videos on data structure,well explained.
@ayushiajit5773
@ayushiajit5773 8 жыл бұрын
Thank you ...ur videos help me a lot :)
@sarthakrohilla8124
@sarthakrohilla8124 7 жыл бұрын
There will be no peace in this world until hatred exists.
@shikharchaudhary6984
@shikharchaudhary6984 4 жыл бұрын
interesting techniques.
@shivaniamehta9851
@shivaniamehta9851 6 жыл бұрын
Sir, how should this be implemented using recursion?
@vivekgr3001
@vivekgr3001 4 жыл бұрын
Perfect!
@saumyaaggarwal3359
@saumyaaggarwal3359 5 жыл бұрын
wonderful!!!
@100_bindusai8
@100_bindusai8 4 жыл бұрын
:-) Thank U😀
@srinivaspochincharla4098
@srinivaspochincharla4098 5 жыл бұрын
Hello, I implemented the two stack technique logic for the question on leetcode. It throwing time limit exceeded.
@ChandraShekhar-by3cd
@ChandraShekhar-by3cd 4 жыл бұрын
What will be Time and Space Complexity of this Approach using Two STACK. Could someone pls explain? Thanks
@nishchaytomar9844
@nishchaytomar9844 4 жыл бұрын
O(n) because we are visiting and operating every node only once.
@vigneshwaranr680
@vigneshwaranr680 4 жыл бұрын
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 ?
@anupreetsihra9229
@anupreetsihra9229 4 жыл бұрын
null is not an integer
@pranayreddy6337
@pranayreddy6337 3 жыл бұрын
Well why would you create an integer deque? How can you access other elements with i.e children with integer values in deque?
@talalnabulsi7071
@talalnabulsi7071 8 жыл бұрын
Would this also work with two queues instead of two stacks?
@lukitaz
@lukitaz 7 жыл бұрын
nope
@kartikprajapati5569
@kartikprajapati5569 6 жыл бұрын
Terrible handwriting... haha
Lowest Common Ancestor Binary Search Tree
4:16
Tushar Roy - Coding Made Simple
Рет қаралды 76 М.
Data structures: Binary Tree
16:17
mycodeschool
Рет қаралды 1,4 МЛН
World’s strongest WOMAN vs regular GIRLS
00:56
A4
Рет қаралды 51 МЛН
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 5 МЛН
Мама у нас строгая
00:20
VAVAN
Рет қаралды 10 МЛН
Long Nails 💅🏻 #shorts
00:50
Mr DegrEE
Рет қаралды 13 МЛН
@golfmk4-x2r whenever someone hates nature cat (sequel)
0:05
2001 volkswagen golf
Рет қаралды 32
Check if Binary Tree is Binary Search Tree
10:29
Tushar Roy - Coding Made Simple
Рет қаралды 122 М.
Morris Inorder Tree Traversal
11:44
Tushar Roy - Coding Made Simple
Рет қаралды 147 М.
L19. Zig-Zag or Spiral Traversal in Binary Tree | C++ | Java
8:21
take U forward
Рет қаралды 262 М.
Spiral (zig-zag) level order traversal of a binary tree
14:12
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 34 М.
Level Order Traversal of Binary Tree
7:57
Tushar Roy - Coding Made Simple
Рет қаралды 67 М.
How to Get a Developer Job - Even in This Economy [Full Course]
3:59:46
freeCodeCamp.org
Рет қаралды 3,2 МЛН
World’s strongest WOMAN vs regular GIRLS
00:56
A4
Рет қаралды 51 МЛН