Top Banner
Dynamic Programming M. Ashraf Iqbal http://www.istockphoto.com/stock-illustration- 12665058-armed-robbery.php Distributed by : www.myUET.net.tc www.myUET.net.tc
154

Dynamic Programming [Dr. Ashraf Iqbal] ()

Oct 14, 2014

Download

Documents

Kashif Ilyas

Lectures of Dr. Ashraf Iqbal on Dynamic Programming , Hosted by www.myUET.net.tc
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Dynamic Programming

M. Ashraf Iqbal

http://www.istockphoto.com/stock-illustration-12665058-armed-robbery.php

www.myUET.net.tc

Page 2: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Knapsack Problem

Page 3: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The 0/1 Knapsack Problem

• The 0-1 knapsack problem: Either put an item once in the knapsack or ignore it so as to maximize total profit while keeping the weight inside the knapsack within its capacity. Alternately we may like to ignore profits and try to maximize the weight in the knapsack such that it does not exceed its capacity. This is quite similar to the subset sum problem in mathematics.

Page 4: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Fractional knapsack problem: Either put an item or its fraction in the knapsack or ignore it so as to maximize total profit while keeping the weight inside the knapsack exactly equal to its capacity.

You can Cut an Item to Fit

http://www.google.com.pk/imgres?imgurl=http://images.clipartof.com/small/5669-Male-Carpenter-Cutting-Wood-On-A-Sawhorse-Clipart-Illustration.jpg&imgrefurl=http://www.clipartof.com/details/clipart/5669.html&h=368&w=450&sz=55&tbnid=QzoxPWsL_w7nAM:&tbnh=104&tbnw=127&prev=/images%3Fq%3Dimage%2Bof%2Bcutting%2Bwood&zoom=1&q=image+of+cutting+wood&hl=en&usg=__13lywSPGfp84b9pE_jq9zFTGznw=&sa=X&ei=1KuRTLvNGoGyvgO81ICJBA&ved=0CBgQ9QEwAA

Page 5: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Un-Bounded 0/1 Knapsack

The unbounded knapsack problem assumes that we have an unlimited supply of each weight. We intend to fill the knapsack as far as possible while keeping the total number of weights minimum (also known as the Change Problem). We can also maximize profit provided profit for each weight is also given.

Page 6: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Un-bounded 0/1 Knapsack

http://www.fotosearch.com/BLD007/jp2005_0002521/

Page 7: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Another Knapsack Problem

The bounded 0/1 knapsack problem restricts the number of each item to a fixed maximum value.

Page 8: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Objectives1. We may like to maximize the number of weights to be placed in the knapsack

such that the total weight remains within the knapsack capacity in a 0/1 scenario.

2. We may like to maximize the profit provided the profit of each weight is the same.

3. We may like to maximize profit provided the weight of each item is the same.

Page 9: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

How Many Knapsack Problems?

• What Strategies should be used?• Greedy?• Dynamic Programming?• Brute Force – look at all options?• What is Greedy• What is Dynamic Programming• What is the relationship between Greedy, Dynamic

Programming, & Brute force Strategies?

How Many Knapsack?

Page 10: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Which Strategy should be used?• Brute Force is expensive but?• Dynamic Programming is intelligent but?• Greedy is FAST but?

Page 11: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Which Strategy should be used?• Brute Force can solve every thing?• Dynamic Programming can solve some thing?• How about Greedy?

Page 12: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Start with the Change Problem?

Page 13: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Start with the Change Problem?

Page 14: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 15: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Recursion Tree

Page 16: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Change Problem?Recursive Formulation? Recursion Tree?

Page 17: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Change Problem transforms into a Graph Problem?

Find a Change = Find a Path?

Page 18: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 19: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Find a Change = Find a Shortest Path?

Page 20: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Where is Brute Force, DP, & Greedy?

Page 21: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Do it by Brute Force?

Page 22: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Do it by Dynamic Programming?

Page 23: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Do it by Greedy?

Page 24: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Change Problem?

• Brute Force provides an Optimal answer?

• Dynamic Programming provides an Optimal answer?

• Greedy strategy provides an Optimal answer?

Page 25: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Profits & Weights in a Knapsack?

