Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SE103 - Week 9, Session 1

Caren
August 08, 2020

SE103 - Week 9, Session 1

Caren

August 08, 2020
Tweet

More Decks by Caren

Other Decks in Education

Transcript

  1. Week 9 and 10:
    Dynamic Programming!

    View Slide

  2. What is Dynamic Programming

    View Slide

  3. 1. Break down into overlapping subproblems
    2. Cache results to avoid solving same subproblems
    What is Dynamic Programming

    View Slide

  4. 1. Break down into overlapping subproblems
    2. Cache results to avoid solving same subproblems
    What is Dynamic Programming
    “Dynamic Programming was basically a phrase
    made up to confuse the government about what
    RAND was doing.”
    - Richard Bellman, ‘father’ of dynamic
    programming

    View Slide

  5. Poll!

    View Slide

  6. Why is Dynamic Programming
    so difficult?

    View Slide

  7. Sounds easy in theory, but way harder in practice!
    Why is Dynamic Programming
    so difficult?

    View Slide

  8. Sounds easy in theory, but way harder in practice!
    Like all other problems, the key is to recognize
    common patterns
    Why is Dynamic Programming
    so difficult?

    View Slide

  9. Sounds easy in theory, but way harder in practice!
    Like all other problems, the key is to recognize
    common patterns
    Continuous practice is critical - you’re probably not
    going to master dynamic programming in 2 weeks.
    Why is Dynamic Programming
    so difficult?

    View Slide

  10. - Fibonacci
    - Knapsack
    - Unbounded knapsack
    - Palindromic Sequences
    - Common Substrings
    Common Patterns in DP

    View Slide

  11. - Fibonacci
    - Knapsack
    - Unbounded knapsack
    - Palindromic Sequences
    - Common Substrings
    Common Patterns in DP

    View Slide

  12. Fibonacci
    0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55…

    To get the nth fib number

    … add the previous two numbers

    View Slide

  13. Fibonacci
    Recursive:

    public int CalculateFibonacci(int n) {
    if(n < 2)
    return n;
    return CalculateFibonacci(n-1) + CalculateFibonacci(n-2);
    }
    Run time: ??

    View Slide

  14. Fibonacci
    Recursive:

    public int CalculateFibonacci(int n) {
    if(n < 2)
    return n;
    return CalculateFibonacci(n-1) + CalculateFibonacci(n-2);
    }
    Run time: 2^n

    View Slide

  15. Fibonacci
    What if we built up the fibonacci sequence first?

    View Slide

  16. Fibonacci
    0 1
    What if we built up the fibonacci sequence first?

    View Slide

  17. Fibonacci
    0 1 1
    What if we built up the fibonacci sequence first?

    View Slide

  18. Fibonacci
    What if we built up the fibonacci sequence first?
    0 1 1 2 3 5 8

    View Slide

  19. Fibonacci
    What if we built up the fibonacci sequence first?
    0 1 1 2 3 5 8
    int dp[] = new int[n + 1];
    dp[0] = 0;
    dp[1] = 1;
    for (int i = 2; i <= n; i++)
    dp[i] = dp[i - 1] + dp[i - 2];
    return dp[n];

    View Slide

  20. Fibonacci
    What if we built up the fibonacci sequence first?
    0 1 1 2 3 5 8
    int dp[] = new int[n + 1];
    dp[0] = 0;
    dp[1] = 1;
    for (int i = 2; i <= n; i++)
    dp[i] = dp[i - 1] + dp[i - 2];
    return dp[n];
    Run time: ??

    View Slide

  21. Fibonacci
    What if we built up the fibonacci sequence first?
    0 1 1 2 3 5 8
    int dp[] = new int[n + 1];
    dp[0] = 0;
    dp[1] = 1;
    for (int i = 2; i <= n; i++)
    dp[i] = dp[i - 1] + dp[i - 2];
    return dp[n];
    Run time: n

    View Slide

  22. Given an array representation of coin values and a
    value n, return the number of ways to make change
    for the target amount n

    Given: {1, 5}, n = 6

    Return: ??

    Number of Ways to Make Change

    View Slide

  23. Given an array representation of coin values and a
    value n, return the number of ways to make change
    for the target amount n

    Given: {1, 5}, n = 6

    Return: 2

    { {6 x 1}, {5 x 1, 1 x 1} }

    Number of Ways to Make Change

    View Slide

  24. Let’s start by building an array from 0 -> n 

    Given: {1, 5}, n = 6

    Number of Ways to Make Change
    0 1 2 3 4 5 6

    View Slide

  25. Let’s start by building an array from 0 -> n

    Given: {1, 5}, n = 6

    In each box, we’ll see how many ways we can make ’n’
    with our coins 1, 5
    Number of Ways to Make Change
    0 1 2 3 4 5 6

    View Slide

  26. Let’s start by building an array from 0 -> n

    Given: {1, 5}, n = 6

    In each box, we’ll see how many ways we can make ’n’
    with our coins 1, 5
    Number of Ways to Make Change
    0 1 2 3 4 5 6
    1

    View Slide

  27. Let’s start by building an array from 0 -> n

    Given: {1, 5}, n = 6

    In each box, we’ll see how many ways we can make ’n’
    with our coins 1, 5
    Number of Ways to Make Change
    0 1 2 3 4 5 6
    1 1

    View Slide

  28. Let’s start by building an array from 0 -> n

    Given: {1, 5}, n = 6

    In each box, we’ll see how many ways we can make ’n’
    with our coins 1, 5
    Number of Ways to Make Change
    0 1 2 3 4 5 6
    1 1 1 1 1

    View Slide

  29. Let’s start by building an array from 0 -> n

    Given: {1, 5}, n = 6

    In each box, we’ll see how many ways we can make ’n’
    with our coins 1, 5
    Number of Ways to Make Change
    0 1 2 3 4 5 6
    1 1 1 1 1 2 2

    View Slide

  30. Let’s start by building an array from 0 -> n

    Given: {1, 5}, n = 6

    Let’s build up our array one ‘coin’ at a time (one pass
    with 1, second pass with 5)
    Number of Ways to Make Change
    0 1 2 3 4 5 6
    1 1 1 1 1 2 2

    View Slide

  31. Let’s start by building an array from 0 -> n

    Given: {1, 5}, n = 6

    if (coinValue <= amount) {

    ways[amount] =

    ways[amount] + ways[amount - coinValue];

    }
    Number of Ways to Make Change
    0 1 2 3 4 5 6
    1 1 1 1 1 2 2

    View Slide

  32. Number of Ways to Make Change
    General Pattern:

    - Create an array to store solutions to ‘subproblems’

    - what would be the solution up to ‘this’ point?

    View Slide

  33. Number of Ways to Make Change
    General Pattern:

    - Create an array to store solutions to ‘subproblems’

    - what would be the solution up to ‘this’ point?

    - Use stored solutions to populate future elements of
    the array

    View Slide

  34. Number of Ways to Make Change
    General Pattern:

    - Create an array to store solutions to ‘subproblems’

    - what would be the solution up to ‘this’ point?

    - Use stored solutions to populate future elements of
    the array

    - writing out the arrray and populating it by hand
    often helps you come up with the algorithm later

    View Slide

  35. Breakout Rooms
    - Half of group does one problem, other half does the
    other problem

    - 30 minutes, everybody tries to do their own problem

    - 10 minutes - group 1 explains their problem

    - 10 minutes - group 2 explains their problem

    - Last 10 minutes - everybody talks about the last
    problem and brainstorm what the dp array would look
    like

    View Slide

  36. How’d it go?

    View Slide

  37. Evaluating companies

    View Slide

  38. Evaluating companies
    Glassdoor reviews

    Researching current people who work at the company
    on LinkedIn

    View Slide

  39. Questions for me?

    View Slide

  40. Questions for me?
    Work Life Balance

    View Slide

  41. Questions for me?
    Work Life Balance
    - How does the team figure out what to work on in the
    next 3-6 months?

    - How does the team tackle tech debt?

    - What is a typical release process?

    - Weekly? Biweekly?

    - How does the team prepare for releases?

    - How is the release monitored afterwards?

    - Are there oncall schedules?

    View Slide

  42. Questions for me?
    Career Growth

    View Slide

  43. Questions for me?
    Career Growth
    - What do you see me working on in my first 3-6
    months on the job?

    - How do people on the team get feedback usually?

    View Slide

  44. Questions for me?
    General
    - What are some challenging projects you’ve worked
    on in the past 3-6 months?

    - What kind of meetings do you usually have in a
    week?

    View Slide

  45. Questions for me?
    Other questions?

    View Slide