Welcome to CSCA20

Download Report

Transcript Welcome to CSCA20

CSCA67 -- Proofs
Goals
Problem Solving
★ Apply known problem solving techniques such as
greedy algorithms.
★ Learn to reduce problems to ones we already can
solve.
★ Formalize our language to make proofs easier to write.
Proving
 Understand various proof techniques such as proof by
contradiction, induction, proof by cases, direct proofs
 Apply those same techniques.
 Make our arguments rigorous!
1
Weighted Job Scheduling
Problem
Given a set of jobs where
 each job has a value or weight
 jobs have a start time and duration
Schedule the jobs so that
 the total value is maximized
 scheduled jobs do not overlap
Q. What are some examples of this type of problem?
A. printer queue, airplanes on runway, server use,
scheduling surgeries…
2
Some Examples
10
5
16
3
Time
3
Some Examples
10
25
19
3
Time
4
Finding an Algorithm
Q. What is an algorithm?
A. A step-by-step procedure for solving a problem or
accomplishing some end especially by a computer.*
Let’s list some potential algorithms to try:
Earliest start time.
10
5
16
3
Time
* Merrian-Webster
5
Potential Algorithms
Largest weight first.
25
10
16
3
Time
Other ideas?
6
Potential Algorithms
Create all possible orders by largest weight first.
Eg. Option 1: Pick 25.
Option 2: Pick 16. Pick 10. Pick 3. Total = 29.
25
16
10
3
11
Time
Q. Does this work?
A. Now Option 2 is Pick 16. Pick 11. Total = 27.
7
So...What’s the Answer?
Use a mathematical tool called Dynamic Programming.
➡You can read about it in a text such as Algorithm
Design by Kleinberg and Tardos.
➡Or visit this link:
http://www.cs.princeton.edu/~wayne/kleinberg-tardos/06dynamicprogramming-2x2.pdf
➡Or take CSCC73.
8
A Simpler Problem
Interval Scheduling Problem
Given a set of jobs where
★ jobs have a start time and finish time
Schedule the jobs so that
 the number of jobs scheduled is maximized
 jobs do not overlap
Notation
J: The set of jobs
ji: The ith job
si: The start time of the ith job
fi: The finish time of the ith job
9
Scheduling The Jobs
What is our algorithm?
Example
j1
j2
j3
j4
j6
j5
j7
Challenge
First person to come up with a correct algorithm wins
chocolate.
10
Scheduling The Jobs
What is our algorithm?
Sort the jobs by increasing start time. Schedule each job if
there are no conflicts.
Example
j1
j2
j3
j4
j6
j5
j7
Ordering
j1, j3, j6, j4, j7, j2, j5
Schedule
j1, j7, j5
11
Scheduling The Jobs
What is our algorithm?
Sort the jobs by increasing start time. Schedule each job if
there are no conflicts.
Does this algorithm always find the best solution?
j2
j1
j3
Ordering
j4
j6
j5
j7
j1, j3, j6, j4, j7, j2, j5
Schedule
j1
12
Scheduling The Jobs
Other ideas?
Does this algorithm always find the best solution?
Ordering
Schedule
13
Scheduling The Jobs
What is our algorithm?
Sort the jobs by increasing finish time. Schedule each job if
there are no conflicts.
Example
j1
j2
j3
j4
j6
j5
j7
Ordering
j3, j6, j1, j7, j4, j2, j5
Schedule
j3, j7, j5
14
Is It Correct?
Q. How do we know our algorithm is correct?
A. Prove it!
One common proof technique is “Proof by Contradiction”
Idea
 Play Devil’s Advocate
 Assume our solution is not the best
 This means there is a better solution B
 Show that our algorithm’s solution is as good as B by making
B equivalent to our solution.
15
The Proof
Let S be the schedule our algorithm creates.
S = (s1, s2, s3, ... , sn)
Consider the set of all optimal solutions O.
Let B be an optimal solution in O
B = (b1, b2, b3, ... , bm)
such that
bi = si for all i < k
where k is maximized. This means that
– the first k-1 values in B and S are the same AND
– no solution in O has the first k values the same as S.
16
The Proof
Let S be the schedule our algorithm creates and B an optimal
solution. Assume that S is NOT OPTIMAL.
S = (s1, s2, s3, ... , sn)
B = (b1, b2, b3, ... , bm)
Q. What do we know about m and n?
A. m > n
Q. What do we know about bk and sk?
A. The finish time for sk is less than or equal to the finish time
for bk.
Q. Why?
17
The Proof
S = (s1, s2, s3, ... , sn)
B = (b1, b2, b3, ... , bm)
Q. If the finish time for sk is less then or equal to the finish time for bk,
what can we say about B* = (b1, b2, b3, ...sk, … , bm)?
A. |B*| = |B|. So B* is as good a solution as B but now B* has the first k
values the same.
Q. How does this finish the proof?
A. We said that B was an optimal solution such that k was as big as
possible. B* has more initial values the same creating a contradiction.
Therefore, our original assumption that S is not optimal must have
been wrong.
18
Challenge
Another Scheduling Problem
Given a set of employees, want to set up a meeting that
everyone can attend. Each person has a calendar
which says whether they are available for any given time
slot during the day.
Give an efficient algorithm to schedule the meeting so
that everyone can attend (if possible).
19