47 Dynamic Programming on Tree General Syntax

  Рет қаралды 92,806

Aditya Verma

Aditya Verma

Күн бұрын

Пікірлер: 146
@ankitsoni8523
@ankitsoni8523 4 жыл бұрын
a very wise man once said "aaj ke baad me kabhi hypothesis par baat nhi krunga", maine first time dekha es topic par kisi ne baat ki, you are really great brother, keep it up
@0anant0
@0anant0 4 жыл бұрын
46 of 50 (92%) done! Very good explanation! I have seen quite a few tree-related code and many of those fall into this pattern, though they try to return values in a host of diff ways. This pattern is uniform and clean.
@SurjitSingh14-c6i
@SurjitSingh14-c6i 3 жыл бұрын
Which one left in bw
@jayshree7574
@jayshree7574 4 жыл бұрын
you raised the standard of teching coding, every other video now looks lame
@divyaa.the.explorer
@divyaa.the.explorer 4 жыл бұрын
seriously so true....hope this channel grows.
@satyamrajsingh7378
@satyamrajsingh7378 4 жыл бұрын
Sir your videos are A masterpiece, you will soon takeover the other youtubers
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
I hope so brother !! Right now it's only 244 subscribers and 4.3k views. Share Please and help this channel grow !!
@code_life4835
@code_life4835 4 жыл бұрын
@@TheAdityaVerma 5 months ago you had 244 subscribers, Now you have 20.5K subscribers. You are really changing the standard of teaching. Thank you for such an awesome content!
@abhaydesalli7344
@abhaydesalli7344 4 жыл бұрын
@@TheAdityaVerma It's 28.6k subscribers today. Hats off man!
@techykush7192
@techykush7192 3 жыл бұрын
@@abhaydesalli7344 and today 46k subscribers amazing man😍😍
@ashadahmad6493
@ashadahmad6493 3 жыл бұрын
@@techykush7192 now 47k subscribers 😍😍😍
@Rakeshmishra-gx8ii
@Rakeshmishra-gx8ii 3 жыл бұрын
LIT intro with revolving pen on fingers.
@divyachoudhary5938
@divyachoudhary5938 4 жыл бұрын
Ur videos are extremely awesome and I have recommended it to all my friends... Just wanna say I love the way u teach and the way u rotate the pen.... 😅
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
Thanks Divya !
@dhawalbhende1250
@dhawalbhende1250 4 жыл бұрын
@@TheAdityaVerma full simpbazi
@abhisheksahay2038
@abhisheksahay2038 4 жыл бұрын
Sir graph k liya bhi kuch video upload kariya..
@k.chandanapriya4004
@k.chandanapriya4004 4 жыл бұрын
sir i have shared it with my friends also.. all of us are eagerly waiting for the graphs and backtracking. please upload it soon sir.
@RandomShowerThoughts
@RandomShowerThoughts Жыл бұрын
the beginning of the video perfectly summed up how to write recursive code for trees
@bloggerayush8550
@bloggerayush8550 10 ай бұрын
"Meko nhi pta kaise answer laake dega Left and right se , bss laakr dega.." is also know as Recursion Leap of Faith 🤣🤣
@ayushkumarsingh8212
@ayushkumarsingh8212 4 жыл бұрын
eik baaar mein aapki saari videos dekh li, DP pehle bhi karta tha mai but aapne nazariya hi badal dia. Eik playlist Array pr bhi nikal do i think placement mein vo bhi bahut important hai
@adarshverma013
@adarshverma013 4 жыл бұрын
Awesome content sirrrr!!!!!! i can't believe i solved todays leetcode challange(of 30day challange) question i.e. maximum path sum just by watching this video. Thanks a lottttt for creating such awesome contents for us!!!!
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
Thanks Adarsh, Dont forget to share if you like the content and help the channel grow !!
@learncoding5633
@learncoding5633 2 жыл бұрын
The content and explanation is awesome please post more videos
@kartiksaini5619
@kartiksaini5619 3 жыл бұрын
BHAI VIDEO SHURU HONE SAI PHLE MAI APKI VIDEO LIKE KARDETA HUN (DIL MANTA HI NAHI...BINA LIKE KIE DEKHNE KO )..BAHUT HI ACHA LAGTA HAI....THX FOR ALL THE EFFORT
@debasishparamanik6527
@debasishparamanik6527 3 жыл бұрын
Hi, I think ans variable should be updated like this, ans=max(temp-1,1+l+r). Because it will be maximum of left diameter, right diameter and path through root.Please clarify.
@bikeshregmi2392
@bikeshregmi2392 Жыл бұрын
I am still confuse on why at last we are returning Temp. Thank you!!
@udaykumar-iu2ok
@udaykumar-iu2ok 4 жыл бұрын
Thanks for simplified solutions
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
Welocme, Share and subscribe.
@lucy-uo6bt
@lucy-uo6bt 4 жыл бұрын
run dfs 2 times -> o(n) :1st to get farthest node and then to calulate the farthest from that node
@mickyman753
@mickyman753 3 жыл бұрын
how can we calculate the farthest node after gettin ghold our node
@pavankalyan4359
@pavankalyan4359 2 жыл бұрын
Take a bow, this is really a great video and this guy made DP look very easy.
@aakanshasoni5798
@aakanshasoni5798 4 жыл бұрын
It would be really helpful if you can help with the recursion code as well. BTW you have done a big favour on us by uploading these videos it made coding simple. Thanks a lot.
@faizan346
@faizan346 4 жыл бұрын
max(temp=1+max(L,R) , relation=1+L+R), dont we get 1+L+R here every time. i think we return temp and store res = max(res,1+L+R);
@tusharshaily
@tusharshaily 4 жыл бұрын
for this question L and R will always remain positive : so there is no use for ,max here . But for other questions we have to look for L and R which can be negative ;
@faizan346
@faizan346 4 жыл бұрын
@@tusharshaily thx i understood that, when i had watched the next video.
@patel1681
@patel1681 Жыл бұрын
This is awesome. Thank you for sharing the knowledge.
@prashantranjan3777
@prashantranjan3777 4 жыл бұрын
Hi Aditya , Your videos are awesome. Kindly make videos on Tree and LinkList
@mohakmalhotra85
@mohakmalhotra85 7 ай бұрын
Amazing, explained it so well brother
@tanmaykumar9277
@tanmaykumar9277 3 жыл бұрын
12:32 Hum res = 0 kyun nahi initialize karr sakte? because vaise bhi jaise hi res solve function mein jaayega toh uski minimum(or worst condition mein) value 0 ho jaayegi... toh humne res = INT_MIN kyun kiya?
@rajsaraogi
@rajsaraogi Жыл бұрын
the way he is teaching is like shortcut without any reason :(
@tanmaytyagi7031
@tanmaytyagi7031 3 жыл бұрын
pair func(TreeNode * root) { if(root == NULL) return {0,0}; pair a = func(root -> left); pair b = func(root -> right); int h = 1 + max(a.first , b.first); int d = max(a.second , max(b.second , a.first + b.first)); return make_pair(h , d); } int diameterOfBinaryTree(TreeNode* root) { return func(root).second; } // pair (first,second) : first -> height , second -> diameter // is my code inefficient? for the calculation of diameter of Tree
@ankitjhunjhunwala9895
@ankitjhunjhunwala9895 3 жыл бұрын
your videos should be taught as fundamentals in college, Great work bro ! Apke charan kanha hai :)
@kartikeyjajoo8499
@kartikeyjajoo8499 3 жыл бұрын
The more you think about the hypothesis section, the more chaotic your thoughts become
@shubhamsingh-gb5zh
@shubhamsingh-gb5zh 4 жыл бұрын
Amazing explanation 👌❤️
@167shivamrai2
@167shivamrai2 3 жыл бұрын
Really appreciate your efforts , that helps all of us. I think govt. should give job to teachers like him who are devoted and dedicated to their work . The govt should pay them salary double which are getting in MNCs , to teach the youth . This man skills and presentation work is so good , then those of NPTEL lecture teachers. Man like him want to teach and understand the importance of basics taught to young programmers , but can't balance all time to do so because of their job roles. I wholeheartedly wish teachers like him should given importance by govt. as they are nourishing the youth with great programming skills . I don't have free time to write such a long comment, but this man deserves appreciations from all . If you like this pls share this on linked in . With mentioning name of teachers like him who should be given vote of appreciations.
@kalagaarun9638
@kalagaarun9638 4 жыл бұрын
0:00 aise hi karte karte kitna kitna pen ka ball tod diya maine !!
@Vikash_Art
@Vikash_Art 4 жыл бұрын
Bro please upload the bitmasking with dp
@suhelalam2686
@suhelalam2686 5 ай бұрын
I am still confuse on why at last we are returning Temp.
@tushnaeduljee1491
@tushnaeduljee1491 4 жыл бұрын
Amazing video :)
@codingwithanonymous890
@codingwithanonymous890 3 жыл бұрын
DP king =Aditya Verma
@Pranshul2002
@Pranshul2002 3 жыл бұрын
Thank you
@mightygerman
@mightygerman Жыл бұрын
Thnx a lot sir...
@rahulyadav-xn5mt
@rahulyadav-xn5mt 3 жыл бұрын
There is no need of variable ans, as 1+l+r >= 1+max(l+r) and l,r>=0;
@affiliatastic1269
@affiliatastic1269 2 ай бұрын
was going to comment same only
@yobro7051
@yobro7051 4 жыл бұрын
bro digits dp v padha do n plz..
@hardikmittal7291
@hardikmittal7291 3 жыл бұрын
0:00 pr pen ghumte hue dekh kr lga ki pen ghumane ka tutorial bnaya h... 😂😂
@sakshamsrivastava6280
@sakshamsrivastava6280 3 жыл бұрын
This is beautiful
@SmokyBigSmoke
@SmokyBigSmoke 4 жыл бұрын
Thank you so much bro
@ashishsoni3187
@ashishsoni3187 4 жыл бұрын
Mera aditya bhai jindabad
@namansharma2203
@namansharma2203 4 жыл бұрын
Aditya sir, can we have this analogy as a full udemy course??Please
@kunalkumarbarman9610
@kunalkumarbarman9610 4 жыл бұрын
Sir left dp ki playlist kb ayegi?
@aravindasaigadamsetty6413
@aravindasaigadamsetty6413 3 жыл бұрын
aaj se bc matlab base condition
@akshayshikhawat6342
@akshayshikhawat6342 3 жыл бұрын
content is very good, try to make vedios on leetcode problems solutions.
@navneetkaur4125
@navneetkaur4125 3 жыл бұрын
bhot badhiyaa!!
@babai2196
@babai2196 2 жыл бұрын
return temp keu karrehehe last me ! samajh nehi aya
@mominmaster2557
@mominmaster2557 4 жыл бұрын
in 12:55 you have written ans = max(temp , 1+r+l), but 1+r+l will be always greater than temp. as temp= 1+max(r,l). So I think ans = 1+r+l ; correct me if I am wrong.
@0anant0
@0anant0 4 жыл бұрын
This is just a template for tree-related DP problems, and not solution for count of nodes, path sum, diameter, etc. -- so check specific problems in later videos.
@tanmaykumar4784
@tanmaykumar4784 4 жыл бұрын
OP bhai.
@abhisheksuryavanshi9675
@abhisheksuryavanshi9675 4 жыл бұрын
Bhai please upload new videos!
@Rahul-vl1no
@Rahul-vl1no 2 жыл бұрын
How answer will send from lower node to higher node? It's my curiosity form last 3 year
@rajsaraogi
@rajsaraogi Жыл бұрын
What is the reason to set value of res = Integer.MIN ?
@Amanali-rl9hw
@Amanali-rl9hw Жыл бұрын
as we are always trying to find the max value of result in each iteration that is why we set it to min(a negative number, and diameter cannot be negative as distance cannot be negative) at the beginning so that even smallest ans like 1/0 is possible
@namanftw8641
@namanftw8641 4 жыл бұрын
sir plzzzzzzz graph pe video laooooo
@mukuldaftary9230
@mukuldaftary9230 3 жыл бұрын
bahut sahi
@vaibhavpandey5615
@vaibhavpandey5615 3 жыл бұрын
sir why you apply ans=max(temp,1+l+r) step i did not understand it.
@abhinandanb3591
@abhinandanb3591 3 жыл бұрын
kena, its just a template
@himanshunegi5228
@himanshunegi5228 4 жыл бұрын
nice
@rahulsaxena9103
@rahulsaxena9103 4 жыл бұрын
can someone explain why we returned temp? There might be a case when 'ans' is greater. We should return ans in that case. Why we are just returning temp?
@deveeshmusic5045
@deveeshmusic5045 4 жыл бұрын
You're right. We should return ans. Perhaps he made a mistake, or both of us are wrong xD
@praxlannister7859
@praxlannister7859 4 жыл бұрын
Both are wrong ans is in res and wo update ho chuka hai before returning
@rishabsinha8749
@rishabsinha8749 4 жыл бұрын
He returned temp because ans is alredy updated and we require temp for further process i.e. l+r+1 means the diameter but for further process we don't require ans rather we require either the left subtree height or the right subtree height whichever is maximum plus 1 that's why temp is returned
@rishabsinha8749
@rishabsinha8749 4 жыл бұрын
int solve(Node* root, int* ans) { if(root == NULL) return 0; int l = solve(root->left, ans); int r = solve(root-> right, ans); *ans = max(*ans, l+r+1); return 1+max(l,r); }
@David-mk8kh
@David-mk8kh Жыл бұрын
4:44 I promise to you bro 🤣🤣🤣
@babbarutkarsh7770
@babbarutkarsh7770 4 жыл бұрын
🔥🔥🔥
@saliq0097
@saliq0097 11 ай бұрын
" agar base condition smjh na aye to if(root == null )return 0 kaam chal jaega "
@anirudhsridhar7900
@anirudhsridhar7900 3 жыл бұрын
The bird view From 4000 feet height 😅
@vinaysarilla4889
@vinaysarilla4889 4 жыл бұрын
Bro Please add Backtracking......
@anmolcoolsinha
@anmolcoolsinha 4 жыл бұрын
Can anyone give the java alternative?
@0anant0
@0anant0 4 жыл бұрын
use can use int[] res = new int[1] and store the value in res[0], and pass int[] res as param. Or define a class variable m_res. Or define a full-fledged class Result that has 'int res' as data member and pass an obj of that as param. You can also use AtomicInteger that can be passed just like a reference -- I think it has get/set methods.
@ani68
@ani68 3 жыл бұрын
91.4k now
@bismeetsingh352
@bismeetsingh352 4 жыл бұрын
Bhai ye video samaj me nai aya,wo relation kya tha jo ans me dala,kuch samja nai.
@mehershrishtinigam5449
@mehershrishtinigam5449 2 жыл бұрын
i did a dp on tree question without even realising it a dp on tree q lol
@ankitdubey9310
@ankitdubey9310 3 жыл бұрын
normal people: i am suffering from cold and fever let me sleep , le aditya verma: yahi to time hai video banane ka legend !!
48 Diameter of a Binary Tree
15:13
Aditya Verma
Рет қаралды 128 М.
DP on Trees: Distance in Tree
17:16
Kartik Arora
Рет қаралды 11 М.
Why no RONALDO?! 🤔⚽️
00:28
Celine Dept
Рет қаралды 95 МЛН
The IMPOSSIBLE Puzzle..
00:55
Stokes Twins
Рет қаралды 192 МЛН
Lazy days…
00:24
Anwar Jibawi
Рет қаралды 7 МЛН
Smart Sigma Kid #funny #sigma
00:33
CRAZY GREAPA
Рет қаралды 27 МЛН
43 Egg Dropping Problem Recursive
30:10
Aditya Verma
Рет қаралды 169 М.
41 Scrambled String Recursive
45:48
Aditya Verma
Рет қаралды 143 М.
DP on Trees: Tree Matching
22:01
Kartik Arora
Рет қаралды 28 М.
7 Time Complexity of a Recursive Tree
25:43
Aditya Verma
Рет қаралды 14 М.
39  Evaluate Expression to True  Boolean Parenthesization Recursive
40:00
Introduction To Dynamic Programming
1:05:12
Coder Army
Рет қаралды 13 М.
L16. Diameter of Binary Tree | C++ | Java
13:47
take U forward
Рет қаралды 380 М.
36  Palindrome Partitioning Recursive
26:35
Aditya Verma
Рет қаралды 198 М.
Why no RONALDO?! 🤔⚽️
00:28
Celine Dept
Рет қаралды 95 МЛН