Level Order Traversal , Sum at Kth Level In Binary Tree | C++ Placement Course | Lecture 27.5

  Рет қаралды 127,673

Apna College

Apna College

Күн бұрын

Пікірлер: 108
@sleepypanda7172
@sleepypanda7172 3 жыл бұрын
Thank-You :) you guys are great! Sharddha didi's Explanation is just awesome! Thanks again
@abhijeetkumarjha8137
@abhijeetkumarjha8137 3 жыл бұрын
I had no confidence in coding when I had begun this course and also hated coding , it was like a burden to me. But now after almost a month I have reached a level where I only want to code . All thanks to this amazing playlist by Apna College channel.
@rahuldasari1886
@rahuldasari1886 3 жыл бұрын
+1
@neerajkumarsingh4721
@neerajkumarsingh4721 3 жыл бұрын
The Hardest part is yet to Come :)
@shivangbhardwaj3165
@shivangbhardwaj3165 3 жыл бұрын
bro yo ufinished 97 videos in a month? how do you keep the consistency please help
@harshhcode
@harshhcode 3 жыл бұрын
@@shivangbhardwaj3165 same question !!!
@dehlanshandirkayr6182
@dehlanshandirkayr6182 2 жыл бұрын
@@shivangbhardwaj3165 3 videos a day :)
@vikasmane8851
@vikasmane8851 3 жыл бұрын
i appreciate all hardwork of apna college Team Huge respect to you guys
@rahultripathi591
@rahultripathi591 3 жыл бұрын
bro do you know where can I have notes of lectures that are not in the description.
@melodytunes2204
@melodytunes2204 3 жыл бұрын
@@rahultripathi591 bro agar pta chale toh mujhe bhi btadiyo
@arky1923
@arky1923 2 жыл бұрын
This is a quite optimized and straightforward approach if anyone needs it void Level_order(node* root){ if(root==NULL){ return; } queue q; q.push(root); while(!q.empty()){ node* temp = q.front(); cout data left)q.push(temp->left); if(temp->right)q.push(temp->right); } } // call by Level_order(struct node* root);
@vivek_1300
@vivek_1300 Жыл бұрын
wonderfull explanation didi
@shubhamkumar9313
@shubhamkumar9313 Жыл бұрын
Awesome, I have been watching lot of other YT videos, not able to understand. But this pictorial presentation is really helpful.
@SaurabhKumar-tm4er
@SaurabhKumar-tm4er 3 жыл бұрын
Nice way to understand all of us didi thanks
@girishporwal5183
@girishporwal5183 3 жыл бұрын
Didi u are the best. Ty Team AC
@vidhanpatni8338
@vidhanpatni8338 Жыл бұрын
2:25 you can hear the cooker whistling here lol;
@dhruvsakariya3129
@dhruvsakariya3129 2 жыл бұрын
Thank You this is very intuitive approach
@amanrathore3610
@amanrathore3610 Жыл бұрын
Very nice exxplaination and video editing,tqs shradha di
@sanyazaveri4511
@sanyazaveri4511 2 жыл бұрын
Very nicely explained. Thank you!
@BECRIZWANkhan
@BECRIZWANkhan 2 жыл бұрын
Great work by apna college
@dhruvarora8136
@dhruvarora8136 Жыл бұрын
best explanation ever. thanks to those animations
@anishsingh9043
@anishsingh9043 Жыл бұрын
If someone is confused. Most basic approach. You just optimize as you want. Just to explain what she did in an elaborated way. while(!q.empty()){ while(q.front() != NULL){ Node* node = q.front(); coutleft); } if(node->right){ q.push(node->right); } q.pop(); } q.pop(); if(!q.empty()){ q.push(NULL); level++; } } cout
@chinnu9772
@chinnu9772 Жыл бұрын
Concept and explanation into deep, tq!!
@Kaushik846
@Kaushik846 Жыл бұрын
Superlike very nice explanation
@yashchampaneri1972
@yashchampaneri1972 3 жыл бұрын
Pls provide Notes of all lecture which is not provided till yet!
@RajanGupta-fj8fi
@RajanGupta-fj8fi 2 жыл бұрын
Didi you are great
@murapovyerkhan2439
@murapovyerkhan2439 2 жыл бұрын
Thanks brothers
@harsh.8436
@harsh.8436 3 жыл бұрын
It was a great class!!!! Can we access notes of this lecture?
@santoshbhupati3579
@santoshbhupati3579 3 жыл бұрын
thank you so much
@MindMunchies.
@MindMunchies. 2 жыл бұрын
thank u dii
@shikhamaurya4453
@shikhamaurya4453 3 жыл бұрын
All I can do is not skipping the Ads and say "Dhanyawaad" to apna college team.😊
@anirudhrajebhosle4286
@anirudhrajebhosle4286 2 жыл бұрын
Aman bhaiya nai apna channel monetize nahi kiya hai. Ad dekho yha na dekho usse Aman bhaiya ko koi farak nahi padega.
@RAMANKUMARGCEBIT
@RAMANKUMARGCEBIT 2 жыл бұрын
very helpful
@sudipc9880
@sudipc9880 3 жыл бұрын
Thanks
@raaz7841
@raaz7841 2 жыл бұрын
if we need sum of kth level only then why we traversing to the last node , we can traverse only up to kth level then break out, there is chance of improvement in this code, please look into this.
@768_sakshisharma9
@768_sakshisharma9 3 жыл бұрын
please make more videos as such
@HimanshuSingh-zu4ht
@HimanshuSingh-zu4ht 3 жыл бұрын
better solution for sum at kth level (just for different approach) void sum(node* root,int k,int* ans){ if(root == NULL){ return; } if(k == 1){ *ans += root->data; } sum(root->left,k-1,ans); sum(root->right,k-1,ans); } int main(){ node* root = new node(1); root->left = new node(2); root->right = new node(3); root->left->right = new node(5); root->left->left = new node(4); root->right->right = new node(7); root->right->left = new node(6); int ans = 0; sum(root,1,&ans); cout
@abhishek.rathore
@abhishek.rathore 3 жыл бұрын
Can't say its better as recursive solutions are generally slower than iterative ones.
@aryanagarwal2071
@aryanagarwal2071 3 жыл бұрын
@@abhishek.rathore BFS vs DFS u cant say which one is better
@chickmagnet2067
@chickmagnet2067 3 жыл бұрын
@Himanshu Singh agreed.
@pk4288
@pk4288 3 жыл бұрын
there will be k+1 in one of the sum(....)
@PradeepSingh-tq7kg
@PradeepSingh-tq7kg 3 жыл бұрын
listen vro k==1 vaali loop me return laga de acha rahega varna k negative hota jaayega until last level jo kisi kaam ka nahi hai................
@hassankhan2698
@hassankhan2698 2 жыл бұрын
Use an optimised approach no need to insert null at the beginning not the the end of while loop. Simple use while loop until the queue is empty.
@aishiksarkar8226
@aishiksarkar8226 2 жыл бұрын
class Solution { public: vector levelOrder(TreeNode* root) { vectorv(0); vector v1; if(root==NULL) return v1; queueq; q.push(root); q.push(NULL); while(!q.empty()) { if(q.front()!=NULL) { // coutleft); if(q.front()->right!=NULL) q.push(q.front()->right); q.pop(); } else { v1.push_back(v); v.clear(); q.pop(); if(q.empty()) return v1; else q.push(NULL); } } return v1; } }; LeetCode Solution
@sasuke3737
@sasuke3737 3 жыл бұрын
push karrenge peeche se
@siddharthlokesh9896
@siddharthlokesh9896 3 жыл бұрын
What is the significance of int 32_t main(), Someone pls explain
@PradeepSingh-tq7kg
@PradeepSingh-tq7kg 3 жыл бұрын
@@mr.darkheart2979 yes
@PradeepSingh-tq7kg
@PradeepSingh-tq7kg 3 жыл бұрын
simple int can be 16 or 32 bit which depends on compiler to compiler but int32_t is always of 32 bits and there is one more type int_fast32_t this serves as the name hints
@niazi74
@niazi74 2 жыл бұрын
Notes of Level order traversal????
@saurabhshandilay8261
@saurabhshandilay8261 3 жыл бұрын
Bhai moj kar di
@alveenamasub8499
@alveenamasub8499 3 жыл бұрын
Million dollar content
@raaz7841
@raaz7841 2 жыл бұрын
notes link?
@MaheshPatil-of1zy
@MaheshPatil-of1zy Жыл бұрын
Why this problem cant solved using recursion?
@ogbuddha7835
@ogbuddha7835 3 жыл бұрын
Queue declare krne pe error aa rha h
@pradeepasktkar4330
@pradeepasktkar4330 3 жыл бұрын
😊😊
@vaibhavsharma4500
@vaibhavsharma4500 3 жыл бұрын
Thank you 🙏🙏
@ayush_b_59
@ayush_b_59 3 жыл бұрын
Can anyone tell me "apna college" channel is giving course of full stack developer? Please
@sleepypanda7172
@sleepypanda7172 3 жыл бұрын
try to ask on his mail. & ya be formal and nice to get a quick reply. CHEERS
@tanmaiysethiajain4367
@tanmaiysethiajain4367 3 жыл бұрын
gfg with animation
@gauravkulkarni6925
@gauravkulkarni6925 3 жыл бұрын
Does anyone know Why are we writing queue Q; What does Node* mean and whats the difference in queue *q …..in short I want to ask * bracket ke Andar Q ha ?.?
@AakashYadav-ri1pt
@AakashYadav-ri1pt 3 жыл бұрын
in queue Q , node* is the data type of queue
@tiger20studio80
@tiger20studio80 3 жыл бұрын
😀
@sachinbairi6353
@sachinbairi6353 3 жыл бұрын
void levelOrder(Node* root){ queue q; q.push(root); while (!q.empty()) { Node* curr = q.front(); q.pop(); coutright) q.push(curr->right); } }
@gauravkulkarni6925
@gauravkulkarni6925 3 жыл бұрын
Why are we writing queue Q; What does Node* mean and whats the difference in queue *q …..in short I want to ask * bracket ke Andar Q ha ?.?
@sachinbairi6353
@sachinbairi6353 3 жыл бұрын
@@gauravkulkarni6925 bro humko ek queue chahiye to store the pointer to our tree Nodes thats why we are doing queue q and not queue *q
@palashpadiya2792
@palashpadiya2792 3 жыл бұрын
My queue is not working
@loser0023
@loser0023 3 жыл бұрын
@@gauravkulkarni6925 bhai basically queue is a container hence we need to specify what are we storing i to , for example say , maybe int or string , here we have defined our own structure node* , which species its clas , hence we specify it using queue same as we do in the case of queue
@shadowmonarch3155
@shadowmonarch3155 2 жыл бұрын
can you tell why we use Node*curr=q.front();
@SubhamKumar-fr7gw
@SubhamKumar-fr7gw 3 жыл бұрын
har video me poora bhar bhar ke paikhana kar deta hai
@RohitSingh-se6ch
@RohitSingh-se6ch 3 жыл бұрын
guys lne 26 q.pop() kyu kiya
@pushprajsinghjadoun2229
@pushprajsinghjadoun2229 3 жыл бұрын
kyu ke jo value print kar de hai vo value queue se hatane padhe ge
@nitishsingh3470
@nitishsingh3470 3 жыл бұрын
Amazing
@harpic949
@harpic949 3 жыл бұрын
Ma panner khaunga
@palashagrawal2343
@palashagrawal2343 3 жыл бұрын
y used NULL concept at first to make it more complicated? We can just simply avoid that NULL to traverse
@revanth6476
@revanth6476 3 жыл бұрын
to just make you understand different problems on traversal. it will help you @palash Agrawal
@thunderstrm4028
@thunderstrm4028 3 жыл бұрын
it will help you in to find the left view and right view of the binary tree
@darshanpagar1894
@darshanpagar1894 3 жыл бұрын
can you please give code for sum at kth level without using null
@ronakgarg7569
@ronakgarg7569 3 жыл бұрын
Didi aapne dimaag khol diaa
@Pragma_Solidity
@Pragma_Solidity 3 жыл бұрын
why are we using NULL in order traversal? i mean code runs same without pushing NULL
@gauravupreti9340
@gauravupreti9340 3 жыл бұрын
Yeah, no need for NULL in this, they did it so that if you want to print binary tree line by line, then you can use NULL to do that.
@PradeepSingh-tq7kg
@PradeepSingh-tq7kg 3 жыл бұрын
if u want to keep track which level u reached
@Funprince1411
@Funprince1411 3 жыл бұрын
Good evening mam..
@srizwan789
@srizwan789 Жыл бұрын
abhi thak mam ne reply nahi diya apko....🙂🙂
@adityanarayanjaiswal890
@adityanarayanjaiswal890 3 жыл бұрын
26000
@stylishstarrohan9616
@stylishstarrohan9616 3 жыл бұрын
mujhe 1 ande vala burger
@saurabhshandilay8261
@saurabhshandilay8261 3 жыл бұрын
Koi notes bhi upload kr do😭
@rutvikrana512
@rutvikrana512 3 жыл бұрын
In Level Order Traversal, If We Dont want to know nodes with level than simple use queue without using NULL at all. void levelOrder(Node* root){ queue Q; Q.push( root ); while( !Q.empty() ){ std::cout data left ) Q.push( Q.front() -> left ); if( Q.front() -> right ) Q.push( Q.front() -> right ); Q.pop(); } } In Second Question We Can Simply Do Recursive InOrder Traversal with Height ... void inOrder(Node* root, int height, int& K, int& answer){ if(height > K) return; if(root -> left) inOrder( root->left, height+1, K, answer ); if(height == K) answer+=root->data; if(root -> right) inOrder( root->right, height+1, K, answer); } int sumAtK(Node* root, int K){ int answer = 0; inOrder( root, 0, K, answer); return answer; }
@epic_amvs4095
@epic_amvs4095 3 жыл бұрын
Yes but then you will not be able to check the different levels
@gauravkulkarni6925
@gauravkulkarni6925 3 жыл бұрын
Why are we writing queue Q; What does Node* mean and whats the difference in queue *q …..in short I want to ask * bracket ke Andar Q ha ?.?
@epic_amvs4095
@epic_amvs4095 3 жыл бұрын
@@gauravkulkarni6925 * bracket ke andar isliye hai kyuki node pointer pass kar rahe hai template mai jaise int x likha hai to agr hame queue chaiye x ko store karne ke liye to ham banaynge queue usi prakar se node * x ko queue mai store karne ke liye banaynge queue kyuki template[ bracket ke andar jo likha hai usme ] mai hame data type pass karna hota hai aur x ka data type is case mai node * hai.
@AyushKumar-pe9wx
@AyushKumar-pe9wx 2 жыл бұрын
The quene q; is not decalred showing while I am trying to run the code help me out please! @ApnaCollege
@abhijeetsawale9944
@abhijeetsawale9944 2 жыл бұрын
Include queue library in code #include
Count and Sum of Nodes | C++ Placement Course | Lecture 27.6
4:31
Apna College
Рет қаралды 72 М.
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
Binary tree: Level Order Traversal
11:23
mycodeschool
Рет қаралды 618 М.
Watch this before you start Coding! 5 Tips for Coders
13:53
Apna College
Рет қаралды 458 М.
Learn Coding & Get a Job (in 2025) 🔥
16:54
CodeWithHarry
Рет қаралды 838 М.
L10. iterative Inorder Traversal in Binary Tree | C++ | Java | Stack
11:14
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19