SlideShare a Scribd company logo
4 -1
Lecture# 9
The Greedy Method
4 -2
The greedy method
 Suppose that a problem can be solved by
a sequence of decisions. The greedy
method has that each decision is locally
optimal. These locally optimal solutions
will finally add up to a globally optimal
solution.
 Only a few optimization problems can be
solved by the greedy method.
4 -3
An simple example
 Problem: Pick k numbers out of n
numbers such that the sum of these k
numbers is the largest.
 Algorithm:
FOR i = 1 to k
pick out the largest number and
delete this number from the input.
ENDFOR
4 -4
Shortest paths on a special graph
 Problem: Find a shortest path from v0
to v3
.
 The greedy method can solve this problem.
 The shortest path: 1 + 2 + 4 = 7.
4 -5
Shortest paths on a multi-stage graph
 Problem: Find a shortest path from v0
to v3
in
the multi-stage graph.
 Greedy method: v0
v1,2
v2,1
v3
= 23
 Optimal: v0
v1,1
v2,2
v3
= 7
 The greedy method does not work.
4 -6
Solution of the above problem
 dmin(i,j): minimum distance between i and
j.
 This problem can be solved by the
dynamic programming method.
dmin(v0,v3)=min





3+dmin(v1,1,v3)
1+dmin(v1,2,v3)
5+dmin(v1,3,v3)
7+dmin(v1,4,v3)
4 -7
Minimum spanning trees
(MST)
 It may be defined on Euclidean space
points or on a graph.
 G = (V, E): weighted connected
undirected graph
 Spanning tree : S = (V, T), T ⊆ E,
undirected tree
 Minimum spanning tree(MST) : a
spanning tree with the smallest total
weight.
4 -8
An example of MST
 A graph and one of its minimum costs
spanning tree
4 -9
Kruskal’s algorithm for
finding MST
Step 1: Sort all edges into increasing order.
Step 2: Add the next smallest weight edge to the
forest if it will not cause a cycle.
Step 3: Stop if n-1 edges. Otherwise, go to
Step2.
4 -10
An example of Kruskal’s algorithm
Sort with respect to cost
Step-1
4 -11
An example of Kruskal’s algorithm
Sort with respect to cost
4 -12
The details for constructing MST
 How do we check if a cycle is formed when a
new edge is added?
 By the SET and UNION method.
 A tree in the forest is used to represent a
SET.
 If (u, v) ∈ E and u, v are in the same set, then
the addition of (u, v) will form a cycle.
 If (u, v) ∈ E and u∈S1
, v∈S2
, then perform
UNION of S1
and S2
.
4 -13
Time complexity
 Time complexity: O(|E| log|E|)
4 -14
Prim’s algorithm for finding
MST
Step 1: x ∈ V, Let A = {x}, B = V - {x}.
Step 2: Select (u, v) ∈ E, u ∈ A, v ∈ B
such that (u, v) has the smallest weight
between A and B.
Step 3: Put (u, v) in the tree. A = A ∪ {v},
B = B - {v}
Step 4: If B = ∅, stop; otherwise, go to
Step 2.
 Time complexity : O(n2
), n = |V|.
(see the example on the next page)
4 -15
An example for Prim’s algorithm
4 -16
The single-source shortest
path problem
 shortest paths from v0
to all destinations
4 -17
Dijkstra’s algorithm
1 2 3 4 5 6 7 8
1 0
2 300 0
3 1000 800 0
4 1200 0
5 1500 0 250
6 1000 0 900 1400
7 0 1000
8 1700 0
Cost adjacency matrix.
All entries not shown
are +∞.
4 -18
 Time complexity : O(n2
)
Vertex
Iteration S Selected (1) (2) (3) (4) (5) (6) (7) (8)
Initial ----
1 5 6 +∞ +∞ +∞ 1500 0 250 +∞ +∞
2 5,6 7 +∞ +∞ +∞ 1250 0 250 1150 1650
3 5,6,7 4 +∞ +∞ +∞ 1250 0 250 1150 1650
4 5,6,7,4 8 +∞ +∞ 2450 1250 0 250 1150 1650
5 5,6,7,4,8 3 3350 +∞ 2450 1250 0 250 1150 1650
6 5,6,7,4,8,3 2 3350 3250 2450 1250 0 250 1150 1650
5,6,7,4,8,3,2 3350 3250 2450 1250 0 250 1150 1650
4 -19
 Can we use Dijkstra’s algorithm to find the
longest path from a starting vertex to an
ending vertex in an acyclic directed graph?
 There are 3 possible ways to apply Dijkstra’s
algorithm:
 Directly use “max” operations instead of “min”
operations.
 Convert all positive weights to be negative. Then
find the shortest path.
 Give a very large positive number M. If the weight
