SlideShare a Scribd company logo
Design and Analysis of Algorithms
Lecture 8
• Job scheduling problem (continued)
• Synchronizing a circuit with minimum delay
1
Algorithms-II : CS345A
A Job scheduling problem
Recap the last lecture
2
• There are jobs:
• Each job takes certain time for execution.
• Each job also has a deadline.
• There is a single server.
All jobs need to be scheduled.
Aim: Compute an order , ,…, in which the jobs should be scheduled
such that maximum lateness is minimized.
3
, ,…,
Job takes time
Job has deadline
time
𝑗𝑖 1
𝑗𝑖 𝑛
𝑗𝑖 2
𝑗𝑖 3
𝟎
𝑗𝑖 𝑘
𝑑𝑖 𝑘
𝑓 𝑖𝑘 𝑑𝑖 𝑘
Lateness of
Scheduling 2 jobs
Lemma:(for 2 jobs)
Scheduling ``the earlier deadline job’’  an optimal solution
4
𝑗1
𝑗 2
𝑡 2
𝑡1
𝑑2
𝑑1
time
𝑗1
𝑗 2
𝟎
In the last class, we realized Time of execution is immaterial
How to schedule more than 2 jobs ?
Lemma:(for 2 jobs)
Scheduling ``the earlier deadline job’’  an optimal solution
5
time
𝟎
Consider any schedule
How to schedule more than 2 jobs ?
Lemma:(for 2 jobs)
Scheduling ``the earlier deadline job’’  an optimal solution
• Schedule the jobs in increasing order of their deadlines.
6
𝟎 time
``jobs scheduled in the increasing order of deadline’’ is an optimal schedule
Algorithm:
time
Consider any schedule
Consider any pair of consecutive jobs.
If they are not scheduled in the increasing order of their deadlines,
swapping them will only minimize the maximum lateness of the schedule
By repeating this step for each pair of consecutive jobs,
we can transform the schedule into a schedule
whose maximum lateness is less than or equal to that of the original schedule.
How do the jobs appear in the
final schedule ?
In increasing order of deadlines.
What if the original schedule
was an optimal schedule ?
SYNCHRONIZING A CIRCUIT
with minimum delay enhancement
7
An Electric Circuit
Electric signal originates at the root
Signal passing through each edge incurs a delay (a few nano seconds)
Finally signal reaches all the leaves.
8
5
6
2
2
3 2
6
2 1 2 1
4
2 3
Delay 11 10 14 10 10 11 10 9
Electric signal
A complete binary tree
14 10
Problem definition
Given:
• There is a circuit in the form of a complete binary tree.
• Electric signal propagates from root to all leaf nodes.
• Each edge has certain delay
• The delay in reaching signal to a leaf node =
“sum of delays on all edges on the path from root.”
Objective:
Enhance delay along certain edges so that
• The delay on all paths from root to leaf nodes is the same.
• Total delay enhancement is minimum.
9
What is the first
step for designing
an algorithm ?
Working on an Example
10
Working on an Example
Total delay enhancement: 27
11
5
6
2
2
3 2
6
2 1 2 1
4
2 3
Delay 11 10 14 10 10 11 10 9
Electric signal
+3 +4 +4 +3 +4 +5
New Delay 14 14 14 14 14 14 14 14
How to achieve 1st
Objective:
Synchronizing all
paths from the root?
How much
enhancement is
needed for this edge ?
+4 is necessary
What algorithm
comes to your mind
based on this
inference ?
Is this the minimum
delay enhancement ?
+4
Spend some time on this
portion to see if you can
reduce the total delay ?
Working on an Example
Total delay enhancement: 27
12
5
6
2
2
3 2
6
2 1 2 1
4
2 3
Delay 11 10 14 10 10 11 10 9
Electric signal
+3 +4 +4 +4 +3 +1
New Delay 14 14 14 14 14 14 14 14
+4
 23