How to start now?

Page 26: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Profits & Weights in a Knapsack?

Page 27: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 28: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Where is Brute Force, DP, & Greedy?

Page 29: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Do it by Brute Force?

Page 30: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Greedy: The Graph collapses?

Page 31: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Dynamic Programming: It Collapses?

Page 32: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Do it by Dynamic Programming?

Page 33: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Change ProblemDo it by Dynamic

Programming?

Page 34: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Change ProblemDo it by Dynamic

Programming?

Page 35: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Change ProblemDo it by Dynamic

Programming?

Page 36: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Maximizing ProfitDo it by Dynamic

Programming?

Weights = 4 3 2 Profit = 10 8 9

Page 37: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Maximizing ProfitDo it by Dynamic

Programming?

Weights = 4 3 2 Profit = 10 8 9

Page 38: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Time complexity calculations?

Page 39: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Knapsack Problem?

Page 40: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 41: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 42: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 43: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 44: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Knapsack Problem?

• The above diagram shows a recursive implementation of which recursive equation? Discuss briefly. We have not yet gone into dynamic programming.

• How can you find (from the above diagram) the combination of weights that exactly fits the knap sack of given capacity equal to 11. Discuss briefly.

• The answer to the above part requires a cute reduction of this problem into a graph problem? What is that graph problem? Please discuss.

• What will be the time complexity of this recursive implementation?

Page 45: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

A New Recursive Formulation?

P(5,11) = P(4,5) + 6 = P(4,6) + 5 = P(4,7) + 4 = P(4,8) + 3 = P(4,9) + 2

max

Page 46: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

A “Last Year” Mistake??

Page 47: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Last Year Class: Hisaan to the rescue

Page 48: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Alternate Recursive Formulation?

Page 49: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Old Recursive Formulation?

Page 50: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Knapsack Problem

Page 51: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 52: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 53: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 54: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Another Knapsack Problem

• Problem: We have k lists of integers and a knapsack of capacity T. We need to select one item from each list such as to maximize the total weight in the knapsack without overflowing it. Here is recursive solution unfolding itself with some common sense.

Page 55: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 56: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

• Problem: We have k lists of integers and a knapsack of capacity T. We need to select one item from each list such as to maximize the total profit in the knapsack such that the weight in the knapsack remains within its capacity. Here is recursive solution unfolding itself with some common sense.

Page 57: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 58: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Problem: We have k lists of integers and a knapsack of capacity T. We need to select one item from each list such as to maximize the total weight in the knapsack without overflowing it. Here is an efficient dynamic programming solution.

Page 59: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 60: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Knapsack Problem• We intend to maximize profit keeping the total weight

within the knapsack capacity. Find a recursive equation corresponding to this scenario. How will you implement this recursive equation on the diagram above?

• How can you find (from the above recursive diagram) the combination of weights that maximizes total profit keeping the total weight within knapsack capacity? Discuss briefly.

• How can you reduce this graph and thus reduce the time complexity of this recursive implementation (without going into dynamic programming).

Page 61: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Problem of Maximizing Profit?

Page 62: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Problem of Maximizing Number of Elements in a single Knapsack

Page 63: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 64: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Activity Selection Problem?

Page 65: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Activity Selection Problem?

Page 66: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 67: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Activity Selection Problem

• Maximize Total Merit with Start time and Finish time fixed for each activity?

• Maximize Total Merit when only Duration is fixed for each activity?

• Maximize the Total Utilization of the Hall?• Maximize the Total Number of activities?

Page 68: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 69: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Activity Selection Problem?

Page 70: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Maximize Merit

Page 71: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 72: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 73: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 74: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 75: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 76: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Com

plex

ity o

f Gra

ph C

onst

ructi

on

Page 77: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 78: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 79: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 80: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 81: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Partitioning Problem• Problem: Given a fixed sequence of n numbers, we wish

to divide the sequence into at most p partitions as fairly as possible (you know the problem already). Assume that we are given the following sequence (5, 1, 2, 3, 4) and assume that p =2.

• Write down a general recursive formulation of the linear partition problem. Find the optimal answer by inspection for the specific problem given above.

