Daniel Sutantyo
Daniel Sutantyo
  • 78
  • 146 696
CP-3.104 - Dynamic Programming - Walrus Weights (Subset Sum, Bottom Up DP)
Problem: Walrus Weights Part 2 (open.kattis.com/problems/walrusweights/)
The video is a continuation of ua-cam.com/video/63f33LGNsrs/v-deo.html, where I showed how to solve the SubsetSum problem using top-down dynamic programming. In this video, I show how to solve SubsetSum using
bottom-up dynamic programming, which is also how we can solve the
Walrus Weights problem.
0:00 - Problem description
2:41 - SubsetSum problem using bottom-up dynamic programming
7:34 - Coding the solution
16:40 - Outro
Please note that all views and opinions expressed in this video are my own and does not reflect that of Kattis or any other person/organisation mentioned in the video.
Переглядів: 822

Відео

CP-3.103 - Dynamic Programming - Walrus Weights (Subset Sum, Top Down DP)
Переглядів 8232 роки тому
Problem: Walrus Weights Part 1 (open.kattis.com/problems/walrusweights/) The above problem is a variation of the SubsetSum problem (which is an NP problem), so in this video I discuss how to do SubsetSum using top-down dynamic programming. I won't actually discuss how to do Walrus Weights yet, this is done in the next video. We also did SubsetSum using recursive backtracking in a previous video...
CP-3.102 - Dynamic Programming - Ocean's Anti 11
Переглядів 3442 роки тому
Problem: Ocean's Anti-11 (open.kattis.com/problems/anti11) Another question that can be done using dynamic programming, continuing from the previous video. Please make sure you are comfortable with recursive backtracking before going through with this video. If you want to check out the video on breaking down problems into subproblems, please see this playlist: ua-cam.com/video/snBcanv7m04/v-de...
CP-3.101 - Dynamic Programming - Pebble Solitaire 1 & 2
Переглядів 1,4 тис.2 роки тому
Problem: Pebble Solitaire (open.kattis.com/problems/pebblesolitaire and open.kattis.com/problems/pebblesolitaire2) Our first problem using dynamic programming (specifically, top-down dynamic programming). As I explain in this video, this is definitely not a traditional way of introducing dynamic programming, but there's already so many resources for that out there, so there's really no point of...
CP-3.004 - Recursive Backtracking - Good Morning! (Kattis)
Переглядів 8892 роки тому
Problem: Good Morning! (open.kattis.com/problems/goodmorning) An interesting problem that we can solve using recursive backtracking. Video Sections: 0:00 - Problem description 3:16 - Outline of the solution 4:59 - Generating all the possible numbers 9:31 - Code - generating all possible numbers 21:44 - Code - finding the closest number to the input Please note that all views and opinions expres...
CP-3.003 - Recursive Backtracking - Geppetto (Kattis)
Переглядів 9092 роки тому
Problem: Geppetto (open.kattis.com/problems/geppetto) Another recursive backtracking question that is very similar to the previous video (ua-cam.com/video/dmAJMyJyxoY/v-deo.html), so please make sure you understand that video before going through this one. Video Sections: 0:00 - Problem description 4:05 - Coding - generating all the possible combinations 9:23 - Coding - removing invalid combina...
CP-3.002 - Recursive Backtracking - GroupSum (CodingBat)
Переглядів 2 тис.2 роки тому
Continuing from the previous video (ua-cam.com/video/snBcanv7m04/v-deo.html), I discuss a basic recursive backtracking question for enumerating every possible combinations in an array. If you have done one or two semesters of computing undergraduate degree, then this is probably something you already know well, but it's such an important basic skill that I think is worth reviewing. For this vid...
CP-3.001 - Visualising Problems and Subproblems
Переглядів 2,8 тис.2 роки тому
In this video I talk about how I visualise problem solving in my head, that is by breaking it down to smaller and smaller subproblems. I am going to follow this approach when explaining problem solving approaches like brute force, recursive backtracking, dynamic programming, and greedy algorithm, because ... well, that's just the way that I think! The video might be too simple for you, or too a...
CP-1.013 Java Tutorial - using classes
Переглядів 2422 роки тому
Problem: I Wanna be the Very Best (open.kattis.com/problems/iwannabe) Another custom sorting problem where I used a class to make the code simpler. Video Sections: 0:00 - Problem description 2:20 - Solution starts (using a class) 6:20 - Sorting the pokemons 12:11 - Closing comments Please note that all views and opinions expressed in this video are my own and does not reflect that of Kattis or ...
CP-1.012 Java Tutorial - Map.Entry and var
Переглядів 3022 роки тому
Problem: Sort (open.kattis.com/problems/sort) I discuss yet another way to traverse through a map: using Map.Entry, which we'll also use to 'sort' the map. I'm also starting to use the var keyword which makes life easier. I realise that I didn't fully explain how the sort works, but it's actually very simple. For descending order, given a and b, we want to return a positive number if a is less ...
CP-1.304 - C++ String Matching
Переглядів 3082 роки тому
Problem: Parsing Hex (open.kattis.com/problems/parsinghex) I discuss a couple of ways to do string matching in C , using the find function in string class and by using regex (regular expression). Of course to use regex, you need to understand how regex works, and I only touched on that very briefly. You need to work on that yourself =). For example, we can simplify the code in the end by using ...
CP-1.303 - C++ map, set, iterator, and stringstream
Переглядів 2592 роки тому
Problem: Bacon, Eggs, and Spam (open.kattis.com/problems/baconeggsandspam) Link to video about maps: ua-cam.com/video/f6hagLrbvkY/v-deo.html This is a simple "reverse a map" question which I will do using C , so you can see how we work with maps and sets in C . Most importantly, I started using iterators, which is something we use a lot in C . I also talked about stringstream which I use to tok...
CP-1.302 - C++ vector, getline, and range-based loops
Переглядів 6672 роки тому
Problem: Ragged Right (open.kattis.com/problems/raggedright) In this video I discuss how to do the following in C : - reading a whole line from standard input (getline function) - using a vector (re-sizeable array) - using range-based loop (i.e. for each loop) Video Sections: 0:00 - Problem description 1:51 - Start of solution - reading whole lines 3:30 - Using a vector 7:43 - Range-based for l...
CP-1.301 - C++ Intro
Переглядів 3852 роки тому
Problem: Seven Wonders (open.kattis.com/problems/sevenwonders) In this video, I compare Java to C , and also show my usual C setup (WSL Visual Studio Code). Please note that this is part of the series started with ua-cam.com/video/2vi1o0Fr0Uk/v-deo.html I personally prefer using C over Java, so I really want to do a series of videos on C . The problem is that I don't want to teach C , that is j...
CP-1.011 Java Tutorial - Traversing a Map
Переглядів 3062 роки тому
Problem: Warehouse (open.kattis.com/problems/warehouse) For this question, I am using TreeMap and TreeSet which are sorted (vs. HashMap/HashSet). If you are new to maps and sets, there's actually quite a lot in this video, so that's why I went a bit slow. Most importantly, I went through a couple of ways to traverse through a map, which is something I didn't do in the previous video on maps. It...
CP-1.010 Java Tutorial - Sorting an ArrayList
Переглядів 4 тис.2 роки тому
CP-1.010 Java Tutorial - Sorting an ArrayList
CP-1.009 Java Tutorial - ASCII
Переглядів 2242 роки тому
CP-1.009 Java Tutorial - ASCII
CP-2.003 - Walkthrough - Sum Kind of Problem (Kattis)
Переглядів 1,2 тис.2 роки тому
CP-2.003 - Walkthrough - Sum Kind of Problem (Kattis)
CP-2.002 - Walkthrough - Lost Lineup (Kattis)
Переглядів 4782 роки тому
CP-2.002 - Walkthrough - Lost Lineup (Kattis)
CP-1.008 Java Tutorial - StringBuilder
Переглядів 2962 роки тому
CP-1.008 Java Tutorial - StringBuilder
CP-1.007 Java Tutorial - HashMap
Переглядів 4622 роки тому
CP-1.007 Java Tutorial - HashMap
CP-1.006 Java Tutorial - HashSet
Переглядів 3222 роки тому
CP-1.006 Java Tutorial - HashSet
CP-2.001 - Walkthrough - The Amazing Human Cannonball (Kattis)
Переглядів 7632 роки тому
CP-2.001 - Walkthrough - The Amazing Human Cannonball (Kattis)
CP-1.005 Java Tutorial - String Splitting
Переглядів 4522 роки тому
CP-1.005 Java Tutorial - String Splitting
CP-1.004 Java Tutorial - Scanner .next() and .nextLine()
Переглядів 4532 роки тому
CP-1.004 Java Tutorial - Scanner .next() and .nextLine()
CP-1.003 Java Tutorial - Bit Manipulation
Переглядів 6762 роки тому
CP-1.003 Java Tutorial - Bit Manipulation
CP-1.002 Java Tutorial - Input/Output and String Processing
Переглядів 9272 роки тому
CP-1.002 Java Tutorial - Input/Output and String Processing
CP-1.001 Java Tutorial - Input/Output
Переглядів 1,8 тис.2 роки тому
CP-1.001 Java Tutorial - Input/Output
CP-1.000 - Intro to Competitive Programming with Kattis and Java
Переглядів 6 тис.2 роки тому
CP-1.000 - Intro to Competitive Programming with Kattis and Java
COMP1010 Week 12 Lecture: Introduction to Complexity Analysis Part 2
Переглядів 653 роки тому
COMP1010 Week 12 Lecture: Introduction to Complexity Analysis Part 2