What algorithm
comes to your mind
based on this
inference ?
𝒖
+1 is necessary for .
𝒗
Recall from the past slide
+4 is necessary for .
Toward designing an algorithm
Total delay enhancement: 14
13
5
6
2
2
3 2
6
2 1 2 1
4
2 3
Delay 11 10 14 10 10 11 10 9
Electric signal
+1
+1
+4
+1
+3
+3
+1
10
11
14
11 11
11
14
14 14 14 14 14
For nodes just above the leaf level What about the nodes
at higher levels ?
All this enhancement was
absolutely necessary.
Inspired by the processing done at the lower levels,
the following seems to be the way to process higher nodes.
Overview of the proposed algorithm
Process the nodes in bottom up order.
A non-leaf node is processed as follows:
• Compute the max-delay path from to a leaf node lying in its left subtree.
• Compute the max-delay path from to a leaf node lying in its right subtree.
If the two delays differ,
“enhance the delay of one of its edges accordingly”
14
We need to describe this step more formally. 
u
For each non-leaf node do the following:
: max delay along any leftward path
: max delay along any rightward path
If ()
increase delay of right edge by -
Else
increase delay of left edge by -
15
𝜷
𝜶
𝜸
𝑫𝑹(𝒖)
𝑫𝑳(𝒖)
+𝑫𝑳(𝒖) − 𝑫𝑹 (𝒖)
+𝑫𝑹 (𝒖) − 𝑫𝑳(𝒖)
PROOF OF CORRECTNESS OF THE ALGORITHM
16
WHAT ASSERTION SUFFICES AS A PROOF ?
What assertion suffices as a proof ?
Usually it is difficult even to find out the claim whose establishment captures the
correctness of the algorithm.
In the current algorithm, what might be this claim ?
Let us have a re-look at the algorithm from point of view of a single node .
17
u
For each non-leaf node do the following:
: max delay along any leftward path
: max delay along any rightward path
If ()
increase delay of right edge by -
Else
increase delay of left edge by -

Delay enhancement by : | - |
18
𝜷
𝜶
𝜸
𝑫𝑹(𝒖)
𝑫𝑳(𝒖)
+𝑫𝑳(𝒖) − 𝑫𝑹 (𝒖)
Claim :
There is an optimal solution where,
the delay enhancement by = ||
Question: How to prove the claim ?
Answer: make careful observations about the algorithm .
19
Observation 1
Root is synchronized in the optimal solution.
Question: What can we say about the synchronization of any node in the optimal solution?
Answer: Every node must be synchronized.
(proof by contradiction: append the path from root to to get two paths with
different delays.)
20
Electric signal
𝜹𝟏 𝜹𝟐
𝒖
Observation 2
Question: In optimal sol., what is the max. delay along any path from to a leaf node ?
Guess: It remain unchanged.
In other words, it will still be max().
21
5
6
2
2
3 2
6
2 1 2 1
4
2 3
Delay 11 10 14 10 10 11 10 9
Electric signal
𝒖
+1
+1
+4
+1
+3
+3
+1
New Delay 14 14 14 14 14 14 14 14
The maximum delay from the root to
any leaf node remains unchanged in the
optimal solution. What can we say about
the maximum delay from any other
node to any leaf node in its subtree?
Usefulness of the guess
22
u
Usefulness of the guess
 In the optimal solution,
we must increase delay of right edge
by ??

Delay enhancement by : | - |
Guess  proof of correctness of algorithm
23
𝜷
𝜶
𝜸
Suppose
𝑫𝑹(𝒖)
𝑫𝑳(𝒖)
+𝑫𝑳(𝒖) − 𝑫𝑹 (𝒖)
-
unchanged
unchanged
How much
enhancement ?
0
How much
enhancement ?
Proving the guess
Guess : In the optimal solution, the delay along any path from to any leaf
node is max().
Question: How to prove it ?
Answer: By contradiction.
24
What if the assertion fails at many nodes ?
Homework: Make sincere attempt to get proof by contradiction.
25

More Related Content