• Draw the recursion tree similar to the one drawn in Fig. 7(attached herewith). Remember that in the present problem p=2. Highlight the edges in your recursion tree, which corresponds to the optimal solution.

Page 82: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Partitioning Problem

(5, 1, 2, 3, 4, 3)

Page 83: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 84: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

(5, 1, 2, 3, 4, 3)

Partition the sequence into 4 partitions

Page 85: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Partition the sequence into 4 partitions (5, 1, 2, 3, 4, 3)

Page 86: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Partition the sequence into 4 partitions (5, 1, 2, 3, 4, 3)

Time Complexity?Number of VerticesNumber of Edges

Page 87: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Partition the sequence into 4 partitions (5, 1, 2, 3, 4, 3)

Page 88: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Once again the Partitioning Problem?

Page 89: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Same Problem but?

Page 90: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Partition the sequence into 4 partitions (5, 1, 2, 3, 4, 3)

Page 91: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tcAdd one more level – but why?

Page 92: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tcAdd one more level – but why?

Page 93: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Rod Partitioning Problem

The size - price tableCutting costs?

Page 94: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Rod Partitioning Problems

1. No cutting cost?2. Uniform cutting

cost?3. Non uniform

cutting cost

Page 95: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Rod Partitioning Problem

The size - price tableCutting Cost = 0

Page 96: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Rod Partitioning

Problem

The size - price tableUniform Cutting Cost = x

Page 97: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Rod Partitioning

Problem

The size - price tableNon Uniform Cutting Cost

Page 98: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Rod Partitioning Problem

Cutting Cost = 0Maximum Price = 13

Page 99: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Rod Partitioning Problem

The size - price tableCutting Cost = 0

Page 100: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Rod Partitioning

Problem

Page 101: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Length & Price is given – put weights?

Page 102: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 103: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 104: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 105: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tcHow many vertices, edges?

Page 106: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tcDynamic Programming?

Page 107: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Dynamic Programming

Page 108: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Dynamic Programming

Page 109: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Dynamic Programming

Total vertices and edges?

Page 110: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Dynamic Programming

Page 111: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Directed Acyclic Graph

Page 112: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

How about a fixed cutting cost?

Page 113: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Maximizing profits after subtracting total cutting costs

Page 114: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Maximizing profits after subtracting total cutting costs

Page 115: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Maximizing profits after subtracting total cutting costs

Page 116: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Maximizing profits after subtracting total cutting costs

Page 117: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Profits after cutting costs

Page 118: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

• Total Vertices?• Total Edges?• Time

Complexity?

Page 119: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

An alternate way of solving it?

Page 120: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

An alternate way of solving it?

Page 121: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 122: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

How the DAG will change? In shape? In edge weights?

Page 123: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 124: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 125: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Once again the partitioning problem

• Given a fixed sequence of n positive numbers how can we partition it in k partitions such that the weight of the heaviest partition is minimum.

Page 126: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 127: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

ghh

Page 128: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Once again the partitioning problem?

• Given a fixed sequence of n positive numbers how can we partition it in k partitions such that the weight of the heaviest partition is minimum.

• How about if k=n?

Page 129: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Once again the partitioning problem?

• Given a fixed sequence of n positive numbers how can we partition it in k partitions such that the weight of the heaviest partition is minimum.

• How about if some numbers are negative?

Page 130: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Once again the partitioning problem?

• How about if some numbers are negative? • What should be the value of k so as to

minimize the weight of the heaviest partition?• The value of k could be just 1?

Page 131: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 132: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 133: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 134: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

ghh

Why can not be the DAG like this or that?

Page 135: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

How the DAG would look like if some edge weights are negative but k is fixed from above?

Page 136: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 137: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Matrix Multiplication Problem?

Page 138: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 139: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 140: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 141: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 142: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 143: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 144: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 145: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 146: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 147: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 148: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 149: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Longest or shortest path problem

Page 150: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

The Longest path problem

Page 151: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Longest Increasing sequence

• What is this problem?

Page 152: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Longest Increasing Sub-Sequence

• What is this problem?

Page 153: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc

Page 154: Dynamic Programming [Dr. Ashraf Iqbal] ()

Distributed by : www.myUET.net.tc