Reverse level order traversal binary tree

preview_player
Показать описание
Given a binary tree, print level order traversal in reverse direction.
Рекомендации по теме
Комментарии
Автор

excellent ! easily understand that binary tree algorithm combines with stack and queue template ! hopefully, make more

daqi-media
Автор

I think you were saying Queue Instead of Stack for leaf nodes from 6:00. BTW great video!

jasmeetsasan
Автор

What if you wanted to print a new line after each level. So your first example would be printed as "70 80 90 \n 40 50 60 \n 20 30 \n 10". A naive solution that comes to mind is you store vector<vector<int>> where v[0] is a vector of all elements on level 0. You can have a reverse for loop. Can't think of anything else.

arjunpassi
Автор

Hi Tushar,
nice video, thank you for all your algo video.
queue + stack approach for reverse lever ordering is better then regular level ordering and then reverse the result ?

karanpathak
Автор

Thanks alot.I was inserting left and then right child at the queue, thus struggled with the ordering of numbers 😄

hasibullah
Автор

good
plz do a video series on tips and tricks to solve problems in competitions

rohithm
Автор

How the fuck should someone come up with this without having seen it before?

arianazin
Автор

hello sir,
can you please solve this problem statement
Write a program to display value of each tree node starting from lowest node (H) till root node of the tree such that:

Each node value is displayed on a separate line.
Values of nodes are displayed from right to left e.g. in case of first level: E will be printed first before B or in case of second level, print order will be: G, F, D and C.
Values of same level nodes are displayed first e.g. all nodes of last level will be printed before second-last level.
Program should define class similar to as below given.
Main class should contain logic to output the values.
Each node should be visited only once.
please help me on this program

kanchannawkar
Автор

Sir instead of this can we use priority queue and inorder traversal technique??

khushgandhi
Автор

How did you get the idea of using a stack and a queue to solve the problem?

azharhussian
Автор

why are u first checking right child first ?

akshayjhamb