Matrix Chain Multiplication Dynamic Programming

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ก.ย. 2024
  • Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
    NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, you will learn about Matrix Chain Multiplication problem using Dynamic Programming. In this question :
    1. You are given an array(arr) of positive integers of length N which represents the dimensions of N-1 matrices such that the ith matrix is of dimension arr[i-1] x arr[i].
    2. You have to find the minimum number of multiplications needed to multiply the given chain of matrices.
    To attempt and submit this question, click here: www.pepcoding....
    For a better experience and more exercises, VISIT: www.pepcoding....
    Have a look at our result: www.pepcoding....
    Follow us on our FB page: / pepcoding
    Follow us on Instagram: / pepcoding
    Follow us on LinkedIn: / pepcoding-education

ความคิดเห็น • 98

  • @ashwinvarma9349
    @ashwinvarma9349 3 ปีที่แล้ว +18

    I always prefer your videos over others' for the depth you cover. Great explanation sir once again!!

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว +2

      Awesome, thank you!

  • @chandrakantshinde6
    @chandrakantshinde6 3 ปีที่แล้ว +21

    perquisite for this problem is Palindrome partitioning problem and for Palindrome partitioning problem prereq. is Rod cutting problem, this series itself DP 😂😂🔥🔥, depend upon previous state

    • @mickyman753
      @mickyman753 3 ปีที่แล้ว

      that palindrome partitioning also needs count of palindromic substring for that gap strategy matrix matrix too

    • @karanveersingh5535
      @karanveersingh5535 2 ปีที่แล้ว

      😂

    • @abhilashpatel6852
      @abhilashpatel6852 ปีที่แล้ว +1

      This video itself is prerequisite for ballon burst problem 😂.

  • @toomuchpoop450
    @toomuchpoop450 3 ปีที่แล้ว +32

    The explanation was great as always sir. I would recommend including a recursive approach too in the video. If in an interview we directly give DP solution the interviewer might think ki ratt liya hai bande ne.

    • @shubhamagarwal2998
      @shubhamagarwal2998 3 ปีที่แล้ว +5

      then why he is asking a easily available question...xd... practice nahi karein kya......

    • @theuntoldtree
      @theuntoldtree 2 ปีที่แล้ว +2

      These r trivial questions , hardly any interviewer ll ask

    • @decostarkumar2562
      @decostarkumar2562 2 ปีที่แล้ว

      @@theuntoldtree Really 🤔

    • @theuntoldtree
      @theuntoldtree 2 ปีที่แล้ว

      @@decostarkumar2562 yeah,same to nhi puchhega

    • @deeptimittal05
      @deeptimittal05 2 ปีที่แล้ว +1

      @@theuntoldtree hello vro, good to see you here😂^_^

  • @asthagupta3813
    @asthagupta3813 2 ปีที่แล้ว +4

    Gap strategy kaha par milegi

  • @harshshukla7260
    @harshshukla7260 3 ปีที่แล้ว +3

    Thank you very much Sir. Best explanation. Bahut acha padhaate hai aap. You value your viewers.

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review - g.page/Pepcoding/review?rc

  • @devkumar9889
    @devkumar9889 2 ปีที่แล้ว +1

    This series is underrated

  • @mdnazirhusain1721
    @mdnazirhusain1721 2 ปีที่แล้ว +3

    Brust ballon problem solve krne k liye Matrix chain problem dekho ar Matrix chain problem ko solve krne k liya pallendromic cut wali video dekho ye ksa endless loop h😂😂

  • @aritralahiri8321
    @aritralahiri8321 3 ปีที่แล้ว

    Wonderful explanation once again . Love the way you go in the very depth of every problem . Thanks a lot Sir !

  • @rakshitdevra7060
    @rakshitdevra7060 2 ปีที่แล้ว

    Hats off sir for such dedication towards teaching.

  • @hritikanand9734
    @hritikanand9734 ปีที่แล้ว +1

    Osm explanation 😍😍

  • @karthikrashinkar204
    @karthikrashinkar204 2 ปีที่แล้ว +2

    please rearrange the playlist properly sir, I don't know where gap strategy is explained. Im watching video according to playlist. 🙏🏾🙏🏾🙏🏾🙏🏾

  • @deeksha6514
    @deeksha6514 3 ปีที่แล้ว +2

    Thanks a lot, Sir for this amazing explanation.

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      You are most welcome😊
      Keep watching and keep learning🙏

  • @DivyaPrakash-bj6zk
    @DivyaPrakash-bj6zk 2 ปีที่แล้ว

    Sir bhut maza aa gaya . Awesome .

  • @manishkumarsingh4631
    @manishkumarsingh4631 2 ปีที่แล้ว +2

    22/79 Done

  • @kirtimaangogna8468
    @kirtimaangogna8468 3 ปีที่แล้ว +1

    Hello sir, Kya aap abi sirf DP k questions complete karoge ya sath me parallel me aur koi topic b karoge ?
    Agar ap koi aur topic parallel me karoge to uska nam bata dijiye taki wo dusre source se parh k time waste na karen ham,
    Thank you so much for this awesome content.

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว +2

      Hashmap-Heaps parallel mei kar rha hun. Thank you for the kind words.

  • @HappyHappy-ih5zp
    @HappyHappy-ih5zp 3 ปีที่แล้ว

    subscribe bhi kr dia and bell notification bhi dba di. Great Content Sir Thank You very Much.

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Thank you so much keep motivating, keep learning and keep loving Pepcoding😊

  • @nknidhi321
    @nknidhi321 2 ปีที่แล้ว

    Maza aa gaya !! ❤️
    Thank you 🙏🏼

  • @priyanshukhullar5836
    @priyanshukhullar5836 4 ปีที่แล้ว +2

    Great sir burst balloon bhi post kijiye sir jldi . Aapse sikhna hai

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว

      hanji. ajkal mei dalega.

  • @umangbehl8152
    @umangbehl8152 2 ปีที่แล้ว

    as soon as i see your video i ignore others and click on it because you drill the concepts in the head

  • @ankushmilan6167
    @ankushmilan6167 2 ปีที่แล้ว +3

    Can someone please tell me what is the first video in which gap strategy is been taught?

    • @Pepcoding
      @Pepcoding  2 ปีที่แล้ว

      For better experience, precised content you should visit - nados.pepcoding.com
      ✅ Signup to NADOS
      ✅ And boost your coding career

    • @amanshrivansh2847
      @amanshrivansh2847 2 ปีที่แล้ว +2

      Diagonal traversal of an array

  • @rohandevaki4349
    @rohandevaki4349 2 ปีที่แล้ว

    working sir, thanks for the great explaination .

  • @ashutak
    @ashutak 3 ปีที่แล้ว +4

    How did you decide you are going to use Gap Strategy, could you please also explain, where this one becomes different from Longest common subsequence, or how many other ways will be there to solve this problem.

    • @gouravgoel2974
      @gouravgoel2974 3 ปีที่แล้ว

      yes please sumit sir

    • @jatinlodhi980
      @jatinlodhi980 2 ปีที่แล้ว

      Where you see problem is kind of sub arrays like ab BC ABC bcd. Because the complete abcde is forming from all that sub parts which is present in gap strategy matrix.

  • @ZentrexGaming
    @ZentrexGaming 3 ปีที่แล้ว

    Sir, Maza aa gaya. Kya mast samjhate ho aap yaar. LITERAL GOD. I hope god bless you and your family. MAST VIDEO

  • @shivammehta9661
    @shivammehta9661 3 ปีที่แล้ว

    Very NIce Explanation

  • @factswithai2
    @factswithai2 3 ปีที่แล้ว +1

    as usual "east or west sumeet sir is the best"

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Keep learning, Keep growing and keep loving Pepcoding!😊

  • @mickyman753
    @mickyman753 3 ปีที่แล้ว

    sir ye questions ko yaad krna pdega kya , kyuki iska method kahi aur nhi lgta hai aur easy to visualise bhi nhi hai

  • @schwarzenneger9240
    @schwarzenneger9240 4 ปีที่แล้ว +4

    Sir aap live kyu nhi aate ajkal ? (9pm wala)

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว +13

      10 video bnae bina sharam aati hai live ane mei

    • @sauravsharma4615
      @sauravsharma4615 4 ปีที่แล้ว

      @@Pepcoding sir is there any way to be teaching assistant in pepcoding ,i have experience

    • @sauravsharma4615
      @sauravsharma4615 4 ปีที่แล้ว

      Of 4 months at CN in C++ Data Strt.

  • @nehasht2
    @nehasht2 2 ปีที่แล้ว

    Love ur explanations ...

    • @Pepcoding
      @Pepcoding  2 ปีที่แล้ว +1

      Thanks a ton.
      For better experience and well organised content sign up on nados.io
      And for being updated follow us on Instagram instagram.com/pepcoding/

    • @nehasht2
      @nehasht2 2 ปีที่แล้ว

      @@Pepcoding sure

  • @princypareek2992
    @princypareek2992 3 ปีที่แล้ว +2

    Sir pls ek baar iss ka recursive code bhi bata dijiye na..

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Hanji beta, ek bari jo agenda main questions h vo complete kr le, then ye sb cheeze bhi cover kr lenge

  • @ArcGaming07YT
    @ArcGaming07YT 2 ปีที่แล้ว

    is there solution for above with n² complexity

  • @payalsagar1808
    @payalsagar1808 3 ปีที่แล้ว +1

    Epic ❤️

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem. If you like our efforts, will you like to review us here - g.page/Pepcoding/review?rc

  • @optimizer_____2420
    @optimizer_____2420 3 ปีที่แล้ว +1

    Can it be solved in n2 time complexity as min cut palindrome question?

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.

  • @kunjpatel1703
    @kunjpatel1703 3 ปีที่แล้ว

    Great Video.
    Just one thing, this solution is giving TLE in python on pepcoding.

  • @anurag4316
    @anurag4316 3 ปีที่แล้ว +1

    hello sir aap at 19:20 par jo loop lagake bol rahe ho mai umeed karta hu aapko ata hoga uska explanation kaha mil sakta hai apne kisi previous video mae keya hai explain please it will be very helpfull and sir love your videos

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว +2

      Here you'll find the gap strategy - www.pepcoding.com/resources/data-structures-and-algorithms-in-java-levelup/dynamic-programming/lps-official/ojquestion.
      Keep learning and keep growing😊

  • @twicein14days
    @twicein14days ปีที่แล้ว

    18:45

  • @NeerajSharma-mz4es
    @NeerajSharma-mz4es 3 ปีที่แล้ว +1

    After rod cutting one can easily solve this thanks sir

  • @rahulbhatia3075
    @rahulbhatia3075 4 ปีที่แล้ว

    Nice video

  • @devanshubilthare5277
    @devanshubilthare5277 3 ปีที่แล้ว

    Sir, dp ma confidence nhi aa rha, abhi bhi koi naye question ko soch nhi pata dp ma. Foundation ke saare questions kre ha aur levelup ke bhi 30 questions kr chuka hu dp ke. Koi tip dijiye Sumit sir

    • @anjneysingh2090
      @anjneysingh2090 3 ปีที่แล้ว

      Maths and memization

    • @mickyman753
      @mickyman753 3 ปีที่แล้ว +1

      bhai common questions ko group krke revise krte rho ,agr ye 70-80 questions kaise bhi krke aate hia toh aage probability jyada hogi ki question ban jaega

  • @nehaagrawal177
    @nehaagrawal177 2 ปีที่แล้ว

    sir, gap strategy ka video kaunsa hai

    • @Pepcoding
      @Pepcoding  2 ปีที่แล้ว

      visit nados.pepcoding.com, post your doubts; there our community will help you out.

  • @karanveersingh5535
    @karanveersingh5535 2 ปีที่แล้ว

    ❤️🔥💯

  • @mukeshojha9318
    @mukeshojha9318 4 ปีที่แล้ว

    Sir i am facing problems that i can not convert my logics into code , so i can not solve any of your question without watching your videos but i understand logic quickly. help me sir.

    • @anjneykumarsingh4461
      @anjneykumarsingh4461 4 ปีที่แล้ว

      Bhai ap glt jgh agya ye level up h, ap 4-5 baari foundation cover kijiye phir hojayega

    • @mukeshojha9318
      @mukeshojha9318 4 ปีที่แล้ว

      @@anjneykumarsingh4461 mai foundation course hi kar rha hu ye letest video tha isliye ispr comment kiya

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว +4

      beta, thoda karte karte aaega. 200-300 question jis din kar doge firr nahi aaegi ye problem

    • @mukeshojha9318
      @mukeshojha9318 4 ปีที่แล้ว

      @@Pepcoding thanks sir I will not losing hope. You hard work inspired me a lot.

  • @kushagrashekhawat8227
    @kushagrashekhawat8227 3 ปีที่แล้ว

    Sir, DP kb tk complete ho jayegi??

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว +2

      25 din aur

  • @ashirwadshukla8221
    @ashirwadshukla8221 3 ปีที่แล้ว

    Million likes video this is

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Thank you so much and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @dipuprasad9196
    @dipuprasad9196 3 ปีที่แล้ว +1

    Sir apjo samjha dete hai wo kathin bilkul bhi nhi lagta

  • @b.sainathreddy4567
    @b.sainathreddy4567 3 ปีที่แล้ว

    nice

  • @viditvaish7317
    @viditvaish7317 2 หลายเดือนก่อน

    i swere no one cam ever match you in terms of explanation

  • @cyberpolice3183
    @cyberpolice3183 2 ปีที่แล้ว

    maja aya

  • @ayushmansharma5321
    @ayushmansharma5321 2 ปีที่แล้ว +1

    //MATRIX CHAIN MULTIPLICATION(Strategy according to recursion example) + Memoization
    import java.util.*;
    public class Main{
    //Size of the Array is upto 1000....
    static int dp[][] = new int [1001][1001];
    public static void main(String args[]){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();

    int arr[] = new int [n];

    for(int i=0;i=j){
    dp[i][j] = 0;
    return 0;
    }

    else if (dp[i][j]!=-1) return dp[i][j];
    else{
    int minimum = Integer.MAX_VALUE;
    for(int k=i;k

  • @technicalrobot9685
    @technicalrobot9685 ปีที่แล้ว

    // Recursion + DP (Java)
    import java.io.*;
    import java.util.*;
    public class Main {
    static int dp[][]=new int[1002][1002];
    public static int mcm(int[] arr){

    return solve(arr, 1, arr.length-1);

    }
    public static int solve(int arr[], int i, int j)
    {
    if(i>=j){
    return 0;
    }

    if(dp[i][j] != 0)
    {
    return dp[i][j];
    }

    int min = Integer.MAX_VALUE;

    for(int k=i; k

  • @manishkumarsingh4631
    @manishkumarsingh4631 2 ปีที่แล้ว +1

    22/79 Done