PPT
Mit15 082 jf10_lec01
PPTX
How Scylla Make Adding and Removing Nodes Faster and Safer
PDF
STA STATIC TIMING ANALYSIS AND ITS USE HOW IT WORKS
PPTX
Lecture-12-CS345A-2023 of Design and Analysis
PPTX
[Slides]L2.pptx
PPTX
Greedy technique - Algorithm design techniques using data structures
PPT
36 greedy
PDF
A greedy algorithms
Mit15 082 jf10_lec01
How Scylla Make Adding and Removing Nodes Faster and Safer
STA STATIC TIMING ANALYSIS AND ITS USE HOW IT WORKS
Lecture-12-CS345A-2023 of Design and Analysis
[Slides]L2.pptx
Greedy technique - Algorithm design techniques using data structures
36 greedy
A greedy algorithms

Similar to Lecture-8-CS345A-2023 of Design and Analysis (20)

PPT
8783733
PPTX
EC561
PPTX
Embedded-Project
PPTX
01 - DAA - PPT.pptx
PDF
Advd lecture 7 logical effort
PDF
lec03 lec03 lec03 lec03 lec03 lec03 lec03
PDF
Clock distribution in high speed board
PPTX
streamingalgo88585858585858585pppppp.pptx
PPTX
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
PDF
El text.tokuron a(2019).jung190711
PDF
MSc Thesis Presentation
PPTX
ECG DENOISING USING NN.pp
PPTX
SFG.pptx
PPTX
prescalers and dual modulus prescalers
PDF
routing (1).pdf shjsjajajaaknsjsjskakakskaksksksk
PPT
Biomedical Signal ProcessingBiomedical Signal Processinglecture21.ppt
PPT
bspbspbspbspbspbspbspbspbsplecture21.ppt
PPTX
Control Signal Flow Graphs lecture notes
PPTX
Linear Programming- Leacture-16-lp1.pptx
PPT
Elegant Solutions
8783733
EC561
Embedded-Project
01 - DAA - PPT.pptx
Advd lecture 7 logical effort
lec03 lec03 lec03 lec03 lec03 lec03 lec03
Clock distribution in high speed board
streamingalgo88585858585858585pppppp.pptx
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
El text.tokuron a(2019).jung190711
MSc Thesis Presentation
ECG DENOISING USING NN.pp
SFG.pptx
prescalers and dual modulus prescalers
routing (1).pdf shjsjajajaaknsjsjskakakskaksksksk
Biomedical Signal ProcessingBiomedical Signal Processinglecture21.ppt
bspbspbspbspbspbspbspbspbsplecture21.ppt
Control Signal Flow Graphs lecture notes
Linear Programming- Leacture-16-lp1.pptx
Elegant Solutions
Ad

More from ssuser9183b6 (7)

PPTX
DEsign and Analysis of ALgorithms slides of lecture 1, 2 and 3
PPTX
Lecture-13-CS345A-2023 of Design and Analysis
PPTX
Lecture-11-CS345A-2023 of Design and Analysis
PPTX
Lecture-7-CS345A-2023 of Design and Analysis
PPTX
Lecture-10-CS345A-2023 of Design and Analysis
PPTX
Lecture-7-CS345A-2023 of Design and Analysis
PPTX
DiscreteMathematicsfor btechAsWeProgress.pptx
DEsign and Analysis of ALgorithms slides of lecture 1, 2 and 3
Lecture-13-CS345A-2023 of Design and Analysis
Lecture-11-CS345A-2023 of Design and Analysis
Lecture-7-CS345A-2023 of Design and Analysis
Lecture-10-CS345A-2023 of Design and Analysis
Lecture-7-CS345A-2023 of Design and Analysis
DiscreteMathematicsfor btechAsWeProgress.pptx
Ad

Recently uploaded (20)

PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Welding lecture in detail for understanding
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPT
Project quality management in manufacturing
PDF
Digital Logic Computer Design lecture notes
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
UNIT 4 Total Quality Management .pptx
PDF
PPT on Performance Review to get promotions
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Operating System & Kernel Study Guide-1 - converted.pdf
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Automation-in-Manufacturing-Chapter-Introduction.pdf
UNIT-1 - COAL BASED THERMAL POWER PLANTS
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Welding lecture in detail for understanding
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Project quality management in manufacturing
Digital Logic Computer Design lecture notes
Lecture Notes Electrical Wiring System Components
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Mechanical Engineering MATERIALS Selection
Internet of Things (IOT) - A guide to understanding
UNIT 4 Total Quality Management .pptx
PPT on Performance Review to get promotions

