Docsity

Greedy Algorithm, Scheduling Problem - Discrete Mathematics | MATH 055, Study notes of Discrete Mathematics

Toggle sidebar
bg1
Mathematics 55– Spring 2005
Lecture 14 (Wednesday 2/23/2005)
More on Proof By Induction
Please read §3.4 for this Friday, and §3.5 for next Monday. I plan to devote 4
more lectures, including today’s, to Chapter 3.
Example: Prove by induction that every positive integer ≄2 can be represented as a
product of powers of prime numbers. (Clarification: A ā€œfactorizationā€ with a single
factor is allowed. Thus 2 = 2 is considered to be a prime factorization of 2.)
Attempted Proof : The first small point is that we’re only supposed to prove something
about all n≄2, rather than all integers n≄1. Let Q(n) be the statement that n
can be represented as a product of (positive integer) powers of prime numbers. Let
P(n) be the statement [(n≄2) →Q(n)]. If we prove P(n) for all n≄1 then we will
have proved Q(n) for all n≄2.
Basis step:Ifn=1thenn≄2isFalse,soP(1) is True.
First attempt at inductive step:Letnbe a positive integer. We want to prove
P(n+ 1). There are two cases. (i) If n+ 1 is prime then the desired factorization
is simply to write n+ 1 as itself; this is one of those factorizations having only one
factors. (ii) If n+ 1 is not prime, then by definition of a prime number, there must
exist at least one integer factor q>1 that divides n+ 1. Choose one such factor q,
and write n+1=qr where ris another positive integer. Now both q, r are <n+1.
If the inductive hypothesis applied to both q, r then we could express each as a
product of powers of primes. Multiplyingtogether their two factorizations would yield
a factorization of n+ 1 as a product of powers of primes, completing the inductive
step.
Thus we see that it could be useful to have a different kind of inductive hypothesis,
of the form P(k) for all k≤n.Theprinciple of strong induction says that this is a
valid method of inference. More precisely, the principle of strong induction says that
P(1) āˆ§āˆ€nī˜‚[P(k) for all k≤n]→P(n+1)
ī˜ƒī˜„ā†’āˆ€nP (n)
where the UofD is N.
Example: Prove that the greedy algorithm for the lecture scheduling problem
always produces an optimal solution.
Definitions of terms: The scheduling problem: UC Mudville opens, and each aca-
demic department submits a nonnegotiable list of lectures it wants to hold. Lecture
jbegins at time bj, and ends at time ej;jranges from 1 to n. These times are
arbitrary; a lecture might begin at 9:17 and end at 9:32, while another might begin
at 9:21 and end at 10:05. Alas, due to construction delays, there’s only one lecture
hall. The scheduling office wants to fit in as many lectures as possible, but of course
no two at the same time. How to choose which ones?
1
pf3
pf4
pf5

Partial preview of the text

Download Greedy Algorithm, Scheduling Problem - Discrete Mathematics | MATH 055 and more Study notes Discrete Mathematics in PDF only on Docsity!

Mathematics 55– Spring 2005 Lecture 14 (Wednesday 2/23/2005) More on Proof By Induction

Please read §3.4 for this Friday, and §3.5 for next Monday. I plan to devote 4 more lectures, including today’s, to Chapter 3.

Example: Prove by induction that every positive integer ≄ 2 can be represented as a product of powers of prime numbers. (Clarification: A ā€œfactorizationā€ with a single factor is allowed. Thus 2 = 2 is considered to be a prime factorization of 2.) Attempted Proof : The first small point is that we’re only supposed to prove something about all n ≄ 2, rather than all integers n ≄ 1. Let Q(n) be the statement that n can be represented as a product of (positive integer) powers of prime numbers. Let P (n) be the statement [(n ≄ 2) → Q(n)]. If we prove P (n) for all n ≄ 1 then we will have proved Q(n) for all n ≄ 2. Basis step: If n = 1 then n ≄ 2 is False, so P (1) is True. First attempt at inductive step: Let n be a positive integer. We want to prove P (n + 1). There are two cases. (i) If n + 1 is prime then the desired factorization is simply to write n + 1 as itself; this is one of those factorizations having only one factors. (ii) If n + 1 is not prime, then by definition of a prime number, there must exist at least one integer factor q > 1 that divides n + 1. Choose one such factor q, and write n + 1 = qr where r is another positive integer. Now both q, r are < n + 1. If the inductive hypothesis applied to both q, r then we could express each as a product of powers of primes. Multiplying together their two factorizations would yield a factorization of n + 1 as a product of powers of primes, completing the inductive step. Thus we see that it could be useful to have a different kind of inductive hypothesis, of the form P (k) for all k ≤ n. The principle of strong induction says that this is a

valid method of inference. More precisely, the principle of strong induction says that