of an edge is w, now M-w is used to replace w.
Then find the shortest path.
 All these 3 possible ways would not work!
The longest path problem
4 -20
Activity On Edge (AOE) Networks
 Tasks (activities) : a0, a1,…
 Events : v0,v1,…
V0
V1
V2
V3
V4
V6
V7
V8
V5
finish
a0 = 6
start
a1 = 4
a2 = 5
a4 = 1
a3 = 1
a5 = 2
a6 = 9
a7 = 7
a8 = 4
a10 = 4
a9 = 2
Some definition:
 Predecessor
 Successor
 Immediate predecessor
 Immediate successor
4 -21
critical path
 A critical path is a path that has the
longest length. (v0, v1, v4, v7, v8)
V0
V1
V2
V3
V4
V6
V7
V8
V5
a0 = 6
a1 = 4
a2 = 5
a4 = 1
a3 = 1
a5 = 2
a6 = 9
a7 = 7
a8 = 4
a10 = 4
a9 = 2
start finish
6 + 1 + 7 + 4 = 18 (Max)
4 -22
The earliest time
 The earliest time of an activity, ai, can occur is the length
of the longest path from the start vertex v0 to ai’s start
vertex.
( Ex: the earliest time of activity a7 can occur is 7. )
 We denote this time as early(i) for activity ai.
∴ early(6) = early(7) = 7.
V0
V1
V2
V3
V4
V6
V7
V8
V5
finish
a0 = 6
start
a1 = 4
a2 = 5
a4 = 1
a3 = 1
a5 = 2
a6 = 9
a7 = 7
a8 = 4
a10 = 4
a9 = 2
6/?
0/?
7/? 16/?
0/?
5/?
7/?
14/?7/?4/?
0/?
18
4 -23
The latest time
 The latest time, late(i), of activity, ai, is defined to be the
latest time the activity may start without increasing the
project duration.
 Ex: early(5) = 5 & late(5) = 8; early(7) = 7 & late(7) = 7
V0
V1
V2
V3
V4
V6
V7
V8
V5
finish
a0 = 6
start
a1 = 4
a2 = 5
a4 = 1
a3 = 1
a5 = 2
a6 = 9
a7 = 7
a8 = 4
a10 = 4
a9 = 2
late(5) = 18 – 4 – 4 - 2 = 8
late(7) = 18 – 4 – 7 = 7
6/6
0/1
7/7 16/16
0/3
5/8
7/10
14/147/74/5
0/0
4 -24
Critical activity
 A critical activity is an activity for which
early(i) = late(i).
 The difference between late(i) and early(i) is
a measure of how critical an activity is.
Calculation
of
Latest Times
Calculation
of
Earliest Times
Finding
Critical path(s)
To solve
AOE Problem
4 -25
Calculation of Earliest Times
 Let activity ai is represented by edge (u, v).
 early (i) = earliest [u]
 late (i) = latest [v] – duration of activity ai
 We compute the times in two stages:
a forward stage and a backward stage.
 The forward stage:
 Step 1: earliest [0] = 0
 Step 2: earliest [j] = max {earliest [i] + duration of (i, j)}
i is in P(j)
P(j) is the set of immediate predecessors of j.
4 -26
 The backward stage:
 Step 1: latest[n-1] = earliest[n-1]
 Step 2: latest [j] = min {latest [i] - duration of (j, i)}
i is in S(j)
S(j) is the set of vertices adjacent from vertex j.
latest[8] = earliest[8] = 18
latest[6] = min{earliest[8] - 2} = 16
latest[7] = min{earliest[8] - 4} = 14
latest[4] = min{earliest[6] – 9; earliest[7] – 7} = 7
latest[1] = min{earliest[4] - 1} = 6
latest[2] = min{earliest[4] - 1} = 6
latest[5] = min{earliest[7] - 4} = 10
latest[3] = min{earliest[5] - 2} = 8
latest[0] = min{earliest[1] – 6; earliest[2] – 4; earliest[3] – 5} = 0
Calculation of Latest Times
4 -27
Graph with non-critical activities deleted
V0
V1
V2
V3
V4
V6
V7
V8
V5
finish
a0
start
a1
a2
a4
a3
a5
a6
a7
a8
a10
a9
V0
V1
V4
V6
V7
V8 finish
a0
start
a3 a6
a7 a10
a9
Activity Early Late L - E Critical
a0 0 0 0 Yes
a1 0 2 2 No
a2 0 3 3 No
a3 6 6 0 Yes
a4 4 6 2 No
a5 5 8 3 No
a6 7 7 0 Yes
a7 7 7 0 Yes
a8 7 10 3 No
a9 16 16 0 Yes
a10 14 14 0 Yes
4 -28
 The longest path(critical path) problem
