🔥🔥 the best part is u actually explained so calmly like one by one. and explained how the output is actually coming with that algorithm for all cases if anything will be explained like this.. concepts gonna so easy
what will be the looping condition in line by line? If it's loop till queue is not empty then in the if condition p ==null, n the enqueue statement under it will make an infinite loop.
Awesome Videos!! I still think there are many missing like finding max element in binary tree using recursion and without recursion which indeed uses LOT. Can you also try to make videos on those topics
Hope this help, but there is another simple version. # None version def horizon_level(root): if root is None: return queue = [] queue.append(root) queue.append(None) while len(queue) != 1: p = queue.pop(0) if p is not None: print(p.data) if p.left is not None: queue.append(p.left) if p.right is not None: queue.append(p.right) else: queue.append(None) return
Hi ..very good explanation..but for left and right view how do I determine the node?for left view maybe the 1st node after each null..but for right view?
Using level by level (not in one line) For the left view: the first root node and then each node just after null. For left view: Any node just before null
really it is amazing and outstanding explanation If we want to communicate with you how can we do that ? we ,a group of students from turkey ,want to take a paid course online from you hopefully you could help us all the best
Program using above algorithm:
public static void LevelOrderTrversal(TreeNode root)
{
Queue q = new LinkedList();
q.add(root);
q.add(null);
int level = 1;
while(!q.isEmpty())
{
TreeNode temp = q.remove();
if(temp != null)
{
System.out.println("Level = " + level + " value = " +temp.val);
if(temp.left != null) q.add(temp.left);
if(temp.right != null) q.add(temp.right);
}
else
{
if(q.peek() == null) break;
q.add(null);
level++;
}
}
}
Amazing great algorithms
!!!Thank you for posting this. Awesome video as always. Keep up the good work!!
Awesome Teaching Sir... You made algorithms subject easy to understand. I will be always grateful to you.
Excellent explanation Vivekanand!
thank you for step by step instructions. Makes a big difference in understanding until the end!
🔥🔥 the best part is u actually explained so calmly like one by one.
and explained how the output is actually coming with that algorithm for all cases
if anything will be explained like this.. concepts gonna so easy
Thank you sooo much man! No matter what anyone says you are awesome and the way you make things clear is amazing. Thanks again :)
Amazing explanation sir.
Really liked it👍👍🥳🥳
love the way you are explaining the things, best ds tutorials
hats off keep it up and upload videos in same manner!!
thanks a lot!!
sir where is the code?
github.com/mission-peace/interview/blob/master/src/com/interview/tree/LevelOrderTraversal.java#L19
Outstanding explanation
Very well explained sir
Awesome explanation
Thanks for the great explanation Vivekanand.
very well explained. Thank you sir .
Superb explanation
great explaination ... i was struggling to understand this
Glad to help you.
Now I did understand the algorithm on wikipedia. Thank you.
Nice Explanation!!
Thank you 🙏
Very nicely explained 👍
thankyou sir for awesome explation
Awsome logic bro👌
Very Nice and clear explanation sir :)
Great explanation.
what will be the looping condition in line by line? If it's loop till queue is not empty then in the if condition p ==null, n the enqueue statement under it will make an infinite loop.
very clear to understand .thanks
You are awesome brother. Better than G* i should say !
Clear and crisp explanation. But do it with code.
Man you're awesome seriously
Thank you sir
great explanation sir
great video sir, thanks a lot
Awesome Sir
Who is your guru? Great explaination...!
Awesome Videos!! I still think there are many missing like finding max element in binary tree using recursion and without recursion which indeed uses LOT. Can you also try to make videos on those topics
You are awesome,Dear
Hats Off Buddy....
great work, man! cheers!
Excellent explanation. Mention the codes also. It would be useful.
Good job Bro. Keep it up :)
Thanks a lot for the video
thank u
do you provide live coaching for interview preparation. ?
Thank you, Sir!
How can I store each level into an ArrayList? Not just printing them all sequential out.
For everybody who is seeking for the same answer. Here is the link:bit.ly/2HmIOm8
What's your return type look like?
thank you much vivek!!!!
thank you!
thank you so much
its really good
wonderful
thank you so much !!!!
Thankx sir, So level order traversal and BFS is same ?
osm. explanation
superb.... :)
There is much better and simple way to print level by level using recursive call collect items into map and then iterate level by level to print them
In case recursive function call is expensive , this method is suitable. The extra Queue memory is actually O(n) which is very less
Hope this help, but there is another simple version.
# None version
def horizon_level(root):
if root is None:
return
queue = []
queue.append(root)
queue.append(None)
while len(queue) != 1:
p = queue.pop(0)
if p is not None:
print(p.data)
if p.left is not None:
queue.append(p.left)
if p.right is not None:
queue.append(p.right)
else:
queue.append(None)
return
thx
❤️
If the tree node has value of type "int" , the Null solution for line by line traversal isn't gonna work.
You can enqueue -1 then
Hi ..very good explanation..but for left and right view how do I determine the node?for left view maybe the 1st node after each null..but for right view?
for right view it will be the end node at each level...
Using level by level (not in one line)
For the left view: the first root node and then each node just after null.
For left view: Any node just before null
Hi @vivekanand thanks for explanatory videos.
Could you please cover trie data structures and there applications. Thanks in advance !
How do I check for consecutive null
inside if loop, check for next element of queue to be null and break out of while loop.
check the length of the queue if len == 1 then stop the while loop, cause only None in the queue
nice..
really it is amazing and outstanding explanation
If we want to communicate with you how can we do that ?
we ,a group of students from turkey ,want to take a paid course online from you
hopefully you could help us
all the best
This is vey High Lebel thinking
great job!
Great video. Do you have code sample?
github.com/mission-peace/interview/blob/master/src/com/interview/tree/LevelOrderTraversal.java#L19
will u please implement the same in code
(Dequeue Print Enqueue ) untill queue is empty.
where do i find the code?
sir plzz also provide code for this
Iska code.....
Everything is Good.Improve English Bro.(Just suggestion)
What's wrong about his English?
Explained logic is crystal clear.....He wouldn't be working for BPO.
thank you sir
Welcome Jayram,