Lecture-8-CS345A-2023 of Design and Analysis

  • 1. Design and Analysis of Algorithms Lecture 8 • Job scheduling problem (continued) • Synchronizing a circuit with minimum delay 1 Algorithms-II : CS345A
  • 2. A Job scheduling problem Recap the last lecture 2
  • 3. • There are jobs: • Each job takes certain time for execution. • Each job also has a deadline. • There is a single server. All jobs need to be scheduled. Aim: Compute an order , ,…, in which the jobs should be scheduled such that maximum lateness is minimized. 3 , ,…, Job takes time Job has deadline time 𝑗𝑖 1 𝑗𝑖 𝑛 𝑗𝑖 2 𝑗𝑖 3 𝟎 𝑗𝑖 𝑘 𝑑𝑖 𝑘 𝑓 𝑖𝑘 𝑑𝑖 𝑘 Lateness of
  • 4. Scheduling 2 jobs Lemma:(for 2 jobs) Scheduling ``the earlier deadline job’’  an optimal solution 4 𝑗1 𝑗 2 𝑡 2 𝑡1 𝑑2 𝑑1 time 𝑗1 𝑗 2 𝟎 In the last class, we realized Time of execution is immaterial
  • 5. How to schedule more than 2 jobs ? Lemma:(for 2 jobs) Scheduling ``the earlier deadline job’’  an optimal solution 5 time 𝟎 Consider any schedule
  • 6. How to schedule more than 2 jobs ? Lemma:(for 2 jobs) Scheduling ``the earlier deadline job’’  an optimal solution • Schedule the jobs in increasing order of their deadlines. 6 𝟎 time ``jobs scheduled in the increasing order of deadline’’ is an optimal schedule Algorithm: time Consider any schedule Consider any pair of consecutive jobs. If they are not scheduled in the increasing order of their deadlines, swapping them will only minimize the maximum lateness of the schedule By repeating this step for each pair of consecutive jobs, we can transform the schedule into a schedule whose maximum lateness is less than or equal to that of the original schedule. How do the jobs appear in the final schedule ? In increasing order of deadlines. What if the original schedule was an optimal schedule ?
  • 7. SYNCHRONIZING A CIRCUIT with minimum delay enhancement 7
  • 8. An Electric Circuit Electric signal originates at the root Signal passing through each edge incurs a delay (a few nano seconds) Finally signal reaches all the leaves. 8 5 6 2 2 3 2 6 2 1 2 1 4 2 3 Delay 11 10 14 10 10 11 10 9 Electric signal A complete binary tree 14 10
  • 9. Problem definition Given: • There is a circuit in the form of a complete binary tree. • Electric signal propagates from root to all leaf nodes. • Each edge has certain delay • The delay in reaching signal to a leaf node = “sum of delays on all edges on the path from root.” Objective: Enhance delay along certain edges so that • The delay on all paths from root to leaf nodes is the same. • Total delay enhancement is minimum. 9 What is the first step for designing an algorithm ?
  • 10. Working on an Example 10
  • 11. Working on an Example Total delay enhancement: 27 11 5 6 2 2 3 2 6 2 1 2 1 4 2 3 Delay 11 10 14 10 10 11 10 9 Electric signal +3 +4 +4 +3 +4 +5 New Delay 14 14 14 14 14 14 14 14 How to achieve 1st Objective: Synchronizing all paths from the root? How much enhancement is needed for this edge ? +4 is necessary What algorithm comes to your mind based on this inference ? Is this the minimum delay enhancement ? +4 Spend some time on this portion to see if you can reduce the total delay ?
  • 12. Working on an Example Total delay enhancement: 27 12 5 6 2 2 3 2 6 2 1 2 1 4 2 3 Delay 11 10 14 10 10 11 10 9 Electric signal +3 +4 +4 +4 +3 +1 New Delay 14 14 14 14 14 14 14 14 +4  23 What algorithm comes to your mind based on this inference ? 𝒖 +1 is necessary for . 𝒗 Recall from the past slide +4 is necessary for .
  • 13. Toward designing an algorithm Total delay enhancement: 14 13 5 6 2 2 3 2 6 2 1 2 1 4 2 3 Delay 11 10 14 10 10 11 10 9 Electric signal +1 +1 +4 +1 +3 +3 +1 10 11 14 11 11 11 14 14 14 14 14 14 For nodes just above the leaf level What about the nodes at higher levels ? All this enhancement was absolutely necessary. Inspired by the processing done at the lower levels, the following seems to be the way to process higher nodes.
  • 14. Overview of the proposed algorithm Process the nodes in bottom up order. A non-leaf node is processed as follows: • Compute the max-delay path from to a leaf node lying in its left subtree. • Compute the max-delay path from to a leaf node lying in its right subtree. If the two delays differ, “enhance the delay of one of its edges accordingly” 14 We need to describe this step more formally. 
  • 15. u For each non-leaf node do the following: : max delay along any leftward path : max delay along any rightward path If () increase delay of right edge by - Else increase delay of left edge by - 15 𝜷 𝜶 𝜸 𝑫𝑹(𝒖) 𝑫𝑳(𝒖) +𝑫𝑳(𝒖) − 𝑫𝑹 (𝒖) +𝑫𝑹 (𝒖) − 𝑫𝑳(𝒖)
  • 16. PROOF OF CORRECTNESS OF THE ALGORITHM 16 WHAT ASSERTION SUFFICES AS A PROOF ?
  • 17. What assertion suffices as a proof ? Usually it is difficult even to find out the claim whose establishment captures the correctness of the algorithm. In the current algorithm, what might be this claim ? Let us have a re-look at the algorithm from point of view of a single node . 17
  • 18. u For each non-leaf node do the following: : max delay along any leftward path : max delay along any rightward path If () increase delay of right edge by - Else increase delay of left edge by -  Delay enhancement by : | - | 18 𝜷 𝜶 𝜸 𝑫𝑹(𝒖) 𝑫𝑳(𝒖) +𝑫𝑳(𝒖) − 𝑫𝑹 (𝒖)
  • 19. Claim : There is an optimal solution where, the delay enhancement by = || Question: How to prove the claim ? Answer: make careful observations about the algorithm . 19
  • 20. Observation 1 Root is synchronized in the optimal solution. Question: What can we say about the synchronization of any node in the optimal solution? Answer: Every node must be synchronized. (proof by contradiction: append the path from root to to get two paths with different delays.) 20 Electric signal 𝜹𝟏 𝜹𝟐 𝒖
  • 21. Observation 2 Question: In optimal sol., what is the max. delay along any path from to a leaf node ? Guess: It remain unchanged. In other words, it will still be max(). 21 5 6 2 2 3 2 6 2 1 2 1 4 2 3 Delay 11 10 14 10 10 11 10 9 Electric signal 𝒖 +1 +1 +4 +1 +3 +3 +1 New Delay 14 14 14 14 14 14 14 14 The maximum delay from the root to any leaf node remains unchanged in the optimal solution. What can we say about the maximum delay from any other node to any leaf node in its subtree?
  • 22. Usefulness of the guess 22
  • 23. u Usefulness of the guess  In the optimal solution, we must increase delay of right edge by ??  Delay enhancement by : | - | Guess  proof of correctness of algorithm 23 𝜷 𝜶 𝜸 Suppose 𝑫𝑹(𝒖) 𝑫𝑳(𝒖) +𝑫𝑳(𝒖) − 𝑫𝑹 (𝒖) - unchanged unchanged How much enhancement ? 0 How much enhancement ?
  • 24. Proving the guess Guess : In the optimal solution, the delay along any path from to any leaf node is max(). Question: How to prove it ? Answer: By contradiction. 24
  • 25. What if the assertion fails at many nodes ? Homework: Make sincere attempt to get proof by contradiction. 25