Matrix Chain Multiplication Dynamic Programming

Поділитися
Вставка
  • Опубліковано 25 сер 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

  • @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 😂.

  • @ashwinvarma9349
    @ashwinvarma9349 3 роки тому +18

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

  • @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 Рік тому +1

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

  • @asthagupta3813
    @asthagupta3813 2 роки тому +3

    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 Рік тому +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😂😂

  • @rakshitdevra7060
    @rakshitdevra7060 Рік тому

    Hats off sir for such dedication towards teaching.

  • @aritralahiri8321
    @aritralahiri8321 3 роки тому

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

  • @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. 🙏🏾🙏🏾🙏🏾🙏🏾

  • @hritikanand9734
    @hritikanand9734 Рік тому +1

    Osm explanation 😍😍

  • @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

  • @DivyaPrakash-bj6zk
    @DivyaPrakash-bj6zk 2 роки тому

    Sir bhut maza aa gaya . Awesome .

  • @manishkumarsingh4631
    @manishkumarsingh4631 2 роки тому +2

    22/79 Done

  • @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

  • @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 🙏🏼

  • @deeksha6514
    @deeksha6514 3 роки тому +2

    Thanks a lot, Sir for this amazing explanation.

    • @Pepcoding
      @Pepcoding  3 роки тому

      You are most welcome😊
      Keep watching and keep learning🙏

  • @priyanshukhullar5836
    @priyanshukhullar5836 3 роки тому +2

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

    • @Pepcoding
      @Pepcoding  3 роки тому

      hanji. ajkal mei dalega.

  • @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.

  • @rohandevaki4349
    @rohandevaki4349 2 роки тому

    working sir, thanks for the great explaination .

  • @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

  • @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!😊

  • @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.

  • @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

  • @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

  • @ArcGaming07YT
    @ArcGaming07YT Рік тому

    is there solution for above with n² complexity

  • @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

  • @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 2 роки тому

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

  • @twicein14days
    @twicein14days Рік тому

    18:45

  • @schwarzenneger9240
    @schwarzenneger9240 3 роки тому +4

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

    • @Pepcoding
      @Pepcoding  3 роки тому +13

      10 video bnae bina sharam aati hai live ane mei

    • @sauravsharma4615
      @sauravsharma4615 3 роки тому

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

    • @sauravsharma4615
      @sauravsharma4615 3 роки тому

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

  • @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

  • @rahulbhatia3075
    @rahulbhatia3075 3 роки тому

    Nice video

  • @NeerajSharma-mz4es
    @NeerajSharma-mz4es 3 роки тому +1

    After rod cutting one can easily solve this thanks sir

  • @karanveersingh5535
    @karanveersingh5535 2 роки тому

    ❤️🔥💯

  • @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.

  • @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 )

  • @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😊

  • @mukeshojha9318
    @mukeshojha9318 3 роки тому

    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 3 роки тому

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

    • @mukeshojha9318
      @mukeshojha9318 3 роки тому

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

    • @Pepcoding
      @Pepcoding  3 роки тому +4

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

    • @mukeshojha9318
      @mukeshojha9318 3 роки тому

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

  • @b.sainathreddy4567
    @b.sainathreddy4567 3 роки тому

    nice

  • @kushagrashekhawat8227
    @kushagrashekhawat8227 3 роки тому

    Sir, DP kb tk complete ho jayegi??

  • @dipuprasad9196
    @dipuprasad9196 3 роки тому +1

    Sir apjo samjha dete hai wo kathin bilkul bhi nhi lagta

  • @cyberpolice3183
    @cyberpolice3183 2 роки тому

    maja aya

  • @viditvaish7317
    @viditvaish7317 Місяць тому

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

  • @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