Level by Level Printing of Binary Tree

preview_player
Показать описание
Given a binary tree, print each level on new line.
Рекомендации по теме
Комментарии
Автор

It is such a relief brushing up things watching your videos one night before interviews :)

sandeepannits
Автор

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.

rahuldevmishra
Автор

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!

amishashahpatel
Автор

Excellent tutorials. Keep up the good work. They really help.

vgrunert
Автор

Thanks Tushar, you are very helpful as always.

ankishbansal
Автор

Awesome video as always. Keep up the good work man.

basedmangoes
Автор

Great stuff. Thank you so much for making this video.

abdallaelmedani
Автор

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.

CEngineer
Автор

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.

dibyajyoti_ghosal
Автор

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.

ANANDJULU
Автор

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

daspradeep
Автор

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 the process until your queue is empty.

DarshanWashimkar
Автор

Dudeeee! you're a national treasure!

yamanshiekhdeia
Автор

coding in python there is no poll() fun what should i do?

shobhitranjan
Автор

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.

sumitchohan
Автор

Is this same as creating a linked lists of all nodes at each depth for a binary tree??

HemaLathadaksnamurthymyfamily
Автор

Thank you for the videos. They really help. Can you also make one to find the depth of a node in a binary tree?

shivanimall
Автор

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?

skariaroy
Автор

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)

alfabinomial
Автор

Hi Tushar, could you please explain backtracking too.

rashmimishra