Dynamic Programming with Java - Learn to Solve Algorithmic Problems & Coding Challenges

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 พ.ย. 2024

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

  • @aanchaallllllll
    @aanchaallllllll ปีที่แล้ว +29

    0:00: 💡 Dynamic programming is a method for solving complex problems by breaking them down into simpler overlapping subproblems and storing solutions to avoid redundant computations.
    10:37: 🌳 The complexity of the recursive solution is very large and difficult to analyze due to the asymmetry of the tree.
    21:27: 📝 The process involves calculating Fibonacci numbers and storing them in a memo to avoid redundant calculations.
    32:21: ⏰ By implementing memoization, the time complexity of the solution improves to O(n).
    43:20: ⏱ The code is too slow and needs memoization to improve its speed.
    53:19: 📊 Implementing memoization strategy in a recursive algorithm can reduce the exponential complexity to linear complexity.
    1:03:37: 💰 The goal is to find the minimum number of coins required to reach a target amount.
    1:13:54: 🔑 The approach is to optimize for the number of coins needed to create a given amount.
    1:24:17: 🌳 The problem can be represented as a tree, where each node represents a possible path in the grid.
    1:34:31: 🔢 The code is implementing a recursive function to count the number of paths to a goal position.
    1:45:46: 🔍 The code sets up a method to track a position in a grid and checks for base cases.
    1:56:26: 🌳 The problem at hand involves a dynamic programming approach to finding duplicate subtrees in a larger tree.
    2:06:57: 🔑 The code snippet describes the implementation of memoization in a recursive method using a hashmap.
    2:17:21: 🔍 The code is finding the minimal sum of squares using a recursive helper method.
    2:28:23: 🔢 The Java walkthrough for the counting change problem involves implementing a recursive method with an additional argument.
    Recap by Tammy AI

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

      Thanks so much

  • @rs4267
    @rs4267 17 วันที่ผ่านมา +1

    Thank you for this video! I really appreciated the explanation of memoization using HashMap. However, I took a slightly different approach in my own code for calculating Tribonacci. Instead of passing the HashMap as a parameter in each function call, I decided to use an instance variable in my classe Source to store the memoized results. This makes the code cleaner and allows easier access to the stored values without having to pass them around. =>
    public class Fibonacci {
    Map memo = new HashMap();
    public static void main(String[] args) {
    Fibonacci fibonacci = new Fibonacci();
    fibonacci.memo.put(0,0);
    fibonacci.memo.put(1,1);
    public Integer run(int n) {
    if (this.memo.containsKey(n)) {
    return this.memo.get(n);
    }
    // calculation and memoization...
    }

  • @zakariaelmoumnaoui4912
    @zakariaelmoumnaoui4912 ปีที่แล้ว +120

    Finally Java this time

    • @gradientO
      @gradientO ปีที่แล้ว +9

      It's concepts that are important, not the language

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

      Python onlyone

    • @Carlos-kv6hx
      @Carlos-kv6hx ปีที่แล้ว +1

      I agree but like 90% of content is web dev here

    • @-karter-4556
      @-karter-4556 ปีที่แล้ว +2

      @@gradientO there is memoric value in applying concepts in an already familiar programming language.

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

      Yup 👍🏻

  • @dkdraipur
    @dkdraipur ปีที่แล้ว +10

    The best ever tutorial make on DP. Using HashMap removes all the ambiguity around the DP. Kudos

  • @sidharth-singh
    @sidharth-singh ปีที่แล้ว +2

    I struggled with Dynamic Programming for past 3 years. This video is amazing! By the half of it, I was already on my way solving them. I like the last one. It was a different variety in itself. I thought of a solution actually storing the paths in a "Set" and then count the length of the "Set". I never thought of this way for this problem . Even though choosing or not choosing is a common pattern in recursion. THNAK YOU SO MUCH!!

    • @pleasantdayNwisdom
      @pleasantdayNwisdom 7 หลายเดือนก่อน

      bhai maene bhi itna acha dp course nhi dekha , striver etc were not teaching simple way , mera yeh feel aaya , i saw his approach for 2 problems and then own my own till the last one ,stuck ho gya hu , mae bhi set wala hi soch rha hu , but pta h kuch better way ho skta h , i want to do this last question on my own

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

    This is exactly what I've been looking for! Dynamic programming can be tricky, but solving algorithmic problems with Java makes it so much easier to grasp. Can't wait to dive into these coding challenges and improve my problem-solving skills. 💻🔥 Thanks for making complex concepts so accessible!

  • @bcampera
    @bcampera 8 หลายเดือนก่อน

    Man there are great vids out there but you're the only one that made me really understand this in a simple manner, I don't feel stupid any more. Thank you so much!

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

    This is absolutely elite, thanks for making this available to the community for free. Just to build on this for learners here, you probably want to explore an iterative solution to the "non-adjacent sum" since large array inputs will blow up your call stack in the recursive approach.

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

    I would like to say thank you to the instructor for providing this knowledge for free on this platform

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

    33:02 This algorithm works only up to fib(46) including. In Java, the int data type has a maximum value of 2,147,483,647 , so if you wanna make the algorithm efficient for every value of n, change the int keyword with long . because if you don't fib(47) will return -1323752223 instead of 2971215073.

  • @justindouglas3659
    @justindouglas3659 ปีที่แล้ว +10

    Finally something i can use to learn. Thank you so much.

  • @MyCodingDiary
    @MyCodingDiary ปีที่แล้ว +10

    You're doing an amazing job at explaining coding concepts. Keep up the great work!

  • @pleasantdayNwisdom
    @pleasantdayNwisdom 7 หลายเดือนก่อน

    Thankyou Alvin Sir , I did Sum possible problem on my own , saw many recommended playlist on dp , but ur way of explanation worked for me ! Happy ! thankyou code camp :) but one slight doubt , like for this question sum possible , suppose if zero digit is required for amount =0 , then what would have been the base case?

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

    This is what needs to be used for the frontend components. Then the communication between components and branches is a breeze. You can send any event with any data to any point and fully control the sequence of those threads at any time. Then components have to be the object of the same class and share the same methods of communication.

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

      Can you explain using examples of where this is used in frontend ?

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

      @@vedangarekar1390 All frontend components should be organized in one tree which becomes a bus for communication between them. The simplest example is the DOM itself, but components may be more complex that just a single HTML tag. HTML becomes a template only for a component. There should be a common class “component/widget/actor”, which all component objects of different types are created from. The best way to understand is the Actor Model by Carl Hewitt. You can google “actor model javascript” to see various examples.

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

    ### Resumo
    Neste conteúdo, Alvin Zablin ensina sobre programação dinâmica, com foco em resolver problemas de Fibonacci de forma recursiva com memoização. Ele começa explicando os conceitos básicos da programação dinâmica e o problema de Fibonacci. Em seguida, ele mostra como resolver o problema de Fibonacci de maneira recursiva, incluindo base cases para 0 e 1. Além disso, ele introduz a estratégia de memoização, onde os resultados são armazenados para evitar cálculos duplicados e melhora o desempenho. Alvin também discute a complexidade de tempo e espaço do algoritmo, destacando a eficiência da abordagem de memoização.
    ### Destaques
    - 📚 Programação dinâmica é usada para resolver problemas complexos quebrando-os em subproblemas sobrepostos e armazenando soluções para evitar cálculos redundantes.
    - 🧮 O problema de Fibonacci é um exemplo clássico usado para entender a programação dinâmica.
    - 🤖 Alvin Zablin ensina como resolver o problema de Fibonacci de forma recursiva, com base em base cases para 0 e 1.
    - 📊 A estratégia de memoização envolve armazenar resultados para evitar recalculos, melhorando o desempenho.
    - 🕰 A complexidade de tempo do algoritmo de Fibonacci com memoização é O(n), enquanto a complexidade de espaço é O(n), tornando-o eficiente.

  • @sathishkumar-rc4se
    @sathishkumar-rc4se ปีที่แล้ว

    In the Sum Possible Challenge he has added the Memo Hashmap inside the If Condition (1:03:45), In general if the Condition is met then the it return the value as True and Loop ends whats the Point in adding the Memo HashMap inside that Condition!

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

      here is chatgpt's answer
      Yes, you're right. Once any branch returns true, the answer for the top-level problem has been found, and you can halt further exploration. Any subsequent or sibling branches don't need to be explored. The recursive call stack will unwind, and true will propagate all the way up, ultimately indicating that the target sum can be achieved with the given numbers.
      The value in memoizing the result (true or false) for a specific target is to handle situations where you're exploring other potential branches or paths before you find one that leads to a solution. Memoization can also be beneficial if you're solving different instances of the problem (e.g., checking for multiple different target values) during the program's execution. However, within the context of a single invocation and after finding a valid combination, you're right that the memoized values won't be accessed since you'd halt the process and return true.
      If you're focused on optimizing purely for the scenario where you halt immediately upon finding a solution, you can indeed skip memoizing the true result in the current context, since it won't be accessed again. The key is understanding the trade-offs and tailoring the approach to the specific requirements and constraints of the situation at hand.

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

      exactly, the main idea is false memos can save a few recursive calls, if its true it just returns so no point in caching.

  • @susantamandal2782
    @susantamandal2782 6 หลายเดือนก่อน +1

    I was going through the Non Adjacent Sum Tree structure and found some of the portions are getting missed. I was looking for any better explanation.
    1:57:00

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

    Great tutorial because everything taught here is easy or made easy to understand.

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

    In the "max path sum" problem using double is not necessarily a good idea. Although it would require an extremely large grid with large numbers to fail, theoretically it can fail due to number representation / precision issues, especially as a "rolling sum" is being calculated (well, to be honest, this would require a long in the "main method" instead of int - but one should still think about these potential issues, that is the important bit here).
    It would have been more straightforward to simply use Integer.MIN_VALUE (or in case of really big inputs, Long. MIN_VALUE) in the initialization. (The performance can be slightly better as well for a really big input.)

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

    this is such a fascinating way of solving problems! I love it!

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

    Amazing lesson Teacher! Than'k!

  • @hend3gossate
    @hend3gossate 4 หลายเดือนก่อน

    besides dynamic programming we can traverse answer tree like bfs instead of dfs

  • @jayjaayjaaay94
    @jayjaayjaaay94 10 หลายเดือนก่อน

    I don't understand count paths problem, you use c== grid.get(0).size() which actually get the right top? 🤔 🤔 Shouldn't we check the right bottom of the grid? c==grid.get(grid.size() - 1).size()
    Please help me

  • @thusith-tec307
    @thusith-tec307 ปีที่แล้ว +3

    Wow... Java. Thank you

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

    I love your lectures... ❤️🥰

  • @amalayounes
    @amalayounes 8 หลายเดือนก่อน

    This is amazing stuff!! Thank you so much.

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

    can you please upload videos on power BI
    you're channel is best learning resource for us

  • @leomamaci376
    @leomamaci376 ปีที่แล้ว +9

    Finally Java, been waiting for it so long 🎉

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

    Thanks for the video, I really got an idea about DP

  • @jayjaayjaaay94
    @jayjaayjaaay94 10 หลายเดือนก่อน

    I don't understand, in count path problems, why it check c== grid.get(0).size?
    Isn't checking right top? 🤔 Shouldn't we check the right bottom?
    Which is
    c== grid.get(grid.size - 1).size?

  • @ka1pana
    @ka1pana 11 หลายเดือนก่อน

    The 0 base case in the Sum possible problem, qualifies as "true" is not clear. Question was are there ways of using the numbers given to add up to the amount. If Amount 0, and numbers are 1, 2, 3 we cannot use any of the numbers to add to 0 (assuming all numbers are positive), so the answer is false right ?

    • @ShubhangiDutta
      @ShubhangiDutta 11 หลายเดือนก่อน

      I think that its referring to case where the amount can be made without choosing any option for the list- so even if you have say 1, 2 and 3, you can always make 0 by never adding any of them, hence true. The same applies to the minChange problem.

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

    Alvin lets goooo!!!

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

    Great tutorials !
    Please make your syntax text larger. Many Thanks !!!

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

    Can you please do this using C# as well?
    Show some love to C#. It’s such a nice language.

  • @fumano2679
    @fumano2679 11 หลายเดือนก่อน

    Hey found here through advent of code 2023 day 12 part 2. Greetings :)

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

    YASSS. I was doing my research paper or project on it just this term

  • @RaviKumar-v9b6m
    @RaviKumar-v9b6m ปีที่แล้ว

    Non adjacent problem I think we can easily solve using For loop

  • @yourpoookieboo
    @yourpoookieboo 9 หลายเดือนก่อน

    Half way through, i get the sums clearly cus of the tree based visualisation for dp or recursion nice hack there, however the count paths sum could have been a bit more in depth , anyway kudos

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

    this is really good. Thank you!

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

    Thanks

  • @StarContract
    @StarContract 10 วันที่ผ่านมา

    I think you have an error in the solution for the non-adjacent-sum problem.
    for the following list: [1,3,5,12,8,5]
    the result should be 17;
    your code result is 20.
    correction:
    return Math.max(
    nums.get(i) + max(nums, i + 2),
    maxNonAdjacentSum(nums, i + 1)
    );

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

    Is there one in c++

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

    Oh my god I am struggling with these kinds of problems and you heard it 😂😂

  • @anon-fz2bo
    @anon-fz2bo ปีที่แล้ว

    hell yea i love dynamic programming

  • @santhoshjoruka2036
    @santhoshjoruka2036 8 หลายเดือนก่อน

    In the count paths problem how did you come up with this logic countPaths(r + 1, c, grid, memo) + countPaths(r, c + 1, grid, memo)? anyone who understands can help on this.

  • @rebelgirl3107
    @rebelgirl3107 6 หลายเดือนก่อน

    Sir, I have a question about dynamic programming, how can I reach you?

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

    To demonstrate a solution to the min change problem the selected problem instance must be so typical that the application of greedy method fails on it.

  • @ankitg6454
    @ankitg6454 8 หลายเดือนก่อน

    Many many thanks

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

    I wish do it with JS or Python

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

      the concepts are way more important than the language implementation

  • @tahitivn
    @tahitivn 5 หลายเดือนก่อน

    view on many videos, this is easier to understand concepts

  • @MarouanBoukli
    @MarouanBoukli 8 หลายเดือนก่อน

    1:18:00 doesn't the minCoins get overwritten every time?

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

    More Java content please

  • @Sisyphus3.14
    @Sisyphus3.14 ปีที่แล้ว +8

    tutorial hell

    • @Robo_Mark-8
      @Robo_Mark-8 ปีที่แล้ว +2

      good for beginners bad for intermediate 😂😂

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

    Thanks!

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

    Thanks👍❤🙏

  • @-karter-4556
    @-karter-4556 ปีที่แล้ว

    Finallyyyy!!!!

  • @ForRo3sS
    @ForRo3sS 5 หลายเดือนก่อน

    This is good

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

    Next up with Python, !!

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

    👌🏻

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

    Is this for beginner ?

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

    Hey hii.....I want complete begginer level to high DynamicProgramming DSA in python....

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

    Hello
    freeCodeCamp how are you I hope you all are well,
    One request please make an "Object-C" mobile app development crash course please,
    Thanks;

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

    Please make trees and graphs in java please

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

      If you cannot follow even a simple example, you'd better look for a simpler career.

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

      @@aammssaamm thank you

  • @Max-tq1ig
    @Max-tq1ig ปีที่แล้ว

    Your mustache is gone, Alvin!

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

  • @SphereofTime
    @SphereofTime 4 หลายเดือนก่อน

    3:23

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

    Too many "rights". It's a common problem.

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

    Hiii

  • @Travelophile
    @Travelophile 7 หลายเดือนก่อน

    this will fail for input [1,2,5] , due to the memoization

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

    My name is bikram barman... From India West Bengal

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

    The lecturer probably knows this, but i cant watch a video where somebody uses an explicit HashMap in a method signature. Makes me wonder which other bad principles are included that i might not notice.

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

      What do you suggest instead?

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

      @@jagi7976 always use interface types, so in this case Map. It doesnt matter if it does not make a difference in this specific case. Some things need to be like muscle memory.

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

      so you have nothing good to say about this great, free lecture? What principles dude, he isn't writing enterprise solutions. It is just a single method. You want him to use dependency injeciton too?

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

      @@Yash42189 Dependency injection would include unnecessary complexion. Using an interface would not, it barely changes what he would have to write.
      And no, i have nothing good to say because i did not watch it after that, as i already said.

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

    Wait, do you think cryptocurrency will crash? I dont think so. More and more companies are integrating cryptocurrency into their operations: Amazon, Cannafarm Ltd, Burger King, even Starbucks, dude!

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

    Java is great language, but not for coding interviews come on...

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

    I dont know, dudes. I think crypto and all these ICOs are just a bubble. Well, crypto is good for transfers and so on, but I dont engage in trading and staking either. Its too risky. My friend recently lost $5000 there. I invest crypto in real business

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

    In your implementation(tribonacci), n(0) and n(1) both return 0, which is incorrect. n(1) should return 1
    @alvinzablan

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

    Thanks!

  • @sadiulhakim7814
    @sadiulhakim7814 5 หลายเดือนก่อน

    Thanks

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

    Hello
    freeCodeCamp how are you I hope you all are well,
    One request Please make an "Object-C" mobile app development crash course please,
    Thanks;