КОМЕНТАРІ

  • @raednoor4215
    @raednoor4215 День тому

    Thanks for the great content.

  • @startinggintama
    @startinggintama 3 місяці тому

    Thank you. This is something I had a problem with in the second video of your playlist. Really good and underrated videos.

  • @Ahryno781
    @Ahryno781 4 місяці тому

    iam curious, should i learn from this playlist before starting CP and CP4 ? as i see many algorithms here too

    • @DanielSutantyo
      @DanielSutantyo 4 місяці тому

      Depending on which playlist? This video was a lecture for 3rd year students, so that's not a good starting point for data structures and algorithm (DSA). Your intro to DSA course would be a much better starting point, or if you don't have one, you can checkout MIT's one: ua-cam.com/play/PLUl4u3cNGP63EdVPNLG3ToM6LaEUuStEY.html The other playlist I have are support materials for the coding club at our uni, and the basic one (ua-cam.com/play/PLMDZqACtfCkN0QFu10NFx3e3P-vKB-CQ2.html) is meant for 1st year students. We use Java at our uni and the 1st year students wouldn't have done the stuff I talked about there (HashMap, StringBuilder, etc). At the same time, they're not a structured course on programming. Neither is CP1 or most competitive programming books. You really need to start with a DSA course and then complement it with CP books/resources.

  • @polycoder
    @polycoder 4 місяці тому

    Which program do you use for visualization? Thank you in advance

    • @DanielSutantyo
      @DanielSutantyo 4 місяці тому

      You mean the visualisation in the video? They're just slides. I used slides.com/ for convenience, but if you're comfortable with javascript, you can also use something like github.com/hakimel/reveal.js or github.com/impress/impress.js. I have also used d3js.org/ to make some animations in the past.

    • @polycoder
      @polycoder 4 місяці тому

      @@DanielSutantyo Thank you are the best.

  • @pragneshamadavadi2267
    @pragneshamadavadi2267 4 місяці тому

    Awesome content ❤‍🔥 explanation was on point

  • @Ahryno781
    @Ahryno781 4 місяці тому

    is kattis good for competitive programming ? should I follow CP4 book ?

    • @DanielSutantyo
      @DanielSutantyo 4 місяці тому

      Yes, but so are other resources like leetcode. Kattis questions are closer to contest questions because it doesn't tell you the approach that you should use, while in leetcode, you usually know what to do because the questions are organised by the topic =). We've been using CP4 since that's pretty much the standard book for competitive programming, and it has a list of relevant questions for each topic it discusses. CP1 and CP2 are free, and the website cpbook.net/methodstosolve has the list of Kattis questions relevant to each topic.

  • @achronicstudent
    @achronicstudent 6 місяців тому

    I have a question about 7:35 In another lecture i took they said "In binary search, typically two comparisons are indeed needed for each step: one to check if the middle element is equal to the target element, and another to decide whether to search the left or right half of the array. " and T(n) = T(n/2) + 2 I am confused could you clarify it please thank you in advance

  • @elizabeth00653
    @elizabeth00653 7 місяців тому

    Thank you so much for these informative solutions. I really hope you keep making these!!!!

  • @hritikzurange
    @hritikzurange 8 місяців тому

    Dear Professor, I am extremely grateful for the work you are doing specially the video series on CLRS. Thanks!

  • @kalebcole5579
    @kalebcole5579 9 місяців тому

    This channel is amazing. Your strategies are explained so well and have helped me greatly in solving problems!

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

    Thank you very much.. great work.

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

    The logic for the true/false return can be simplified like so: if (start == nums.length) { return target == 0; }

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

      Hi, the code is simplified, yes, but with that code, there's no 'early exit', i.e. you will keep recurse until you hit the end of the array even if it's hopeless. As a simple example, iif there's no answers, e.g. groupSum(0,[10,20,30,40,50], 5) you will evaluate all the possibilities (2^5 = 32), where as if you have the early exit (if (target < 0)) you'll only evaluate 5 times.

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

    Nd can't the user press like this after 1 can't he press the 7th key . Cause in the question it's mentioned that we can go downard and righr

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

    Why haven't u added recursion calls for numbers like 8 , 5

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

    need more videos!

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

    maybe , if you could draw out a few things so , we can get the bigger picture. Great video !please make making them

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

    Hey, I'm not aware if you still check your channel or not but if you do, please continue making videos on java+cp. Great channel <3

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

    Hi Daniel, Thanks for such a great videos on Dynamic Programing. I've improved a lot thanks to you

  • @codingcompetitiveprogrammi6118

    dari indonesia bang

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

    thanks

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

    Thank you for your lecture videos. They're really helpful.

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

    You explain in more detail than the CLRS book. Really appreciate your effort in this topic. Your video answer a lot of questions in my head. Wish a good day.

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

    Thank Daniel it is so beneficial that starting competitive programming I appreciate it.

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

    Very Good Algorithm Lectures

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

    With this, what you would say about Dynamic Programming, is it a technique which is to be applied to a problem whose subproblems overlap, and Backtracking is a technique in which all subproblems need to be solved. What about the Divide & Conquer, is it we can safely say that in D & C we divide the problem into subproblems, which are not at all related and then solve them independently, and solving the subproblems we combine their solution. Please kindly elaborate more in the light of this video.

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

    Thank you !!

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

    Hi Daniel, nice guide. Can you explain a bit more in-depth why you reset the board after completing a move and calling the recursion? (At the end of each of the for loops in f()-method).

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

      Do you mean when I 'restore' the board by cancelling the move, like what I said around 22:50 mark? It's like playing chess or any other board game, but you're allowed to take back a move. Imagine you move the king and you get check-mated, then your opponent say, "OK, let's try again, do something else". You'd move the king to its original position and try to go somewhere else instead. In this setting, basically what we're doing is: for loop - keep repeating until we've tried every single move do a move recurse - we go to the future and see what happens take back the move (reset the board) if we don't reset the board, then we're not really 'taking back' the move, right?

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

      ​@@DanielSutantyo Yes, it is from 22:50. Thanks, I think I understand a bit better now!

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

    Thank you!

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

    appreciate the work👏 and your voice is also kinda soothing

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

    Hi Daniel, great series for a beginner Java programmer like myself. Problems that aren't intimidating and clear easy to follow along explanations. I was wondering if it possible to zoom up the text a little (both code and problem) so it's more comfortable to see? Thanks so much!

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

      Thank you, Tina. This was the first video that I recorded and I made the mistake of recording it in 720p. Every other video I made were recorded in 1080p, and if the text is still not clear, the link to the question should always be in the video description.

  • @MarcoMartinez-fe6km
    @MarcoMartinez-fe6km 2 роки тому

    You are the greatest! Thank you!

  • @HelloWorld-eh7zk
    @HelloWorld-eh7zk 2 роки тому

    Nice video! I used a different approach. I believe this one also runs in O(2^n) but I am not sure how to compute. Can you help me analyze the time complexity of the code below? public boolean groupSum(int start, int[] nums, int target) { if (target == 0){ return true; } if (start == nums.length || target < 0){ return false; } for (int i = start; i < nums.length; i++){ if (groupSum(i+1, nums, target - nums[i])){ return true; } } return false; }

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

      Thanks for the comment, and sorry, obviously I don't check youtube that often =) I realise now that I made a mistake in this video. Your code is basically the first approach that I discussed, but obviously you are not permuting anything. I guess in my mind at the time, I wanted to make sure that students know the difference between combinations vs permutations. As for efficiency, I'm sure there's a way to prove this mathematically, but I can't think of it for now. My gut feeling says that your code is actually FASTER than the solution I have, because as an example (I hope this make sense), let's say your array is [1,2,3,4,5], if you want to evaluate the sum of single elements, your recursions would just try 1 on its own, 2 on its own, 3 or its own, etc, where as my solution would try [1,0,0,0,0] [0,2,0,0,0] [0,0,3,0,0] [0,0,0,4,0] [0,0,0,0,5] In fact, I think I will always do twice the number of recursions. I haven't had the time to make more videos for the last few months, but when I do, I definitely have to address this mistake.

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

      Sorry, just to be more clear, when I wrote 0, I meant "choose nothing". What I'm trying to say there is, in my code, to check something like [0,0,0,0,5] I have to make the function calls 5 times, but in your code, this is only done once because when you start with 5, you won't try anything else. Another way to put it, you never take the 'NO' branch, which means you're doing half the recursion (in the worst case).

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

    what if the given target is 0? in this case if there are no minus integers or 0 in the array then shouldnt it return false?

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

      In general, it is up to you how you want to handle the case when target == 0 (do you allow the trivial choice of not selecting any integers?). For this question, one of the test cases is an empty array with target == 0 which should return true. It also makes things simpler because the point is to show how recursive backtracking works. If you require at least one integer in the array to be selected, then you can pass another variable that keeps tracks of the number of integers chosen so far.

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

      @@DanielSutantyo i see thanks.

  • @MarcoMartinez-fe6km
    @MarcoMartinez-fe6km 2 роки тому

    Thank you Daniel! You are appreciated!

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

    This is my approach. #include<bits/stdc++.h> using namespace std; int main() { string str; cin >> str; int score = 0; int t, c, g; t = 0; c = 0; g = 0; for (int i = 0; i < str.size(); i++) { if (str[i] == 'C') { c += 1; } else if (str[i] == 'G') { g +=1; } else { t+=1; } } score += pow(t,2) + pow(g,2) + pow(c,2); while (t > 0 and c > 0 and g > 0) { t -= 1; c -= 1; g -= 1; score += 7; } cout << score << endl; }

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

    great video ! thank you for showing both the pure iterator approach and the auto keyword approach.

  • @user-pd1en1fd1r
    @user-pd1en1fd1r 2 роки тому

    Personally I prefer BufferedReader and PrintWriter for I/O

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

      It's actually faster than using Scanner, but I chose Scanner for the target audience so that we don't have to worry about tokenizing the string =). There are definitely questions where using a Scanner can result in a TLE.

    • @user-pd1en1fd1r
      @user-pd1en1fd1r 2 роки тому

      @@DanielSutantyo Yeah exactly, but I guess Scanner is the easiest way for beginners so it makes sense in a tutorial like this There are also more ways for faster output options like buffered writer, but usually I like print writer more. The only difference to system.out is that you have to use bw.flush() afterwards or set auto flush to true. People would not expect it, but sometimes i/o can be the bottleneck so it is worth to consider it. Btw thx for your Java videos, there are basically like 10 people on earth who use Java for cp, so thank you for being one of the other nine haha

    • @user-pd1en1fd1r
      @user-pd1en1fd1r 2 роки тому

      哦btw你是中国人吗-?

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

      @@user-pd1en1fd1r Nope, but I can read enough to understand that lol. We use Java because that's what our uni use for 1st and 2nd year students, and yeah, I think 99% of CP is C++ =).

    • @user-pd1en1fd1r
      @user-pd1en1fd1r 2 роки тому

      @@DanielSutantyo Yeah, C++ is more efficient and the std library is great, so it is probably the better option. Sometimes I also wonder why Rust is so uncommon in CP. We learn C/C++, Java, Assembly and Haskell in first year at my university + VHDL.

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

    it's that c++ or python?

    • @startinggintama
      @startinggintama 3 місяці тому

      Java..

    • @tanyamorro7454
      @tanyamorro7454 3 місяці тому

      ​@@startinggintamaAh yes, thank you, you saved me after 2 years. I really needed it 😮

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

    Comment for the algo 😍!! Do what the pros do = P-R-O-M-O-S-M !!!

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

    Absolute Legend!

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

    Best video on this problem on youtube. Thanks and keep up the good work !

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

    I was a bit tired when I made this video, so there are some mistakes (e.g. forgetting if (last != 1) in the brute force code). For the final code, I should've set dp[1] = 1 instead of having that if statement in the generate function!

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

    simple problems and explain c++ language

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

    make more videos please

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

    Your keyboard sounds really nice

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

    What a video lecture, what a lecture!! Just Faboulous, we want more.

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

    Damn, great explain

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

    Love it =))))))

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

    Awesome video :D Btw, how did you added the shiba inu? :o