Please likeeee, shareeee and subscribeeeeeeee :) Also follow me at Insta: Striver_79
@democratcobra3 жыл бұрын
Understood
@sarthakbhatia78883 жыл бұрын
done
@AbhishekKumar-vr7sh3 жыл бұрын
Yesterday I gave my paytm interview and all the dsa questions asked were from the sde sheet. Moreover, the questions asked from the core subjects were from the core sheet. I was able to crack the interview with great ease all thanks to striver bhaiya OP. You are the best mentor in this world 🔥
@AbhishekKumar-vr7sh3 жыл бұрын
@Himanshu Kataria 😂😂😂
@debanjan_poddar3 жыл бұрын
You gave the interview yesterday.. How are you already sure that you will be selected?
@AbhishekKumar-vr7sh3 жыл бұрын
@@debanjan_poddar It was an on campus interview. Results came out that night itself. Processing is faster in case of on campus placement.
@AbhishekKumar-vr7sh3 жыл бұрын
@@aadeshsharma0001 thanks bro
@singhsahab94783 жыл бұрын
@Himanshu Kataria lol
@111rhishishranjan2 Жыл бұрын
vector Solution::preorderTraversal(TreeNode* A) { stackst; TreeNode*node =A; vectorv; while(!st.empty() || node != NULL){ if(node != NULL){ v.push_back(node->val); st.push(node); node = node->left; } else{ node = st.top(); st.pop(); node = node->right; } } return v; } //this is a nice stack approach . with more clean code.
@curs3m4rk3 жыл бұрын
watched a lot of videos for iterative traversal, but this one hit my brain in first attempt. Your explanation is great man
@aryanpinto5105 Жыл бұрын
Was just able to code on my own. The way you give the intuition is just next level. Tysm Striver. Grateful to have a teacher like you.❤💯
@abhishekanand68472 жыл бұрын
What ,it means --- Vectorpreorder Traversal(Treenode* root )
@user-vaidesh9 ай бұрын
It means the function is returning a vector that contains data in the form of integers and the function takes a struct or class of node to represent a treee
@Ishan3013 жыл бұрын
Striver is life saviour for tier-3 college guys like me. Thank you.
@shivangisrivastava11583 жыл бұрын
i am thrilled at my transformation, i was able to write correct code before looking at your code! Tysm bhaiya😵♥️
@harshvardhanmishra10722 жыл бұрын
Started this tree series today and I don't know when I come up to the Lecture number 9. Such a wonderful explanation. Thanks you so much Sir for doing so much effort for us.😊
@piyushsaxena62432 жыл бұрын
this is the best tree series till date , thanks a lot striver, would be really helpful if you could bring a playlist on dp on trees as well for both cp and interviews.
@thegreekgoat983 жыл бұрын
What an explanation!!!!! I wrote the C++ code by myself after watching the explanation part...
@Codeology7083 жыл бұрын
This Man Is a great example for those who say you can get a placement in Giant MNC's . Thanks Bhaiya You inspired me a lot
@vishalwaghmare31302 жыл бұрын
This is the best channel I have come across on Data Structures/Coding. Thanks a lot!
@Manasidas99 Жыл бұрын
Sir your teaching style is really unique.
@manasgupta664711 ай бұрын
yep
@lifehustlers164 Жыл бұрын
Completed 10/54(18% done)!!!
@tech_PersonalityАй бұрын
00:35 Iterative preorder traversal in binary tree 01:22 Iterative Preorder Traversal in Binary Tree is done using Stack 02:12 Iterative Preorder Traversal in Binary Tree using Stack 03:11 Iterative Preorder Traversal in Binary Tree using Stack 04:32 Importance of right side effects on mental strength 05:27 Iterative preorder traversal in binary tree is efficient and useful
@stith_pragya Жыл бұрын
Thank You So Much for this wonderful video.....🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@AdityaKumar-be7hx Жыл бұрын
We can avoid a few extra checks to write a smaller code: class Solution { public: vector preorderTraversal(TreeNode* root) { vector preorder; stack st; st.push(root); while(!st.empty()){ auto curr=st.top(); st.pop(); if(curr!=nullptr){ preorder.push_back(curr->val); st.push(curr->right); st.push(curr->left); } } return preorder; } };
@vasudhajha91152 жыл бұрын
Hello Striver! I hope you're doing well :) Thank you so much for making these series that newbies like me can come back to again and again. The passion that you bring to teaching is infectious and in a sea of tutorial hell, your tutorials are a guiding light and the best path to follow! Really appreciate the effort that you put to help countless people. Your work is inspiring.
@shashibhushanrajput24613 жыл бұрын
Nice simple explanation bhaiya.. please make a serious on medium and hard DP problems. Because right now DP is really in demand at Interviews.
@sharmanihal996 ай бұрын
Just in case someone is looking for the python code for the above: class Solution: def preorderTraversal(self, root: Optional[TreeNode]) -> List[int]: #Iterative Solution if not root:return stack=[root] ans=[] while stack: top=stack.pop() ans.append(top.val) if top.right: stack.append(top.right) if top.left: stack.append(top.left) return ans
@noorjabeen731 Жыл бұрын
You are not a king.... You are a kingmaker ✨ 👑
@apmotivationakashparmar722Ай бұрын
Thank you So much Striver . Please upload Complete String in A-Z Dsa Sheet.
we can use queue too how does that too working while using queue?
@cinime2 жыл бұрын
Understood! So amazing explanation as always, thank you very much!!
@nawabkhan49162 жыл бұрын
great work, and have lots of sponsor ad so that you can provide great videos.
@somyapratapsingh98492 жыл бұрын
Looks like watch whole series in one go :))
@rahatsshowcase86142 жыл бұрын
Recursion uses already stackspace But we are again usig that stack separately!Something new i likeit
@chiragbansal33643 жыл бұрын
Awesome explanation in just 6 mins
@bhavkushwaha7 ай бұрын
Thankyou Striver, Understood!
@samuelfrank1369 Жыл бұрын
UNDERSTOOD. THANKS A LOT.
@prathameshjadhav294210 ай бұрын
Nice teaching bro.....
@lavanyaprakashjampana9332 жыл бұрын
we love your content and we love you....
@PranjalGunjanDiaries Жыл бұрын
YOU ARE THE BEST..
@jankeshchakravarthy9389 Жыл бұрын
Great video, I did not understand where are you printing?
@coolgaurav51634 ай бұрын
Understoood
@ErgoswamiАй бұрын
Completed!
@sonalisingh79322 ай бұрын
understood👍👍
@BharatKumar-rc8vn4 ай бұрын
cool stuff
@sagarchauhan31873 жыл бұрын
Hello Sir, Can you please complete the remaining videos of trees and graph of SDE sheet? please please upload!!🥺🥺
@vakhariyajay2224 Жыл бұрын
Thank you very much. You are a genius.
@yashmandaviya13562 жыл бұрын
What is the purpose behind using extra space of the stack , its not improving the time complexity of the preorder traversal?
@sidvyas2 жыл бұрын
Bro once you explain most of the time I am able to code the logic by myself. Thanks so much man!!
@sonakshibajpai64455 ай бұрын
understood!! thanks striver
@pradipkumarmukhi11 күн бұрын
Understood!!!
@DeadPoolx1712Ай бұрын
UNDERSTOOD;
@theSeniorSDE3 жыл бұрын
Striver, Completed this Question
@bhaveshkumar68422 жыл бұрын
Immensely grateful for your content
@anshikagupta585811 ай бұрын
Thankyou Striver:)
@mriit30258 ай бұрын
I just realized how much I lost the time which should be used to understand the deep logic and the code will be automatic... In my second year of Btech, I had a DS (Data Structure) course, but I just understood the surface logicrememberedember the code mostly which was enough for getting 9/10. as iterative code was not important I was too lazy to understand it. so, my advice to myself is : Did you really understand? really? check? like. I completed a module in DS and just remembered the code, am I able to do a dry run of the code and understand the working! remember don't procastinate!
@nagavedareddy58912 жыл бұрын
Huge respect..❤👏
@rohankrishnani2 жыл бұрын
Please make video on circular queue implementation as well
@letmeinthefiend85222 жыл бұрын
instead of taking right - left in stack.. can we use queue so that we can use left-right approch .. i learn preoder by rootleftright.. stack approach making confusion right before left
@tejas73792 жыл бұрын
No, it's not possible using queue. Regarding stack approach, think how stack works. Since right goes before left, left node will be popped and explored first, then the right node.
@psibarpsi2 жыл бұрын
@@tejas7379 Why is it not possible to use queue here? Can you please elaborate?
@tejas73792 жыл бұрын
@@psibarpsi In stack we push right and left. Then when we pop we get left first and add its children to stack. So when we pop again we will be traversing all left children. So before we reach right part, we would have completely traversed left sub tree. Now lets say we use queue, we push left first and then right. [left, right]. So when we pop we get left first and then we push left's children to queue, like [right, (lefts children)]. When we pop again we will be exploring right subtree then again left sub tree's children. Which is wrong.
@aakriti12 жыл бұрын
@@tejas7379 Thanks for the nice explanation of why we're using a stack here and why we can't make use of a queue for this question.
@tejas73792 жыл бұрын
@@aakriti1 Glad it helped.
@SambhavJaincs23m0602 ай бұрын
0:48 START
@Learnprogramming-q7f8 ай бұрын
Thank you Bhaiya
@DevanshuAugusty Жыл бұрын
shouldn't we take a temp node for root cause we dont want to modifie the data
@1tav02 жыл бұрын
thank you so much for these series
@codeman38288 ай бұрын
Understood
@PrashantSingh-jy6zp3 жыл бұрын
for best experience go to 0:48
@mahaveerbana20312 жыл бұрын
dil se thank you striver
@itsmepiyushsaha3 жыл бұрын
Superb explanation!
@UECAshutoshKumar Жыл бұрын
Thank you sir
@guruprasadkancharla55552 жыл бұрын
why are we using stack? Is there any specific reason? We can do this using Queue also ?
@harshsinha32212 жыл бұрын
Queue should be used for Level order traversal, preorder traversal uses recursive call, so you can figure out that recursion itself uses stack DS
@codenchill7323 жыл бұрын
You made it so simple !! thanks alot
@gangsta_coder_123 жыл бұрын
Excellent explanation as always 🔥🔥🔥🔥🔥
@aditisharma57452 жыл бұрын
You are the best!!
@culeforever5408 Жыл бұрын
understood
@vakhariyajay315 Жыл бұрын
Thank you very much.
@aryansingh5198Ай бұрын
Why did we traverse the right sub tree first in pre order Arent we supposed to go from Root Left Right ???
@bhushankorg56062 жыл бұрын
Nice explaination!
@_AkashRuidas2 жыл бұрын
great explaination
@mahaksharma78279 ай бұрын
👏👏👏👏
@kasyapdharanikota85703 жыл бұрын
best explanation
@Mr.Indianwxvhehsy9191hghgx11 ай бұрын
nice
@sofikulmallick37663 жыл бұрын
amazing explanation!
@ramulala93653 жыл бұрын
Great Explanation!
@mriduljain1981 Жыл бұрын
completed lecture 9 of tree playlist
@codemarshal655 Жыл бұрын
Did you know, you can do iterative in / pre / post order traversals using same code?? Checkout how I did it in just 20 lines, in my new video kzbin.info/www/bejne/bKjbf5ZunKidbqc
@harshitjaiswal9439 Жыл бұрын
Understoooooooood!!!
@rexitspersonal83532 жыл бұрын
converting recursive preorder to iterative public static List preorderTraversalSecond(Node root) { List ans = new ArrayList(); Stack ds = new Stack(); if (root == null) return ans; Node node = root; while (true) { if (node != null) { ans.add(node.val); ds.push(node); node = node.left; } else { if (ds.isEmpty()) break; node = ds.pop(); node = node.right; } } return ans; }
@priyanshupandeypandey79942 жыл бұрын
jiiiiiiiooooooo guru jiiiiiiii
@senseiKakashi072 жыл бұрын
this is somewhat like recursion, as recursion uses stack behind the scenes, right call tu wait kar mein pehle left hoke aata hu😂
@kirtikhohal33132 жыл бұрын
loll
@laxmikantkatre4579 Жыл бұрын
I used little different approach to solve this question. I am pushing left first and then right in stack. Below is the Accepted Code: //Iterative Solution public List preorderTraversal(TreeNode root) { List ans = new LinkedList(); if(root == null) return ans; Stack stack = new Stack(); TreeNode node = root; while(true) { if(node != null) { stack.push(node); ans.add(node.val); node = node.left; } else { if(stack.isEmpty()) break; node = stack.pop(); node = node.right; } } return ans; }
@singhs_aniket3 жыл бұрын
Understood 👌👌
@koushik12613 жыл бұрын
Bhaiya, in interviews do they ask explicitly to implement in iterative/recursive method?
@D44Aishwarya Жыл бұрын
thanks a lot sir!
@prateekverma91663 жыл бұрын
THANKS STRIVER
@t-anime5172 жыл бұрын
Understood😊
@as_a_tester2 жыл бұрын
tysm striver bhai
@abhijeetbasfore68162 жыл бұрын
Thank you
@ravisaharan2193 ай бұрын
Can someone please give an example of worst case scenario of space complexity where stack size goes up to O(N)
@RAJ-cc4xn Жыл бұрын
Can we do this Using Queue ? Anyone Please answer
@ganavin34232 жыл бұрын
understood
@SachinSingh-id8mf2 жыл бұрын
bhaiya if you write a code in the video.. this would be more easy to understand.