L20. Boundary Traversal in Binary Tree | C++ | Java

preview_player
Показать описание


#treeSeries #striver #placements
Рекомендации по теме
Комментарии
Автор

Please likeeee, shareeee and :) Also follow me at Insta: Striver_79

At 04:35, i have mistakenly told inorder n written preorder. Both of them will work, its just that you need to take the first from left.. :)

takeUforward
Автор

The isleaf funtion is:

bool isleaf(Node* root){
if(!root->left and !root->right) return true;
else return false;
}

subhamengine
Автор

When i listen word as inOrder(LDR) traversal, i thought it was preOrder(DLR). Then i read comments & get to know you corrected and pinned that point, when i read more comment, i was thinking to switch from this video & look for another video for same problem. But i watch whole video & remembered that never judge a book from its cover, Although here cover is also very famous among developers in IT. 😊😊😊

rohan
Автор

For anyone wandering here is the isLeaf( ) fucntion:

bool isLeaf(TreeNode<int> *root) {
return !root -> left && !root -> right;
}

aysams
Автор

Leetcode has now added this question in their premium subscription now....but GFG is also good.. :)

pragatiagrawal
Автор

In leaf Traversal, any traversal ( Preorder, Inorder, Postorder ) will work because we are printing left subtree first before right subtree
I hope this helps 🙂

anshumaan
Автор

Coded on my own just after listening to the approach!! 🙇

parthmittal
Автор

I have done binary tree early also but they were just explaining gfg solutiions but u teach us intuition how u got the approach and all great work

magnitegame
Автор

The addLeaves function is done in PRE-ORDER form but it should be IN-ORDER.

Updated Code for addLeaves(Node root, List<Integer> ans):
Language: JAVA (change accordingly for other languages)

private static void addLeaves(Node root, List<Integer> ans) {
if (root.left != null)
addLeaves(root.left, ans); //LEFT

if (isLeaf(root)) {
ans.add(root.val); //ROOT
return;
}

else if (root.right != null)
addLeaves(root.right, ans); //RIGHT
}

tanmoychakraborty
Автор

yes Understood !!! 👏 Boundary traversal amazingly explained

shivangisrivastava
Автор

Thanks for including those questions too which required LeetCode Premium subscription.

_SOHAMSAMANTA
Автор

I solved this solution under in 38min but here im to check the approach you have used.
I didnt realize few cases so i waster around 25 min but i got the intution in under 10min after i read the question

V.The.Great.F
Автор

4:05 Correction: Inorder is left root right

somanshukadam
Автор

Bhaiya i really liked you video and your explanation... plz make a similar DP series 🙏

ayush.kumar_
Автор

Took some iterations to understand it, thanks for these awesome videos!

ashtonronald
Автор

Bhaiya your videos are great all your playlists.
Especially your DP playlist is great I was scared of DP problems but your explaination made them easy.

ShivamRaj-beoy
Автор

00:01 Discussing the anti-clockwise boundary traversal of a binary tree.
01:23 Boundary traversal of a binary tree discussed
02:36 Traversing the left boundary excluding leaf nodes.
03:46 Traversal strategy for right boundary excluding leaf nodes
05:00 Summarizing the right boundary traversal and reversing the direction
06:11 Boundary traversal in binary tree involves excluding leaf nodes and moving clockwise along the boundary.
07:27 Understanding Boundary Traversal in Binary Tree
08:39 Boundary traversal in a binary tree has O(n) time complexity
Crafted by Merlin AI.

babulalyadav
Автор

Amazing content. Very much appreciate it.

sahithchandraporeddy
Автор

Unbelievable explanation....with detailed provided ..in first go code on notepad and first go its right...confident so much... all credit goes to you only.. thank you so much and grateful to you...

pranaypatadiya
Автор

Thank you Bhaiya, you made this question really easy. Keep Going, more power to you.

abhinavdubey