can be solved by the critical path
method(CPM) :
Step 1:Find a topological ordering.
Step 2: Find the critical path.
(see [Horiwitz 1998].)
CPM for the longest path
problem
4 -29
The 2-way merging problem
 # of comparisons required for the linear 2-
way merge algorithm is m1
+ m2
-1 where m1
and m2
are the lengths of the two sorted lists
respectively.
 The problem: There are n sorted lists, each of
length mi
. What is the optimal sequence of
merging process to merge these n lists into
one sorted list ?
4 -30
 Extended Binary Tree Representing a 2-way
Merge
Extended binary trees
4 -31
An example of 2-way merging
 Example: 6 sorted lists with lengths 2,
3, 5, 7, 11 and 13.
4 -32
 Time complexity for
generating an optimal
extended binary
tree:O(n log n)
4 -33
Huffman codes
 In telecommunication, how do we represent a
set of messages, each with an access
frequency, by a sequence of 0’s and 1’s?
 To minimize the transmission and decoding
costs, we may use short strings to represent
more frequently used messages.
 This problem can by solved by using an
extended binary tree which is used in the 2-
way merging problem.
4 -34
An example of Huffman algorithm
 Symbols: A, B, C, D, E, F, G
freq. : 2, 3, 5, 8, 13, 15, 18
 Huffman codes:
A: 10100 B: 10101 C: 1011
D: 100 E: 00 F: 01
G: 11
A Huffman code Tree
4 -35
Chapter 4 Greedy method
Input(A[1…n])
Solution ←ψ
for i ← 1 to n do
X ← SELECT(A) ( 最好有一 data structure ,經 preprocessing 後可以很快的找
到 ( 包括 delete))
If FEASIBLE( solution, x)
then solution ← UNION( select, x)
endif
repeat
Output (solution)
特點
(1) 做一串 decision
(2) 每個 decision 只關心自己是不是 optimal 一部份與其它無關 ( 可以 local
check)
Note
(1) Local optimal 須是 global optimal
(2) 有時裡面隱含一個 sorting
4 -36
Knapsack problem
 Given positive integers P1, P2, …, Pn,
W1, W2, …, Wn and M.
 Find X1, X2, … ,Xn, 0≦Xi≦1 such that
is maximized.
 Subject to
∑=
n
1i
iiXP
∑=
≤
n
1i
ii MXW
4 -37
Knapsack Problem Example
 M = 20, (P1, P2, P3)=(25,24,15)
(W1, W2, W3) = (18, 15, 10)
 Four feasible solutions, 4 is optimal
(X1, X2, X3) ΣWiXi ΣPiX
1. (1/2,1/3,1/4) 16.5 24.25
2. (1,2/15,0) 20 28.2
3. (0, 2/3, 1) 20 31
4. (0, 1, 1/2) 20 31.5
4 -38
Job Sequencing with Deadlines
 Given n jobs. Associated with job I is an
integer deadline Di≧0. For any job I the profit
Pi is earned iff the job is completed by its
deadline. To complete a job, one has to
process the job on a machine for one unit of
time.
 A feasible solution is a subset J of jobs such
that each job in the subset can be completed
by its deadline. We want to maximize the
∑∈Ji iP
4 -39
 n = 4, (p1, p2, p3, p4) = (100,10,15,27)
(d1, d2, d3, d4) = (2, 1, 2, 1)
Feasible solution Processing
sequence
value
1 (1,2) 2,1 110
2 (1,3) 1,3 or 3, 1 115
3 (1,4) 4, 1 127
4 (2,3) 2, 3 25
5 (3,4) 4,3 42
6 (1) 1 100
7 (2) 2 10
8 (3) 3 15
9 (4) 4 27
4 -40
Optimal Storage on Tapes
 There are n programs that are to be stored
on a computer tape of length L. Associated
with each program i is a length Li.
 Assume the tape is initially positioned at
the front. If the programs are stored in the
order I = i1, i2, …, in, the time tj needed to
retrieve program ij
tj =
∑=
j
1k
ik
L
4 -41
Optimal Storage on Tapes
 If all programs are retrieved equally often,
then the
mean retrieval time (MRT) =
 This problem fits the ordering paradigm.
Minimizing the MRT is equivalent to
minimizing
d(I) =
∑=
n
1j
jt
n
1
∑∑= =
n
1j
j
1k
ik
L
4 -42
Example
 Let n = 3, (L1,L2,L3) = (5,10,3). 6 possible
orderings. The optimal is 3,1,2
Ordering I d(I)
1,2,3 5+5+10+5+10+3 = 38
1,3,2 5+5+3+5+3+10 = 31
2,1,3 10+10+5+10+5+3 = 43
2,3,1 10+10+3+10+3+5 = 41
3,1,2 3+3+5+3+5+10 = 29
3,2,1, 3+3+10+3+10+5 = 34