[ P (1) ∧ āˆ€n

[P (k) for all k ≤ n] → P (n + 1)

)]

→ āˆ€nP (n)

where the UofD is N.

Example: Prove that the greedy algorithm for the lecture scheduling problem always produces an optimal solution. Definitions of terms: The scheduling problem: UC Mudville opens, and each aca- demic department submits a nonnegotiable list of lectures it wants to hold. Lecture j begins at time bj , and ends at time ej ; j ranges from 1 to n. These times are arbitrary; a lecture might begin at 9:17 and end at 9:32, while another might begin at 9:21 and end at 10:05. Alas, due to construction delays, there’s only one lecture hall. The scheduling office wants to fit in as many lectures as possible, but of course no two at the same time. How to choose which ones?

(Two lectures are not considered to overlap if one begins at exactly the moment when the other ends.) The greedy algorithm: (i) Choose whichever lecture ends earliest. (In case of a tie, choose any one.) (ii) Discard all lectures that overlap with the chosen one. Then go back to step (i), choosing only from among those lectures not discarded. Repeat until no lectures remain. Here’s a series of pictures illustrating a sample set of lectures and the application of the greedy algorithm. Time runs horizontally, from left to right. the time axis is not shown. Each line segment denotes a lecture; the left endpoint indicates its beginning time, and the right endpoint its ending time.

Figure 1: All proposed lectures (above).

Figure 2: The lecture ending earliest has been selected, and all other lectures that overlap with it have been discarded.

then applying the greedy algorithm to A. That is,

greedy(L) = 1 + greedy(A).

Consider any set S of nonoverlapping lectures. Let K ∈ S be a lecture that ends earliest. Express S as S = T ∪ {K} where K /∈ T. Then eK ≤ bi ≤ ei for any i ∈ T. Since eJ ≤ eK, this means that no lecture in T overlaps with lecture J. Thus T āŠ‚ A. By the induction hypothesis, |T | ≤ greedy(A). Thus

|S| = 1 + |T | ≤ 1 + greedy(A) = greedy(L).

Here’s some material that wasn’t included in the lecture, due to time constraints: Comment. There are many, many greedy algorithms. We saw another earlier in the semester, dealing with making change. Greedy algorithms arise in problems where one makes a sequences of choices among alternatives in attempting to optimize or maximize something. Choosing one alternative narrows the field of possibilities for the next choice, and so on. In a greedy algorithm, roughly speaking, one makes whichever choice appears to yield the greatest immediate progress towards the goal, without considering what will happen down the line. In chess, this means thinking only of the present move, rather than thinking ahead. In making change, it means using the largest denomination of coin available, so that the remaining change to be made is minimized. In the scheduling problem, it means choosing whichever lecture ends earliest, so that the greatest amount of time remains for the scheduling of additional lectures. We’ve already learned (text and problem set discussions of making change with various denominations of coins) that sometimes greedy algorithms produce optimal solutions, but sometimes they do not. Greedy algorithms are generally easy to implement — just as chess would be easy if one never had to think ahead. Thus it’s often useful to prove that a greedy algo- rithm is optimal, for one then has a simple and optimal solution.

There are lots of other examples of proofs by induction in our text. I recommend studying them.

There are two theoretical points you might be wondering about. (1) What justifies the principle of induction? That is, why is it a valid rule of inference? (2) What justifies the principle of strong induction? The well-ordering property of N (or of N = { 0 , 1 , 2 , Ā· Ā· Ā· } = N ∪ { 0 }): Every nonempty subset of N contains a (unique) smallest element. That is: if S āŠ‚ N is

nonempty then there exists n ∈ S such that (k ∈ S) → (n ≤ k). In this course, we accept the well-ordering property as an axiom about N, that is, as a fundamental assumption that is not proved. In mathematics one must begin with some axioms; one can’t prove something from nothing at all. In more advanced treatments one starts with the theory of sets and with a small list of axioms about sets, and one proves the well-ordering property from those axioms. To do that would take us much of a semester, and although fascinating, would probably not significantly advance our understanding of the subject matter of this course. So I hope that you’re willing to take the well-ordering property for granted.

Proof that induction is a valid method of inference: Suppose given some predicate P (n). Suppose that P (1) is True, and that āˆ€n ∈ N(P (n) → P (n + 1)) is True. We must prove that P (n) is True for all n ∈ N. Let S be the set of all n ∈ N for which P (n) is False; we want to prove that S is empty. If not, then by the well-ordering property, S has some smallest element, k. Let n = k āˆ’ 1. Then n /∈ S, since k is smallest. Therefore P (n) is True. Then both P (n) and P (n) → P (n + 1) are True, so P (n + 1) is True by modus ponens. Thus P (k) is True, so k /∈ S, a contradiction. Thus S must be empty.