Matrix Chain Multiplication

Поделиться
HTML-код
  • Опубликовано: 2 ноя 2024

Комментарии • 258

  • @jackinab0x600
    @jackinab0x600 4 года назад +80

    You know its funny, I watched this video 4 years back when I was in my undergraduate and im returning here today while im doing my Masters.
    Thank you

    • @shashanksagarjha2807
      @shashanksagarjha2807 4 года назад +1

      please check this playlist : ruclips.net/p/PLeF0b8iqbx4mogykbd82-HY9Y1-JS9MDr

  • @growandlearndaily
    @growandlearndaily 2 года назад +2

    I Appeared in the Google Inida Interview, In that mail along with JD , they were suggesting to watch @Tushar Roy's video. Great Achievement bro.

  • @RahulLohra
    @RahulLohra 9 лет назад +3

    You are a Genius , explaining the concept in just 11 minutes . Thanks

  • @devonpowell3006
    @devonpowell3006 7 лет назад +2

    You're the only person/resource online that I've seen explain the backtracking well enough to understand. Great job, and thanks!

    • @shashanksagarjha2807
      @shashanksagarjha2807 4 года назад

      please check this playlist : ruclips.net/p/PLeF0b8iqbx4mogykbd82-HY9Y1-JS9MDr

  • @BackToBackSWE
    @BackToBackSWE 5 лет назад +33

    Awesome video, this really helped me back when I watched it.

    • @nikhilshrivastava3227
      @nikhilshrivastava3227 4 года назад +1

      When is your video coming on this problem? He is good but your way of teaching is better.

    • @shashanksagarjha2807
      @shashanksagarjha2807 4 года назад

      please check this playlist : ruclips.net/p/PLeF0b8iqbx4mogykbd82-HY9Y1-JS9MDr

    • @HARIHaran-ks7wp
      @HARIHaran-ks7wp 3 года назад

      the man, the myth, the legend!

  • @Farren246
    @Farren246 8 лет назад +8

    Love that recursive code at the end; how it all comes down to a function with only two lines inside it.

  • @aditipawde5894
    @aditipawde5894 9 лет назад +128

    Hello Tushar! Your videos are really very good! They explain exactly how to crack a problem. Just one suggestion, if you could mention complexities (time and space) of each problem giving reason behind it, it would be very useful! Thank for all the videos.

  • @sachinsagar1994
    @sachinsagar1994 6 лет назад +2

    Tum bhot badhiya kaam karta hai Maksood bhai.. Or koi tumko Thank You ni bolta.. Aaj mai tumko Thank you bolne ko aya.. Thankyou bhai.. **jaadu ki jhappi intensifies** tum mereko pass kara dia ❤️🙌

  • @Snehilw
    @Snehilw 9 лет назад +8

    I have seen all your videos buddy & the code too, these are excellent videos, kudos to you to create them & to have shared them with everyone.

    • @Snehilw
      @Snehilw 9 лет назад

      Tushar..this is a very good initiative. Good luck to you! Kudos

  • @M.x_mutua
    @M.x_mutua 7 месяцев назад

    watching this video 2024 and its the Best. this man did good job long time ago👏👏👏👏👏

  • @LUX1111111111111
    @LUX1111111111111 9 лет назад +72

    I love Indian people so much! They are so darn good at programming and English, envy envy .. I am from China :) smart Indians

    • @abhinavkanoria7627
      @abhinavkanoria7627 8 лет назад +7

      Ha-ha 谢谢你! By the way I'm helping a person in China learn English and in turn he helps me learn Chinese and Chinese culture :)

    • @abhinavkanoria7627
      @abhinavkanoria7627 7 лет назад +3

      I met a Chinese person on RUclips and now he's with me in WhatsApp. Also, I'm Facebook friends with another person in south China and we met on a Game of thrones fan group.
      Also try the app 'Hello Pal' it lets you connect with native language speakers around the world.

    • @abhinavkanoria7627
      @abhinavkanoria7627 7 лет назад

      *on

    • @devbackhome
      @devbackhome 7 лет назад +3

      How do you guys communicate? Whats the common language?

    • @shima3610
      @shima3610 4 года назад

      I envy Chinese people so much because of their perseverance and hard working :)

  • @ramanboywss
    @ramanboywss 6 лет назад +2

    Saving my life on my homework assignment, this and the knapsack problem. Thank you so much!

  • @Seanwong03
    @Seanwong03 3 года назад

    Best explanation I have seen so far. Thank you.

  • @mohitsingla325
    @mohitsingla325 9 лет назад +5

    Seriously good job! explaining the concepts so effectively in that short time...

  • @anil21040
    @anil21040 3 года назад

    Thank you Tushar. Your crystal clear explanations really make problems simpler

  • @onyinyechichukwuma689
    @onyinyechichukwuma689 5 лет назад +1

    Beautifully taught! I have watched a bunch of similar videos, and this is the only one that I understood! Thanks Tushar!

  • @balasahebdabhade3091
    @balasahebdabhade3091 9 лет назад +3

    Very clear cut and best explanation. Thanks for sharing !!!

  • @saras_arya
    @saras_arya 9 лет назад +71

    Great videos tushar. one little thing. Only if you could have told that [2, 3] is the size of the matrix it would have been easier. Great Explanantion anyways. Subscribed already

    • @malharjajoo7393
      @malharjajoo7393 8 лет назад +8

      +Saras Arya - Good point. I was wondering about that.

    • @tarachandprajapati7112
      @tarachandprajapati7112 6 лет назад +3

      m glad i saw this comment before watching the video

    • @dedust8648
      @dedust8648 4 года назад +3

      exactly

    • @parthsalat
      @parthsalat 4 года назад +3

      Thanks a lot man! I was looking out for an explanation

  • @christina_pupul6314
    @christina_pupul6314 6 лет назад

    在智障边缘被挽救了。。终于理解了动态规划!谢谢小哥哥!

  • @MrDivad006
    @MrDivad006 5 лет назад

    Time complexity is O(n^3) because number of subproblems is O(n^2) and time per subproblem is O(n).
    You get the number of subproblems by asking yourself how many subproblems there are where 2 matrices are being multiplied (answer is n-1), then how many subproblems where 3 matrices are multiplied (n-2) and so on until n matrices (n-1 + n-2 + n-3 + n-4 + ... + 1 = O(n^2)).
    You get the time per subproblem by realizing that the largest subproblem (compute min cost for n matrices) has n possible solutions which you need to compute and then find the minimum of, if the largest subproblem takes O(n) then all other subproblems also take O(n).

  • @katchie2888
    @katchie2888 8 лет назад

    This is great thank you so much. I have an exam today and you cleared this right up for me.

  • @tranxuanuc9509
    @tranxuanuc9509 3 года назад

    continue doing your thing please cause i see you teach so well

  • @sony87863
    @sony87863 7 лет назад

    Probably the one of the easiest way of teaching matrix chain :D

  • @imdadali5146
    @imdadali5146 7 лет назад

    sir!! you r best in dynamic programming..........

  • @Itsjustfaiq
    @Itsjustfaiq 7 лет назад +2

    The savior of my semester

  • @raivathg3457
    @raivathg3457 6 лет назад

    Very nice and easy to understand videos

  • @hot13399
    @hot13399 8 лет назад +9

    For someone doesn't understand why matrix multiplication result is p * q * r, you can look at this article:www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Dynamic/chainMatrixMult.htm

  • @abhayasharma7065
    @abhayasharma7065 3 года назад

    your video is still the best one out there! :)

  • @yiikai
    @yiikai 6 лет назад

    Thank You!!! So much better than my lecture notes

  • @akashgupta9217
    @akashgupta9217 8 лет назад

    Great Explanation... You made it a lot easier to understand .. Kudos

  • @kamalbahadur007
    @kamalbahadur007 9 лет назад

    u nailed it man..... concept clear js b4 exam..

  • @nikitagupta2961
    @nikitagupta2961 9 лет назад

    u r far much better than my professors ..
    keep up the gud work..bless u

  • @barrypops7499
    @barrypops7499 7 лет назад

    Btw, the reason he keeps track of what is multiplied by what is because *k* = the way you multiplied the matrices. Usually the k you selected (the minimum) is put into a choice table next to the table of multiplications. He doesn't really do much with recording the way he multiplied the matrices in this video.

  • @mgzy89
    @mgzy89 6 лет назад

    Thank you Tushar, your videos are wonderful!

  • @rubeenasultana1187
    @rubeenasultana1187 5 лет назад

    Very good teaching!!

  • @Himanshu-vd1jm
    @Himanshu-vd1jm 9 лет назад +4

    it would be better if you use bright marker....like black or red...rather than this blue one...because at some places...it was difficult to view clearly.
    P.s your videos are awesome :)

  • @OthmanAlikhan
    @OthmanAlikhan 8 лет назад

    Thanks for the video. The explanation was really clear, video quality was high and overall very well presented. =)

  • @allisonkuhl5355
    @allisonkuhl5355 7 лет назад +1

    I think I finally understand! Thanks for the explanation. :)

  • @TheAshishk007
    @TheAshishk007 7 лет назад

    Great tutorial, Simplified to the core , Thanks :D

  • @nitinpaliwal9196
    @nitinpaliwal9196 8 лет назад

    thanx a lot !! you made it very easy to understand and implement

  • @aronquemarr7434
    @aronquemarr7434 4 года назад

    Came here to find out how to determine the order of multiplication from the table. Thanks.

  • @SAINIVEDH
    @SAINIVEDH 5 лет назад

    Recursive solution: product(A,1,3)
    product(A,i,j){
    i == j ---> return 0;
    mini INT_MAX;
    for(k=i;k

  • @thiagarajansaravanan
    @thiagarajansaravanan 8 лет назад +1

    Awesome Explanation!

  • @anjugopinath8616
    @anjugopinath8616 4 года назад

    The example in the video uses a 4 by 4 matrix. But, the code in github uses a 5 by 5 matrix. And, I think the logic is different for both

  • @taruntrikha5262
    @taruntrikha5262 9 лет назад

    Awesome explanation.. now its so clear to me.. tnx.. Subscribed

  • @nikhilsendidwana3635
    @nikhilsendidwana3635 5 лет назад

    Arre sir aap toh hero ho

  • @tariqsaeid9856
    @tariqsaeid9856 8 лет назад

    Ohhhh! Thanks man, You are a life Savior!

  • @RUKSUDAPORN
    @RUKSUDAPORN 7 лет назад

    how to solve
    Let P be a set of balanced parenthesis strings and P is recursively defined as follows.
    1. e is in P, where e is an empty string.
    2. If alpha, beta are in P, then (alpha)beta is also in P.
    Prove that every nonempty balanced parenthesis string can be obtained via rule 2 from a unique alpha-beta pair.
    Hint: Mathematical induction but induct on what??????

  • @shubhamgoyal2622
    @shubhamgoyal2622 8 лет назад

    So easily explained!

  • @pallesaikrishna
    @pallesaikrishna 9 лет назад

    undoubtedly the clear explanation and thanks for tutorial :)

  • @damizht
    @damizht 8 лет назад

    Dear Tushar, great explanation, thank you! Just 1 question, cannot understand the T[i][j] formula you wrote in the end. Could you please elaborate on it a bit more?

  • @dakshisatbest
    @dakshisatbest 8 лет назад +10

    i understood the procedure but how is the code formed.
    i am not able to understand the code

    • @utkarshsaxena8034
      @utkarshsaxena8034 7 лет назад +3

      Never Give Up Never Give Up !!!

    • @vardaanbajaj3181
      @vardaanbajaj3181 6 лет назад +2

      it's simple math n-L+1 tells how many continuous groups of L are formed, i+L-1 tells about the last matrix in the current group of L matrices. The rest is self explanatory :)

  • @kunwoomyung1033
    @kunwoomyung1033 8 лет назад

    This is the best explanation! thanks a lot

  • @saurabhgoel8191
    @saurabhgoel8191 6 лет назад

    very good i understood it very easily thanks

  • @kundan621
    @kundan621 9 лет назад

    this is just amazing:)
    thanx i got the concept in just 11 mins ;)

  • @hemavathi-wp6zb
    @hemavathi-wp6zb 7 лет назад

    very good explanation

  • @amellperalta
    @amellperalta 9 лет назад +1

    Good job! Thanks for the help.

  • @siddharthsharmaBelieve
    @siddharthsharmaBelieve 9 лет назад +1

    Good work !!

  • @zokna
    @zokna 8 лет назад +3

    The formulation you wrote at the end on the table doesn't make sense. You wrote "take the minimum of one number". I guess you wanted to say "take the minimum of the newly computed number and the pre-existing number at T[i][j]".
    Your code is correct though:
    T[i][j] = min(T[i][j], q) where q = T[i][k] + T[k][j] + A[i]*A[k]*A[j] and A is the input array.

    • @ravikhannawalia3107
      @ravikhannawalia3107 7 лет назад

      Nope, its the maximum for the different values of k where k>=i and k

  • @robealamalik7763
    @robealamalik7763 8 лет назад

    great explanation...thanks alot sir

  • @kaioh1384
    @kaioh1384 5 лет назад

    nice explanation.

  • @hellschatt
    @hellschatt 8 лет назад

    Nice explanation! I'm happy that you gave up SimplePickup and that you're teaching computer science now :P

    • @hellschatt
      @hellschatt 8 лет назад

      +Tushar Roy There is a guy called Jesse on the youtube channel "SimplePickup" and you reminded me of him. That's why I made this joke :P

  • @w180112
    @w180112 8 лет назад

    nice explanation, thanks a lot!

  • @radhe8765
    @radhe8765 3 года назад +1

    Sir is looking like Younger brother of ravindra babu ravula

  • @ab001atg
    @ab001atg 7 лет назад +1

    While calculating for l=4, why did we not include the case to multiply 1 and 2 first and then multiply the result with say 0 or 3?

  • @LeonYapKL
    @LeonYapKL 4 года назад

    I think there is lack of description of the problem, the pair of number is the dimension of the matrix.

  • @tapanjeetroy8266
    @tapanjeetroy8266 6 лет назад

    Thanks a lot sir..helped me at the last moment...

  • @madhundle
    @madhundle 8 лет назад

    This helped so much. Thank you!

  • @vardaanbajaj3181
    @vardaanbajaj3181 6 лет назад

    beautifully explained :)

  • @ethanwang8951
    @ethanwang8951 9 лет назад

    Hey Tusha, first thanks for cool video. You are assuming the chain is pre sorted in a unique order for multiplication. which could not be the case for [4X2][2X3][3X2][2X4]

    • @ethanwang8951
      @ethanwang8951 9 лет назад

      ***** If in the example above, we call them the matrix 1, 2, 3, 4. In this case, when you consider the two matrix scenario, not only 1x2, 2x3, 3x4, but also it's possible that 4x1 as well. So if (4X1)X2X3 turn out to be the lowest cost, could it still be covered?

  • @sahajsomani9193
    @sahajsomani9193 5 лет назад

    The video just solves the program with no mention of dynamic programming. Forget the code, it doesn't even bring in the concept.

  • @ajanasathian8192
    @ajanasathian8192 9 лет назад

    +Tushar Roy , How the matrices are multiplied? I didn't get that. Here every matrices are 1x2. Please reply to me

  • @ashisharyan2020
    @ashisharyan2020 5 лет назад

    it would be of great help if you explain the logic behind your solution.

  • @abhishekanand3706
    @abhishekanand3706 6 лет назад

    Great Job Man !!!!!

  • @BiranchiNarayanNayak
    @BiranchiNarayanNayak 8 лет назад

    Great Tutorial... i love it....

  • @KountayDwivedi
    @KountayDwivedi 5 лет назад

    Awesome way to solve this problem rapidly, brother.
    Not recommended for beginners, though.
    :-}

  • @RakeshKumar-yn3hh
    @RakeshKumar-yn3hh 6 лет назад +1

    what is the relation between i, j and k? How to select k?

  • @nisaradappadathil6380
    @nisaradappadathil6380 6 лет назад

    in the final recursive equation you said minimu of(something), but there is only one thing inside the bracket. It atleast need 2 things to take a min right? in the equation you shld have put k from i to j

  • @Animalianzz
    @Animalianzz 8 лет назад

    Hi!
    Can you explain how the formula that you have used in the end will cover all the cases for example will it consider the case T[1][2]+val[0].first*val[0].second*val[2].second for the cell number T[0][2]? As according to the formula for given value of 'i' you are varying 'k' but i can also vary?

  • @rayzhang336
    @rayzhang336 8 лет назад

    very clear. Thank you!

  • @ua5680
    @ua5680 7 лет назад +3

    ekrem hocam

  • @cyberpunk6554
    @cyberpunk6554 7 лет назад

    awesome tutorial mann 😀

  • @nikhilgupta0
    @nikhilgupta0 9 лет назад

    thanks for the video,but you should write formula at the begining(clearly) then procede with the table,because after going through the solution now relating it to the formula gets difficult,but thanks anyway :)

  • @MrKishorebitta
    @MrKishorebitta 8 лет назад

    hi Tushar,
    Thanks for your video.I want to practice on white board. One question about your white board.What is size of your white board?

  • @ProudBharatiyaTV
    @ProudBharatiyaTV 7 лет назад +45

    This looks like you have crammed the formula and just create video... You should have explained how you thought about the solution rather than just debugging the problem ...

    • @gsriram7
      @gsriram7 7 лет назад

      Exactly!

    • @truthprevails899
      @truthprevails899 5 лет назад +1

      Tushar has done a great job here. If you need further explanation you can request or you can create an explanation video and can provide the link. However, you can refer MIT 6 006 lecture 22 by Prof. Erick and then see this video. You can understand better.

    • @charan775
      @charan775 4 года назад

      His content is different than the others. He provides the method to fill the table that's it. That's really helpful for many people. If you want deeper explanation you should refer other videos.

    • @TheAlgorithmicEye
      @TheAlgorithmicEye 4 года назад

      If anyone is looking for a more intuitive explanation, I made a 3b1b-styled video, also animating how the DP table is filled at the end ruclips.net/video/wkIUHguF7bs/видео.html

  • @OauthC2ID
    @OauthC2ID 8 лет назад

    Thanks! I've forked your GitHub repo.

  • @shambhavigupta825
    @shambhavigupta825 8 лет назад

    Thank you! It was really helpful! :)

  • @jetmirg1268
    @jetmirg1268 8 лет назад

    c\10.6 Let A1,...,An be matrices where the dimensions of Ai are di−1 × di, for i =
    1,...,n. Here is a proposal for a greedy algorithm to determine the best order
    in which to perform the matrix multiplications to compute A1×A2×...×An.
    Algorithm 10.6 (MatrixMultiplicationOrder)
    Input: Dimension D = (d0, d1,...,dn) of n matrices
    Output: An array Order in which entry i contains the ith multiplication
    MaMuOrd(D)
    1 At each step, choose the largest remaining dimension
    2 (among d1,...,dn−1), and multiply two adjacent matrices
    3 that share that dimension.
    4 .
    .
    .
    5 return Order
    Observe that this strategy produces the optimal order of multiplications for
    the matrices in the example discussed in class.
    (a) What is the order of the running time of this algorithm (only to determine
    the order in which to multiply the matrices, not including the actual
    multiplications)?
    (b) Either give a convincing argument that this strategy will always minimize
    the number of multiplications, or give an example where it does not do
    so.

  • @kurinchimalarn8555
    @kurinchimalarn8555 8 лет назад

    Hi Tushar! Very good explanation. Thanks. Between in the link with source code, I see only the optimal cost returned. Do you have a version where the extracting optimal sequence is captured?

  • @samanwaysahoo7072
    @samanwaysahoo7072 7 лет назад

    good lecture

  • @zeroimpetuous
    @zeroimpetuous 8 лет назад

    In L=-3, you could also multiply 1,2 with 3 which would make the total options of 3 to choose the min cost from. Why did you skip that?

    • @SarvenderDahiya
      @SarvenderDahiya 8 лет назад +1

      No he did not, at 6:25 he did that.
      For L=3 , we have two choices , 0 to 2 and 1 to 3, each with two options.

  • @nishhhaaa1
    @nishhhaaa1 5 лет назад +25

    The first 3 minutes was complete confusion. You should have atleast introduced by explaining what matrix multiplication is and how matrices can be multiplied. I like your videos, but the dearth of basic intro to problems has always been an issue. I had to go to another video, understand the concept and then come back to listen to the rest of your video.
    Kindly take this as a constructive suggestion ! Good job otherwise !

    • @ManishSharma-lm3wg
      @ManishSharma-lm3wg 5 лет назад

      Yaeh i felt same

    • @andrewphilip8574
      @andrewphilip8574 5 лет назад

      i mean its kinda obvious that if you are learning matrix chain multiplication, you must be having a certain idea about it's basics

    • @abinavch2632
      @abinavch2632 4 года назад

      Even I felt the same...

    • @GuhaJanakiraman
      @GuhaJanakiraman 4 года назад

      There is a lot of comment about Tushar’s video needing an intro. Not every video in every concept needs a long intro. If you need that for every video there are channels that provide that. You come to Tushar’s videos to get to the point. Who else explains CMM in 11 mins?

  • @lalitmeghwal75
    @lalitmeghwal75 4 года назад

    what is the cost? how are you getting the cost by multiplying those 3 digits? how did you think of filling the table in this manner after knowing the recursive solution? Just filling the table after knowing the solution, I think that's not coding made simple. I hope you see my comment!

  • @ytstudy7007
    @ytstudy7007 6 лет назад

    Sir ek doubt h ye bataiye hm jo determinant solve krte h to hum usme row ar coloumn dono operation lga skte h yaa fir sirf row or column?

  • @souravsinghtomar8573
    @souravsinghtomar8573 4 года назад

    this reminded me of the college lecture to pass the exam

  • @amanmeena2878
    @amanmeena2878 6 лет назад

    Thanks alot sir !!!

  • @cellardoor8943
    @cellardoor8943 8 лет назад +2

    greetings from Greece! I have fully understanded this.However,in some exercises they don't give you the actual size of each matrix,but a "size sequence" ...For example, we have matrices A1,A2,A3,A4,A5,A6 with size sequence (2,3,4,5,6,7)...and i cannot understand what that means..Please explain it to me.Btw,I'm not sure if "size sequence" is a valid translation haha

    • @cellardoor8943
      @cellardoor8943 8 лет назад

      i don't think so.If that was the case,we would need 1 more number.

    • @mohdarshulmansoori9200
      @mohdarshulmansoori9200 6 лет назад

      It means you have matrices of order 2x3, 3x4, 4x5, 5x6, 6x7.

  • @darogajee3286
    @darogajee3286 7 лет назад

    Do Full video on Theory of Computation
    According to sylllabus of IPU/Delh MCA..

  • @harshitagarwal5188
    @harshitagarwal5188 8 лет назад

    i was a little confused on how to display the odering of multiplication and ur git repo too doesn't have path back tracking implementation ,can u implement path backtracking on ur git repo ?

  • @bhavanabharatisingh4135
    @bhavanabharatisingh4135 7 лет назад

    Just Awesome !!!