More Related Content

What's hot

Unit 3 daa
Unit 3 daaUnit 3 daa
Unit 3 daa
Nv Thejaswini
 
My presentation all shortestpath
My presentation all shortestpathMy presentation all shortestpath
My presentation all shortestpath
Carlostheran
 
ODD HARMONIOUS LABELINGS OF CYCLIC SNAKES
ODD HARMONIOUS LABELINGS OF CYCLIC SNAKESODD HARMONIOUS LABELINGS OF CYCLIC SNAKES
ODD HARMONIOUS LABELINGS OF CYCLIC SNAKES
graphhoc
 
013_20160328_Topological_Measurement_Of_Protein_Compressibility
013_20160328_Topological_Measurement_Of_Protein_Compressibility013_20160328_Topological_Measurement_Of_Protein_Compressibility
013_20160328_Topological_Measurement_Of_Protein_Compressibility
Ha Phuong
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
Dr. C.V. Suresh Babu
 
Daa unit 4
Daa unit 4Daa unit 4
Daa unit 4
Abhimanyu Mishra
 
Algorithms explained
Algorithms explainedAlgorithms explained
Algorithms explained
PIYUSH Dubey
 
Minimal spanning tree class 15
Minimal spanning tree class 15Minimal spanning tree class 15
Minimal spanning tree class 15
Kumar
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
Dr Shashikant Athawale
 
Algorithm chapter 9
Algorithm chapter 9Algorithm chapter 9
Algorithm chapter 9
chidabdu
 
Skiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programmingSkiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programming
zukun
 
LeetCode Solutions In Java .pdf
LeetCode Solutions In Java .pdfLeetCode Solutions In Java .pdf
LeetCode Solutions In Java .pdf
zupsezekno
 
Estimating structured vector autoregressive models
Estimating structured vector autoregressive modelsEstimating structured vector autoregressive models
Estimating structured vector autoregressive models
Akira Tanimoto
 
Mit15 082 jf10_lec01
Mit15 082 jf10_lec01Mit15 082 jf10_lec01
Mit15 082 jf10_lec01
Saad Liaqat
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Shakil Ahmed
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
Krish_ver2
 
Np cooks theorem
Np cooks theoremNp cooks theorem
Np cooks theorem
Narayana Galla
 
Data Algorithms And Analysis
Data Algorithms And AnalysisData Algorithms And Analysis
Data Algorithms And Analysis
garishma bhatia
 
Digital signal processing
Digital signal processingDigital signal processing
Digital signal processing
ReachLocal Services India
 
DSP System Homework Help
DSP System Homework HelpDSP System Homework Help
DSP System Homework Help
Matlab Assignment Experts
 

What's hot (20)

Unit 3 daa
Unit 3 daaUnit 3 daa
Unit 3 daa
 
My presentation all shortestpath
My presentation all shortestpathMy presentation all shortestpath
My presentation all shortestpath
 
ODD HARMONIOUS LABELINGS OF CYCLIC SNAKES
ODD HARMONIOUS LABELINGS OF CYCLIC SNAKESODD HARMONIOUS LABELINGS OF CYCLIC SNAKES
ODD HARMONIOUS LABELINGS OF CYCLIC SNAKES
 
013_20160328_Topological_Measurement_Of_Protein_Compressibility
013_20160328_Topological_Measurement_Of_Protein_Compressibility013_20160328_Topological_Measurement_Of_Protein_Compressibility
013_20160328_Topological_Measurement_Of_Protein_Compressibility
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
Daa unit 4
Daa unit 4Daa unit 4
Daa unit 4
 
Algorithms explained
Algorithms explainedAlgorithms explained
Algorithms explained
 
Minimal spanning tree class 15
Minimal spanning tree class 15Minimal spanning tree class 15
Minimal spanning tree class 15
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Algorithm chapter 9
Algorithm chapter 9Algorithm chapter 9
Algorithm chapter 9
 
Skiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programmingSkiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programming
 
LeetCode Solutions In Java .pdf
LeetCode Solutions In Java .pdfLeetCode Solutions In Java .pdf
LeetCode Solutions In Java .pdf
 
Estimating structured vector autoregressive models
Estimating structured vector autoregressive modelsEstimating structured vector autoregressive models
Estimating structured vector autoregressive models
 
Mit15 082 jf10_lec01
Mit15 082 jf10_lec01Mit15 082 jf10_lec01
Mit15 082 jf10_lec01
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
 
Np cooks theorem
Np cooks theoremNp cooks theorem
Np cooks theorem
 
Data Algorithms And Analysis
Data Algorithms And AnalysisData Algorithms And Analysis
Data Algorithms And Analysis
 
Digital signal processing
Digital signal processingDigital signal processing
Digital signal processing
 
DSP System Homework Help
DSP System Homework HelpDSP System Homework Help
DSP System Homework Help
 

Similar to Lecture#9

algorithm Unit 3
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
Monika Choudhery
 
Project Management Techniques
Project Management TechniquesProject Management Techniques
Project Management Techniques
project management
 
Branch and bounding : Data structures
Branch and bounding : Data structuresBranch and bounding : Data structures
Branch and bounding : Data structures
Kàŕtheek Jåvvàjí
 
A New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmA New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring Algorithm
Jim Jimenez
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
pert_n_cpm.ppt
pert_n_cpm.pptpert_n_cpm.ppt
pert_n_cpm.ppt
chandrasekarnatraj
 
pert_n_cpm.ppt
pert_n_cpm.pptpert_n_cpm.ppt
pert_n_cpm.ppt
chandrasekarnatraj
 
04 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x204 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x2
MuradAmn
 
Ip 5 discrete mathematics
Ip 5 discrete mathematicsIp 5 discrete mathematics
Ip 5 discrete mathematics
Mark Simon
 
Hierarchical matrix techniques for maximum likelihood covariance estimation
Hierarchical matrix techniques for maximum likelihood covariance estimationHierarchical matrix techniques for maximum likelihood covariance estimation
Hierarchical matrix techniques for maximum likelihood covariance estimation
Alexander Litvinenko
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
Krish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
Krish_ver2
 
Ch07 linearspacealignment
Ch07 linearspacealignmentCh07 linearspacealignment
Ch07 linearspacealignment
BioinformaticsInstitute
 
Unit 3-Greedy Method
Unit 3-Greedy MethodUnit 3-Greedy Method
Unit 3-Greedy Method
DevaKumari Vijay
 
module4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfmodule4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdf
Shiwani Gupta
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)
Mumtaz Ali
 
8282967.ppt
8282967.ppt8282967.ppt
8282967.ppt
ArunachalamSelva
 
Discrete Math IP4 - Automata Theory
Discrete Math IP4 - Automata TheoryDiscrete Math IP4 - Automata Theory
Discrete Math IP4 - Automata Theory
Mark Simon
 
Low-rank tensor methods for stochastic forward and inverse problems
Low-rank tensor methods for stochastic forward and inverse problemsLow-rank tensor methods for stochastic forward and inverse problems
Low-rank tensor methods for stochastic forward and inverse problems
Alexander Litvinenko
 
Ou3425912596
Ou3425912596Ou3425912596
Ou3425912596
IJERA Editor
 

Similar to Lecture#9 (20)

algorithm Unit 3
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
 
Project Management Techniques
Project Management TechniquesProject Management Techniques
Project Management Techniques
 
Branch and bounding : Data structures
Branch and bounding : Data structuresBranch and bounding : Data structures
Branch and bounding : Data structures
 
A New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmA New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring Algorithm
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
pert_n_cpm.ppt
pert_n_cpm.pptpert_n_cpm.ppt
pert_n_cpm.ppt
 
pert_n_cpm.ppt
pert_n_cpm.pptpert_n_cpm.ppt
pert_n_cpm.ppt
 
04 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x204 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x2
 
Ip 5 discrete mathematics
Ip 5 discrete mathematicsIp 5 discrete mathematics
Ip 5 discrete mathematics
 
Hierarchical matrix techniques for maximum likelihood covariance estimation
Hierarchical matrix techniques for maximum likelihood covariance estimationHierarchical matrix techniques for maximum likelihood covariance estimation
Hierarchical matrix techniques for maximum likelihood covariance estimation
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
Ch07 linearspacealignment
Ch07 linearspacealignmentCh07 linearspacealignment
Ch07 linearspacealignment
 
Unit 3-Greedy Method
Unit 3-Greedy MethodUnit 3-Greedy Method
Unit 3-Greedy Method
 
module4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfmodule4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdf
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)
 
8282967.ppt
8282967.ppt8282967.ppt
8282967.ppt
 
Discrete Math IP4 - Automata Theory
Discrete Math IP4 - Automata TheoryDiscrete Math IP4 - Automata Theory
Discrete Math IP4 - Automata Theory
 
Low-rank tensor methods for stochastic forward and inverse problems
Low-rank tensor methods for stochastic forward and inverse problemsLow-rank tensor methods for stochastic forward and inverse problems
Low-rank tensor methods for stochastic forward and inverse problems
 
Ou3425912596
Ou3425912596Ou3425912596
Ou3425912596
 

Recently uploaded

Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
JomonJoseph58
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
melliereed
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
zuzanka
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDFLifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Vivekanand Anglo Vedic Academy
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
RamseyBerglund
 

Recently uploaded (20)

Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDFLifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
 

Lecture#9

  • 1. 4 -1 Lecture# 9 The Greedy Method
  • 2. 4 -2 The greedy method  Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each decision is locally optimal. These locally optimal solutions will finally add up to a globally optimal solution.  Only a few optimization problems can be solved by the greedy method.
  • 3. 4 -3 An simple example  Problem: Pick k numbers out of n numbers such that the sum of these k numbers is the largest.  Algorithm: FOR i = 1 to k pick out the largest number and delete this number from the input. ENDFOR
  • 4. 4 -4 Shortest paths on a special graph  Problem: Find a shortest path from v0 to v3 .  The greedy method can solve this problem.  The shortest path: 1 + 2 + 4 = 7.
  • 5. 4 -5 Shortest paths on a multi-stage graph  Problem: Find a shortest path from v0 to v3 in the multi-stage graph.  Greedy method: v0 v1,2 v2,1 v3 = 23  Optimal: v0 v1,1 v2,2 v3 = 7  The greedy method does not work.
  • 6. 4 -6 Solution of the above problem  dmin(i,j): minimum distance between i and j.  This problem can be solved by the dynamic programming method. dmin(v0,v3)=min      3+dmin(v1,1,v3) 1+dmin(v1,2,v3) 5+dmin(v1,3,v3) 7+dmin(v1,4,v3)
  • 7. 4 -7 Minimum spanning trees (MST)  It may be defined on Euclidean space points or on a graph.  G = (V, E): weighted connected undirected graph  Spanning tree : S = (V, T), T ⊆ E, undirected tree  Minimum spanning tree(MST) : a spanning tree with the smallest total weight.
  • 8. 4 -8 An example of MST  A graph and one of its minimum costs spanning tree
  • 9. 4 -9 Kruskal’s algorithm for finding MST Step 1: Sort all edges into increasing order. Step 2: Add the next smallest weight edge to the forest if it will not cause a cycle. Step 3: Stop if n-1 edges. Otherwise, go to Step2.
  • 10. 4 -10 An example of Kruskal’s algorithm Sort with respect to cost Step-1
  • 11. 4 -11 An example of Kruskal’s algorithm Sort with respect to cost
  • 12. 4 -12 The details for constructing MST  How do we check if a cycle is formed when a new edge is added?  By the SET and UNION method.  A tree in the forest is used to represent a SET.  If (u, v) ∈ E and u, v are in the same set, then the addition of (u, v) will form a cycle.  If (u, v) ∈ E and u∈S1 , v∈S2 , then perform UNION of S1 and S2 .
  • 13. 4 -13 Time complexity  Time complexity: O(|E| log|E|)
  • 14. 4 -14 Prim’s algorithm for finding MST Step 1: x ∈ V, Let A = {x}, B = V - {x}. Step 2: Select (u, v) ∈ E, u ∈ A, v ∈ B such that (u, v) has the smallest weight between A and B. Step 3: Put (u, v) in the tree. A = A ∪ {v}, B = B - {v} Step 4: If B = ∅, stop; otherwise, go to Step 2.  Time complexity : O(n2 ), n = |V|. (see the example on the next page)
  • 15. 4 -15 An example for Prim’s algorithm
  • 16. 4 -16 The single-source shortest path problem  shortest paths from v0 to all destinations
  • 17. 4 -17 Dijkstra’s algorithm 1 2 3 4 5 6 7 8 1 0 2 300 0 3 1000 800 0 4 1200 0 5 1500 0 250 6 1000 0 900 1400 7 0 1000 8 1700 0 Cost adjacency matrix. All entries not shown are +∞.
  • 18. 4 -18  Time complexity : O(n2 ) Vertex Iteration S Selected (1) (2) (3) (4) (5) (6) (7) (8) Initial ---- 1 5 6 +∞ +∞ +∞ 1500 0 250 +∞ +∞ 2 5,6 7 +∞ +∞ +∞ 1250 0 250 1150 1650 3 5,6,7 4 +∞ +∞ +∞ 1250 0 250 1150 1650 4 5,6,7,4 8 +∞ +∞ 2450 1250 0 250 1150 1650 5 5,6,7,4,8 3 3350 +∞ 2450 1250 0 250 1150 1650 6 5,6,7,4,8,3 2 3350 3250 2450 1250 0 250 1150 1650 5,6,7,4,8,3,2 3350 3250 2450 1250 0 250 1150 1650
  • 19. 4 -19  Can we use Dijkstra’s algorithm to find the longest path from a starting vertex to an ending vertex in an acyclic directed graph?  There are 3 possible ways to apply Dijkstra’s algorithm:  Directly use “max” operations instead of “min” operations.  Convert all positive weights to be negative. Then find the shortest path.  Give a very large positive number M. If the weight of an edge is w, now M-w is used to replace w. Then find the shortest path.  All these 3 possible ways would not work! The longest path problem
  • 20. 4 -20 Activity On Edge (AOE) Networks  Tasks (activities) : a0, a1,…  Events : v0,v1,… V0 V1 V2 V3 V4 V6 V7 V8 V5 finish a0 = 6 start a1 = 4 a2 = 5 a4 = 1 a3 = 1 a5 = 2 a6 = 9 a7 = 7 a8 = 4 a10 = 4 a9 = 2 Some definition:  Predecessor  Successor  Immediate predecessor  Immediate successor
  • 21. 4 -21 critical path  A critical path is a path that has the longest length. (v0, v1, v4, v7, v8) V0 V1 V2 V3 V4 V6 V7 V8 V5 a0 = 6 a1 = 4 a2 = 5 a4 = 1 a3 = 1 a5 = 2 a6 = 9 a7 = 7 a8 = 4 a10 = 4 a9 = 2 start finish 6 + 1 + 7 + 4 = 18 (Max)
  • 22. 4 -22 The earliest time  The earliest time of an activity, ai, can occur is the length of the longest path from the start vertex v0 to ai’s start vertex. ( Ex: the earliest time of activity a7 can occur is 7. )  We denote this time as early(i) for activity ai. ∴ early(6) = early(7) = 7. V0 V1 V2 V3 V4 V6 V7 V8 V5 finish a0 = 6 start a1 = 4 a2 = 5 a4 = 1 a3 = 1 a5 = 2 a6 = 9 a7 = 7 a8 = 4 a10 = 4 a9 = 2 6/? 0/? 7/? 16/? 0/? 5/? 7/? 14/?7/?4/? 0/? 18
  • 23. 4 -23 The latest time  The latest time, late(i), of activity, ai, is defined to be the latest time the activity may start without increasing the project duration.  Ex: early(5) = 5 & late(5) = 8; early(7) = 7 & late(7) = 7 V0 V1 V2 V3 V4 V6 V7 V8 V5 finish a0 = 6 start a1 = 4 a2 = 5 a4 = 1 a3 = 1 a5 = 2 a6 = 9 a7 = 7 a8 = 4 a10 = 4 a9 = 2 late(5) = 18 – 4 – 4 - 2 = 8 late(7) = 18 – 4 – 7 = 7 6/6 0/1 7/7 16/16 0/3 5/8 7/10 14/147/74/5 0/0
  • 24. 4 -24 Critical activity  A critical activity is an activity for which early(i) = late(i).  The difference between late(i) and early(i) is a measure of how critical an activity is. Calculation of Latest Times Calculation of Earliest Times Finding Critical path(s) To solve AOE Problem
  • 25. 4 -25 Calculation of Earliest Times  Let activity ai is represented by edge (u, v).  early (i) = earliest [u]  late (i) = latest [v] – duration of activity ai  We compute the times in two stages: a forward stage and a backward stage.  The forward stage:  Step 1: earliest [0] = 0  Step 2: earliest [j] = max {earliest [i] + duration of (i, j)} i is in P(j) P(j) is the set of immediate predecessors of j.
  • 26. 4 -26  The backward stage:  Step 1: latest[n-1] = earliest[n-1]  Step 2: latest [j] = min {latest [i] - duration of (j, i)} i is in S(j) S(j) is the set of vertices adjacent from vertex j. latest[8] = earliest[8] = 18 latest[6] = min{earliest[8] - 2} = 16 latest[7] = min{earliest[8] - 4} = 14 latest[4] = min{earliest[6] – 9; earliest[7] – 7} = 7 latest[1] = min{earliest[4] - 1} = 6 latest[2] = min{earliest[4] - 1} = 6 latest[5] = min{earliest[7] - 4} = 10 latest[3] = min{earliest[5] - 2} = 8 latest[0] = min{earliest[1] – 6; earliest[2] – 4; earliest[3] – 5} = 0 Calculation of Latest Times
  • 27. 4 -27 Graph with non-critical activities deleted V0 V1 V2 V3 V4 V6 V7 V8 V5 finish a0 start a1 a2 a4 a3 a5 a6 a7 a8 a10 a9 V0 V1 V4 V6 V7 V8 finish a0 start a3 a6 a7 a10 a9 Activity Early Late L - E Critical a0 0 0 0 Yes a1 0 2 2 No a2 0 3 3 No a3 6 6 0 Yes a4 4 6 2 No a5 5 8 3 No a6 7 7 0 Yes a7 7 7 0 Yes a8 7 10 3 No a9 16 16 0 Yes a10 14 14 0 Yes
  • 28. 4 -28  The longest path(critical path) problem can be solved by the critical path method(CPM) : Step 1:Find a topological ordering. Step 2: Find the critical path. (see [Horiwitz 1998].) CPM for the longest path problem
  • 29. 4 -29 The 2-way merging problem  # of comparisons required for the linear 2- way merge algorithm is m1 + m2 -1 where m1 and m2 are the lengths of the two sorted lists respectively.  The problem: There are n sorted lists, each of length mi . What is the optimal sequence of merging process to merge these n lists into one sorted list ?
  • 30. 4 -30  Extended Binary Tree Representing a 2-way Merge Extended binary trees
  • 31. 4 -31 An example of 2-way merging  Example: 6 sorted lists with lengths 2, 3, 5, 7, 11 and 13.
  • 32. 4 -32  Time complexity for generating an optimal extended binary tree:O(n log n)
  • 33. 4 -33 Huffman codes  In telecommunication, how do we represent a set of messages, each with an access frequency, by a sequence of 0’s and 1’s?  To minimize the transmission and decoding costs, we may use short strings to represent more frequently used messages.  This problem can by solved by using an extended binary tree which is used in the 2- way merging problem.
  • 34. 4 -34 An example of Huffman algorithm  Symbols: A, B, C, D, E, F, G freq. : 2, 3, 5, 8, 13, 15, 18  Huffman codes: A: 10100 B: 10101 C: 1011 D: 100 E: 00 F: 01 G: 11 A Huffman code Tree
  • 35. 4 -35 Chapter 4 Greedy method Input(A[1…n]) Solution ←ψ for i ← 1 to n do X ← SELECT(A) ( 最好有一 data structure ,經 preprocessing 後可以很快的找 到 ( 包括 delete)) If FEASIBLE( solution, x) then solution ← UNION( select, x) endif repeat Output (solution) 特點 (1) 做一串 decision (2) 每個 decision 只關心自己是不是 optimal 一部份與其它無關 ( 可以 local check) Note (1) Local optimal 須是 global optimal (2) 有時裡面隱含一個 sorting
  • 36. 4 -36 Knapsack problem  Given positive integers P1, P2, …, Pn, W1, W2, …, Wn and M.  Find X1, X2, … ,Xn, 0≦Xi≦1 such that is maximized.  Subject to ∑= n 1i iiXP ∑= ≤ n 1i ii MXW
  • 37. 4 -37 Knapsack Problem Example  M = 20, (P1, P2, P3)=(25,24,15) (W1, W2, W3) = (18, 15, 10)  Four feasible solutions, 4 is optimal (X1, X2, X3) ΣWiXi ΣPiX 1. (1/2,1/3,1/4) 16.5 24.25 2. (1,2/15,0) 20 28.2 3. (0, 2/3, 1) 20 31 4. (0, 1, 1/2) 20 31.5
  • 38. 4 -38 Job Sequencing with Deadlines  Given n jobs. Associated with job I is an integer deadline Di≧0. For any job I the profit Pi is earned iff the job is completed by its deadline. To complete a job, one has to process the job on a machine for one unit of time.  A feasible solution is a subset J of jobs such that each job in the subset can be completed by its deadline. We want to maximize the ∑∈Ji iP
  • 39. 4 -39  n = 4, (p1, p2, p3, p4) = (100,10,15,27) (d1, d2, d3, d4) = (2, 1, 2, 1) Feasible solution Processing sequence value 1 (1,2) 2,1 110 2 (1,3) 1,3 or 3, 1 115 3 (1,4) 4, 1 127 4 (2,3) 2, 3 25 5 (3,4) 4,3 42 6 (1) 1 100 7 (2) 2 10 8 (3) 3 15 9 (4) 4 27
  • 40. 4 -40 Optimal Storage on Tapes  There are n programs that are to be stored on a computer tape of length L. Associated with each program i is a length Li.  Assume the tape is initially positioned at the front. If the programs are stored in the order I = i1, i2, …, in, the time tj needed to retrieve program ij tj = ∑= j 1k ik L
  • 41. 4 -41 Optimal Storage on Tapes  If all programs are retrieved equally often, then the mean retrieval time (MRT) =  This problem fits the ordering paradigm. Minimizing the MRT is equivalent to minimizing d(I) = ∑= n 1j jt n 1 ∑∑= = n 1j j 1k ik L
  • 42. 4 -42 Example  Let n = 3, (L1,L2,L3) = (5,10,3). 6 possible orderings. The optimal is 3,1,2 Ordering I d(I) 1,2,3 5+5+10+5+10+3 = 38 1,3,2 5+5+3+5+3+10 = 31 2,1,3 10+10+5+10+5+3 = 43 2,3,1 10+10+3+10+3+5 = 41 3,1,2 3+3+5+3+5+10 = 29 3,2,1, 3+3+10+3+10+5 = 34