MA THEMA TICAL INDUCTION Induction and Deduction - - PDF document

ma thema tical induction induction and deduction
SMART_READER_LITE
LIVE PREVIEW

MA THEMA TICAL INDUCTION Induction and Deduction - - PDF document

MA THEMA TICAL INDUCTION Induction and Deduction Mathematical Induction (its strength) Examples { Sum of rst n naturual numb ers Prove b y induction that the sum of the rst n natural numb ers is


slide-1
SLIDE 1 MA THEMA TICAL INDUCTION
  • Induction
and Deduction
  • Mathematical
Induction (its strength)
  • Examples
{ Sum
  • f
rst n naturual numb ers Prove b y induction that the sum
  • f
the rst n natural numb ers is n(n + 1)=2. i.e. S (i) : n X i=1 i = n
  • (n
+ 1) 2 { Sum
  • f
p
  • w
ers
  • f
t w
  • Prove
b y induction that the sum
  • f
the rst n p
  • w
ers
  • f
t w
  • (0..n)
is 2 n+1
  • 1.
i.e. S (i) : n X i=0 2 i = 2 n+1
  • 1
{ nth derivative
  • f
e k x Prove b y induction that the nth derivative
  • f
e k x is k n e k x . i.e. S (n) : d n dx n e k x = k n e k x 1
slide-2
SLIDE 2
  • Arithmetic
and Geometric p rogressions. { Derivations
  • f
general fo rms { Pro
  • fs
b y induction { An exp ression fo r the sum
  • f
the rst n
  • dd
numb ers and p rove it using Mathematical In- duction. { Pro cedure fo r deriving an exp ression fo r the sum
  • f
a p
  • lynomial
series: P n i=0 p(n k ) where p(n k ) is a p
  • lynomial
in n
  • f
  • rder
k : a 1 n k + a 2 n k 1 +
  • +
a k
  • General
template fo r Induction p ro
  • fs:
  • One
mo re example: Erro r co rrecting co des S(n): C n is any set
  • f
bit strings
  • f
length n that is erro r detecting, then C n contains at most 2 n1 strings. { Assume S(n) { Divide C n+1 into t w
  • sets
  • f
strings 1x and 0y { x & y
  • bviously
b e erro r detecting themselves. { By hyp
  • thesis,
x/y contain no mo re than 2 n1 strings. { Thus maximum total numb er
  • f
strings is 2
  • 2
n1 = 2 n+11 2
slide-3
SLIDE 3 Complete (strong) Vs W eak induction
  • Complete
(o r strong) induction: Uses t w
  • r
mo re assumptions from the basis up to n.
  • Examples:
Prove that there exist integers a and b such that 8n 2 Z \ n > : n = 2a + 3b. Prove that there exist no integers x; y ; z such that 8n 2 Z \ n > 2 : x n + y n = z n .
  • F
allacies and getting ca rried a w a y with induction (All ma rbles a re red, 8n 2 Z : a n = 1)
  • Structural
induction: Proving p rop erties ab
  • ut
a structure b y using a basis case and an inductive assumption.
  • Examples:
In a colony
  • f
aphids rep ro ducing asexually , let the status
  • f
an aphid b e rep resented b y the numb er
  • f
its children. Sho w that the total numb er
  • f
aphids in the colony is
  • ne
mo re than the sum
  • f
the sta- tuses
  • f
all the aphids. Assume that a pa rticula r implementation
  • f
Bina ry trees uses the No de with right and left child p
  • int-
ers. In such a bina ry tree, p rove that the numb er
  • f
NULL p
  • inters
is
  • ne
mo re than the total numb er
  • f
no des. 3
slide-4
SLIDE 4 Proving Program Prop erties What a re lo
  • p
inva riants? A Selection So rt p rogram: (1) for (i = 0; i < n-1; i++) { (2) small = i; (3) for (j = i+1; j < n; j++) (4) if (A[j] < A[small]) (5) small = j; (6) swap(&A[small], &A[i]); (7) } S (k ): If w e reach the test fo r j < n
  • n
line (3) with j = k then smal l indexes smallest
  • f
A[i::k
  • 1].
4
slide-5
SLIDE 5 Basis: S (i + 1): smal l indexes smallest
  • f
A[i::i]. Induction: Pro
  • f
  • f
S (k + 1) assuming S (k ). S (k ): When testing fo r j < n at line (3), smal l indexes smallest
  • f
A[i::k
  • 1].
No w consider what happ ens in the lo
  • p
b
  • dy
when j = k , sp ecically in the \if " statement
  • f
lines (4) and (5). if A[k ] is less than the smallest
  • f
A[i + 1::k
  • 1]
then smal l = k . Then smal l indexes smallest
  • f
A[i + 1::k ]. If A[k ] is not less than the smallest
  • f
A[i + 1::k
  • 1]
then the value
  • f
small is unchanged. So small will no w b e the index
  • f
the smallest
  • f
A[i + 1::k ]. Thus, in either case, if the lo
  • p
test is reached subse- quently with the value
  • f
j incremented from k to k + 1, smal l indexes the smallest
  • f
A[i + 1::k ] which p roves S (k ) holds fo r all values
  • f
k
  • i
+ 1. Question: what is the truth value
  • f
S (k ) when k > n) 5
slide-6
SLIDE 6 No w consider the whole SelectionSo rt function. The follo wing assertion is made ab
  • ut
it. T (m): If w e reach the test i < n
  • 1
at line 1, with i = m, then 1. A[0::m
  • 1]
a re in non-decreasing
  • rder.
2. All
  • f
A[m::n
  • 1]
a re greater than
  • r
equal to any
  • f
A[0::m
  • 1].
Basis: m = 0. 1. A[0::
  • 1]
a re
  • bviously
in so rted
  • rder.
2. All
  • f
A[0::n
  • 1]
  • any
  • f
A[0::
  • 1]
Induction: Pro
  • f
  • f
T(m+1) assuming T(m). Consider what happ ens when i = m. W e kno w (b y the IH) that A[0::m
  • 1]
a re in so rted
  • rder
and no element
  • f
A[0::m
  • 1]
is greater than any element
  • f
A[m::n
  • 1].
w e exit the lo
  • p
  • f
lines (3){(5), the lo
  • p
va riable j w
  • uld
have the value n and so at that p
  • int
smal l will index the smallest
  • f
A[m::n
  • 1],
b y the p revious induc- tion. 6
slide-7
SLIDE 7 No w note t w
  • things
ab
  • ut
the situation: 1. By the rst condition
  • f
the IH, w e kno w that A[0::m
  • 1]
a re already in so rted
  • rder.
2. By the second condition, w e kno w that smal l is greater than
  • r
equal to any item in A[0::m
  • 1].
Thus, 1. After sw apping A[m] with A[smal l ], incrementing i to m + 1, p ro ceeding a round the lo
  • p,
just b efo re the test, w e can assert that A[0::m] is so rted which is condition 1. 2. A[smal l ] is the smallest
  • f
A[m::n
  • 1]
and that b
  • th
A[m] and all elements
  • f
A[0::m
  • 1]
a re less than
  • r
equal to any element in A[m + 1::n
  • 1]
which is condition 2. Note that when m = n, w e have exited the
  • uter
lo
  • p
and so, A[0::n
  • 1]
a re in so rted
  • rder.
7
slide-8
SLIDE 8 Pro
  • f
numb er 2: F acto rial function. (1) int factorial(int n) { (2) int i = 2; (3) int fact = 1; (4) while (i <= n) { (5) fact = fact * i; (6) i++; } (7) return fact; } First { Pro
  • f
  • f
termination: Chose E = n
  • i
+ 1. Second | Pro
  • f
  • f
co rrectness: S (k ): If w e reach the test i <= n at line (4), with the value
  • f
the lo
  • p
va riable i set to k , then fact will contain the value (k
  • 1)!
Basis: The basis is S (2). i = 2 ! f act = 1 b y assign- ment. Induction: Assume S (k ). Prove S (k + 1). 8
slide-9
SLIDE 9 Proving p rop erties
  • f
recursive functions: (1) int fact(int n) (2) if (n <= 1) (3) return 1; (4) else (5) return n * fact(n-1); W e w ant to p rove the follo wing inductive assertion
  • n
i. S (i) : If the function fact is called with the a rgument i, it returns the value i! Basis: Consider S (1). Line (2) p erfo rms a test which succeeds and so facto rial returns 1 which is indeed 1! Induction: Assume S (k ), i.e. fact(k) returns k !. No w consider what will happ en if fact() is called with a rgu- ment k + 1 with k
  • 1
The test
  • n
line (2) fails and so the else pa rt is executed. Thus the call
  • f
facto rial returns the p ro duct
  • f
(k + 1)
  • f
act(k ). Ho w ever, b y the IH, fact(k) will return the value k !. Thus the value returned b y the p resent call will b e (k + 1)
  • k
! which b y the denition
  • f
the facto rial function is (k + 1)!. QED. 9
slide-10
SLIDE 10 Recursive Selection so rt: (1) void recSS(int A[], int i, int n) { (2) if (i < n-1) { (3) small=i; (4) for (j = i; j < n; j++) (5) if (A[j] < A[small]) (6) small = j; (7) swap(&A[small], &A[i]); (8) recSS(A, i+1, n); (9) } (10) } S (k ): If the function recSS() is called with i = k , then when it returns it will leave A[k ::n
  • 1]
in non-descending
  • rder.
Basis: S (n
  • 1).
The IH is fo r S (k ) where
  • k
< n. W e must sho w that S (k
  • 1)
holds given S (k ). 10
slide-11
SLIDE 11 Merge So rt: LIST MakeList() { int x; LIST pNewCell; if (scanf(``%d'', &x) == EOF) return NULL; else { pNewCell = (LIST) malloc(sizeof(CELL)); pNewCell->next = MakeList(); pNewCell->element = x; return pNewCell; } } LIST MergeSort(LIST list) { LIST SecondList; if (!list || !list->next) return list; else { SecondList = split(list); return merge(MergeSort(list), MergeSort(SecondList)); } } 11
slide-12
SLIDE 12 LIST merge(LIST list1, LIST list2) { if (!list1) return list2; if (!list2) return list1; if (list1->element <= list2->element) { list1->next = merge(list1->next, list2); return list1; } else { list2->next = merge(list2->next, list1); return list2; } } LIST split(LIST list) { LIST pSecondCell; if (!list || !list->next) return NULL; else { pSecondCell = list->next; list->next = pSecondCell->next; pSecondCell->next = split(pSecondCell->next); return pSecondCell; } } 12
slide-13
SLIDE 13 Running Times 1. Log means log 2 in this mo dule. 2. Ab
  • ut
counting machine instructions... 3. The 90{10 rule: (Eg. Exp eriment using gp rof/gmon under Unix) 4. Why is it p
  • intless
to count the actual numb er
  • f
seconds? 5. Benchma rking Vs Analysis 6. Running time is conventionally denoted b y T (n) (no units) A selection so rt p rogram fragment: (2) small = i; (3) for (j = i+1; j < n; j++) { (4) if (A[j] < A[small]) (5) small = j; T
  • tal
time sp ent in this lo
  • p
is 4(n
  • i
  • 1)
+ 1. What is meant b y quadratic and linea r time? 13
slide-14
SLIDE 14 Big-Oh notation: T (n) is O (f (n)) if there exists some integer n > and constant c > such that 8n > n : T (n)
  • cf
(n) Example: Find the Big-oh fo r T (n) = (n + 1) 2 (Hint: 3,2
  • r
1,4) Question: Can T (n) b e considered O (n 2 =1000)? Sho w that: log n is p n etc. 1. Constant facto rs don't matter 2. Lo w
  • rder
terms don't matter Thumb rule: if lim n!1 h(n) g (n) = then O (g (n) + h(n)) = O (g (n)). The T ransitive La w: if f (n) is O (g (n)) and g (n) is O (h(n)), then f (n) is O (h(n)). Some useful p
  • ints:
1. if p and q a re p
  • lynomials
in n and deg r ee(p)
  • deg
r ee(q ) then p is O (q ) 2. if deg r ee(p) > deg r ee(q ) then p is not O (q ) 3. Every exp
  • nential
gro ws faster than any p
  • lynomial
4. No exp
  • nential
is O (p) where p is a p
  • lynomial
14
slide-15
SLIDE 15 Some common exp ressions and their names: BIG-OH INF ORMAL NAME O (1) constant O (log n) loga rithmic O (n) linea r O (n log n) n log n O (n 2 ) quadratic O (n 3 ) cubic O (2 n ) exp
  • nential
Example: What is the time complexit y
  • f
the follo wing fragment: (1) scanf(``%d'', &n); (2) for (i = 0; i < n; i++) (3) for (j = 0; j < n; j++) (4) A[i][j] = 0; (5) for (i = 0; i < n; i++) (6) A[i][i] = 1; Discuss p rogram running times fo r: 1. Primitive
  • p
erations 2. fo r/while lo
  • ps
(simple and complex) 3. if/switch statements 4. function calls (in lo
  • ps
(in init/tests/b
  • dy))
Dra wing a pa rse tree fo r a statement and nding the running time. Use as example the Selection so rt frag- ment. 15
slide-16
SLIDE 16 Analysing recursive functions: F
  • r
the facto rial function, Basis: T (1) = O (1) Induction: T (n) = O (1) + T (n
  • 1)
Let the basis tak e a units
  • f
time. And the inductive step tak e b + T (n
  • 1)
units
  • f
time. T (1) = a T (2) = a + b T (3) = a + b + b = a + 2b . . . T (n) = a + (n
  • 1)b
Solving b y rep eated substitution: W e have the sequence
  • f
equations T (n) = b + T (n
  • 1)
T (n
  • 1)
= b + T (n
  • 2)
. . . T (2) = b + T (1) 16
slide-17
SLIDE 17 Substituting rep eatedly , w e get T (n) = (n
  • 1)b
+ a Consider T(n) = b + T(n-1) to b e the rst substitution. W e w ant to p rove b y induction
  • n
the numb er
  • f
substi- tutions i (something not stated explicitly in the b
  • k):
S (i): If 1
  • i
< n, then T (n) = ib + T (n
  • i)
so that w e can assert that after (n-1) substitutions, T (n) = (n
  • 1)b
+ T (1). Basis: i = 1, W e kno w T (n) = b + T (n
  • 1)
is true from its denition. Induction: Consider i < n
  • 1.
Then, S (i) : T (n) = ib + T (n
  • i).
S (i + 1) is the (i + 1)th substitution. So substitute
  • nce
mo re in S (i), i.e. Substitute fo r T (n
  • i)
in S (i). T (n) = ib + b + T (n
  • i
  • 1)
= (i + 1)b + T (n
  • (i
+ 1)) = S (i + 1) Q.E.D. Analysis
  • f
Merge so rt: Simple to sho w that merge() tak es O (n) time
  • n
a list length n 17
slide-18
SLIDE 18 Consider split() T (0) = O (1) and T (1) = O (1). Let them b e a and b resp. T (n) = O (1) + T (n
  • 2),
i.e. T (n) = c + T (n
  • 2)
Why? T (2) = c + T (0) = a + c T (3) = c + T (1) = b + c T (4) = c + T (2) = a + 2c . . . T (n) = a + cn=2 fo r even n and T (n) = b + c(n
  • 1)=2
fo r
  • dd
n. Pro
  • f
b y induction
  • n
the numb er
  • f
substitutions: T (n) = c + T (n
  • 2)
= 2c + T (n
  • 4)
. . . S (i): If 1
  • i
< n=2, then T (n) = ic + T (n
  • 2i)
Substitute
  • nce
mo re fo r T (n
  • 2i)
to get the (i + 1)th substitution. T (n) = ic + c + T (n
  • 2i
  • 2)
= (i + 1)c + T (n
  • 2(i
+ 1)) = S (i + 1) Q:E :D : 18
slide-19
SLIDE 19 No w consider the function MergeSo rt() Easy to see that T (n) = 2T (n=2) + O (n), i.e. T (n) = 2T (n=2) + bn Let's b egin the substitutions T (1) = a T (2) = 2T (1) + 2b = 2a + 2b T (4) = 2T (2) + 4b = 4a + 8b T (8) = 2T (4) + 8b = 8a + 24b T (16) = 2T (8) + 16b = 16a + 64b . . . Generalising w e get, T (n) = an + bn log 2 n An induction
  • n
the numb er
  • f
substitutions w e need to mak e to T (n) b efo re ending up with T (1). This will
  • bviously
b e log 2 n since n is halved at each stage. (Ho w many times can w e cut a numb er to half its size b efo re ending up with a numb er <= 1?) 19
slide-20
SLIDE 20 T
  • intuit
S (i), consider the follo wing substitutions T (n) = 2T (n=2) + bn = 2(2T (n=4) + bn=2) + bn = 4T (n=4) + 2bn = 4(2T (n=8) + bn=4) + 2bn = 8T (n=8) + 3bn . . . So in general, S (i): If 1
  • i
  • log
2 n, then T (n) = 2 i T (n=2 i ) + ibn Pro
  • f:
Basis: T (n) = 2T (n=2) + bn, true from the denition. Induction: Assume S (i) : T (n) = 2 i T (n=2 i ) + ibn Consider the next substitution into S (i), T (n) = 2 i T (n=2 i ) + ibn = 2 i (2T ((n=2 i )=2) + bn=2 i ) + ibn = 2 i+1 T (n=2 i+1 ) + (i + 1)bn = S (i + 1) Q:E :D : Making log 2 n substitutions to T (n), w e end up with the base case: T (n) = an + bn log 2 n and so T (n) is O (n log n). 20
slide-21
SLIDE 21 Solving Recurrence Relations Tw
  • metho
ds: 1. Rep eated substitution 2. Guessing and p roving (Don't freak
  • ut!!)
Example
  • f
rst t yp e (Rep eated substitution) T ry T (1) = a; T (n) = T (n
  • 1)
+ g (n) W e can sho w b y rep eated substitution, i times, T (n) = T (n
  • i)
+ i1 P j =0 g (n
  • j
) T
  • get
the basis case (where no mo re subs can b e made, w e must use i = n
  • 1.
This gives: T (n) = T (1) + n2 P j =0 g (n
  • j
) F
  • r
facto rial, g (n) = O (1) = b F
  • r
recursive selection so rt, g (n) = O (n) = bn T ry to derive the complexities
  • f
the t w
  • functions.
21
slide-22
SLIDE 22 Merge so rt: T (n) = 2T (n=2) + g (n) = 4T (n=4) + 2g (n=2) + g (n) = 8T (n=8) + 4g (n=4) + 2g (n=2) + g (n) . . . = 2 i T (n=2 i ) + X j =0 i
  • 12
j g (j =2 j ) The base case when no mo re subs a re to b e made is reached after log 2 n substitutions. So, T (n) = an + log 2 n1 P j =0 2 j g (j =2 j ) F
  • r
merge so rt, g (n) = bn (recall) So, T (n) = an + log 2 n1 X j =0 bn = an + bn log 2 n is O (n log n) Q:E :D : 22
slide-23
SLIDE 23 Example
  • f
second t yp e (b y guessing) T ry to p rove the complexit y
  • f
merge so rt. Guess that T (n) is b
  • unded
b y cn log n + d No w p ro ceed along the follo wing lines. Prove the follo wing b y induction. S (n) : F
  • r
merge so rt, T (n)
  • f
(n) where f (n) = cn log n+ d where n
  • 1
is a p
  • w
er
  • f
2. Basis: S (1) is true if a
  • d
(Recall that T (1) = a and T (n) = 2T (n=2) + bn. No w assume S (i) fo r 1
  • i
< n and p rove S (n) as b elo w: W e w ant to p rove T (n)
  • cn
log n + d fo r some c; d, that is there exists some value
  • f
c and d fo r which the ab
  • ve
inequalit y is true; can w e nd them? 23
slide-24
SLIDE 24 T (n) = 2T (n=2) + bn
  • 2(c
n 2 log n 2 + d) + bn
  • cn(log
n
  • log
2) + 2d + bn
  • cn
log n
  • cn
+ 2d + bn
  • cn
log n + d + n(b
  • c)
+ d Can w e nd a b; c and d such that fo r n
  • 1,
n(b
  • c)
+ d
  • 0?
If so, the ab
  • ve
inequalit y will hold. Since n(b
  • c)
+ d
  • 0;
n(b
  • c)
  • d.
Also, since n
  • 1,
this is
  • nly
true if b
  • c
  • d.
Also, since a
  • d,
assume a = d then w e have b
  • c
  • a
  • r
a + b
  • c.
Letting c = a + b, and d = a, w e have T (n)
  • (a
+ b) log n + a Thus T (n) is O (n log n) 24
slide-25
SLIDE 25 Some common recurrences and their running times: T (n) BIG-OH T (n
  • 1)
+ bn k O (n k +1 ) cT (n
  • 1)
+ bn k ; c > 1 O (c n ) cT (n=d) + bn k ; c > d k O (n log d c ) cT (n=d) + bn k ; c < d k O (n k ) cT (n=d) + bn k ; c = d k O (n k log n) If time p ermits: T ry to guess an p rove an upp er b
  • und
fo r the follo wing recurrence: Basis: G(1) = 3 Induction: G(n) = (2 ( n 2 ) + 1)G( n 2 ) fo r n > 1. Hints: 1. First expand G(n) b y rep eated substitution to get the dominant term in the exp ression. 2. Don't fo rget the constant term (d) 25
slide-26
SLIDE 26 Combinato rics Counting assignments { Colours to houses, etc. k n r ul e (Also called selections with replacement) Example: Ho w many bits do y
  • u
need to uniquely address every b yte in a memo ry bank
  • f
100 MB? (2 n = 100
  • 1000
  • 1024).
Counting p ermutations { Q (n) Ordered selections without replacement: Q (n; m) = num- b er
  • f
w a ys w e can select m items from n such that
  • rder
matters fo r the selected items
  • nly
. ( Q (n; m) = n(n
  • 1)(n
  • 2)
  • (n
  • m
+ 1) = n! (nm)! ) Computing logs
  • f
la rge facto rials Uno rdered selections (also called combinations)
  • n
m
  • =
Q (n;m) Q (m) Example: Numb er
  • f
p
  • k
er hands (5 ca rds) 26
slide-27
SLIDE 27 Imp
  • rtant
p rop erties
  • f
  • n
m
  • fo
r < m < n;
  • n
m
  • =
  • n
  • 1
m
  • +
  • n
  • 1
m
  • 1
  • n
m
  • =
  • n
n
  • m
  • P
ascal's triangle:
  • n
m
  • =
P [n + 1][m + 1] (mth entry in the nth ro w, numb ering from 0) Computing ratios
  • f
la rge facto rials Running times
  • f
functions to compute p ermutations and combinations. (Contrast with running times
  • f
functions to list all the p ermutations and combinations, Recursive and iterative versions.) Why
  • n
m
  • must
yield an integer Shap e
  • f
the function f (m) =
  • k
m
  • 27
slide-28
SLIDE 28 Binomial co-ecients: Consider (x + y ) n fo r n = 1; 2; :::; i (x + y ) n = X m=0 n
  • n
m
  • x
m y nm Consider sp ecial cases
  • f
ab
  • ve
when y = 0; 1
  • r
x = y = 1 Multinomials: P ermutations with identical elements. Distribution
  • f
  • bjects
to bins Distributing distinguishable
  • bjects
in k classes 28
slide-29
SLIDE 29 DIJKSTRA'S SHORTEST-P A TH ALGORITHM This will b e the last lecture from me this semester fo r this course. I will, ho w ever, see y
  • u
again after the Easter b reak fo r the mid-semester test. The plan
  • f
this lecture: 1. A ttempt to nd y
  • ur
  • wn
sho rtest path algo rithm. 2. Description and discussion
  • f
Dijkstra's algo rithm 3. Pro
  • f
  • f
the algo rithm and why it w
  • rks.
4. Silent admiration and app reciation
  • f
the b eaut y , elegance and simplicit y
  • f
the algo rithm. Example graph: A ! B = 15 B ! C = 12 A ! C = 20 B ! D = 28 D ! E = 24 E ! F = 11 C ! F = 13 29
slide-30
SLIDE 30 Sta rt
  • b
y assuming that all
  • ther
no des a re at distance innit y from the source no de and gradually adjust these distances as w e go
  • n.
The sho rtest distances a re discovered from the source no de to every
  • ther
no de, in the
  • rder
  • f
nea rness, i.e. nea rest no des a re decided b efo re lo
  • king
at fa rther no des. Some denitions:
  • A
no de is called settled if the minimum distance to it from the source is kno wn.
  • The
sho rtest sp ecial path (SSP) to an unsettled no de, if it exists, is a path that travels
  • nly
through settled no des except at the last step.
  • W
e maintain a value dist(u) fo r every no de u such that if the no de gets settled, then dist(u) = length
  • f
sho rtest path to u. If u is not settled, then dist(u) = length
  • f
sho rtest sp ecial path to u. 30
slide-31
SLIDE 31 HO W TO SETTLE A NODE: Adjust the value
  • f
dist(u) fo r all no des u that remain unsettled and a re aected b y the settled no de. i.e. T
  • settle
no de v , fo r each a rc v ! u, if dist(v ) + l en(v ! u) < dist(u), then dist(u) := dist(v ) + l en(v ! u) A t the sta rt
  • f
the algo rithm, no no des a re settled and there exists a sp ecial path
  • f
length zero from the source no de to itself. A t each pass, settle
  • ne
unsettled no de with the least value
  • f
dist(u) as describ ed ab
  • ve.
The algo rithm terminates when all no des have b een set- tled. 31
slide-32
SLIDE 32 IMPORT ANT POINT: A t the b eginning
  • f
any pass
  • ver
the no des in the algo- rithm, the sho rtest
  • f
all sp ecial paths is THE sho rtest path to the no de it go es to. Note that this is not the case with the
  • ther
sp ecial paths (non-sho rtest sp ecial paths). That is why this is the no de that is settled next. T
  • see
why , let the sho rtest
  • f
all sp ecial paths go to no de v and another sp ecial path, (not the sho rtest
  • ne)
go to no de u. THERE IS A POSSIBILITY that there might b e a path from v to u, such that going to v and thence to u is sho rter than going to u directly . Ho w ever, THERE IS NO POSSIBILITY that going to u and thence to v is sho rter than going to v directly since going to u is itself longer than going to v . So there is A RISK in settling u b efo re v , but there is NO RISK in settling v b efo re u. Sp end a few minutes
  • n
this p
  • int
and understand this completely and y
  • u
will feel absolutely comfo rtable with the inductive p ro
  • f.
AL TERNA TEL Y, PONDER: Why should no des b e settled in the
  • rder
  • f
nea rness? This is in fact a critical requirement fo r the algo rithm. Consider the scena rio when there exist sp ecial paths
  • f
length 10 and 20 from the source s to t w
  • no
des u and v . What gua rantees that the algo rithm will w
  • rk:
Settling u rst
  • r
v ? 32
slide-33
SLIDE 33 PROOF BY INDUCTION: S(n): When there a re k settled no des, a F
  • r
each settled no de, u; dist(u) gives the minimum distance from s to u and the sho rtest path s ! u consists entirely
  • f
settled no des. b F
  • r
each unsettled no de u; dist(u) is the minimum distance
  • f
any sp ecial path from s ! u
  • r
1 if no such path exists. First p rove that (a) holds after the (k + 1)th no de, v is settled: Pro
  • f
is b y contradiction: Assume that dist(u) is not the sho rt- est path to v . Then there must have existed some non-sp ecial path that is sho rter than the sp ecial path since b y the Inductive Hyp
  • thesis
(b), w e kno w that when k no des w ere settled, the sho rtest sp ecial path to v is the sho rtest
  • f
all sp ecial paths to v . But w e can't have an unsettled w b e
  • n
a non-sp ecial path to v b ecause (see P
  • nder
p
  • int
ab
  • ve)
w should have b een settled b efo re v . Therefo re (a) holds. Then p rove that (b) also holds after v is settled: Consider an a rbitra ry unsettled no de u after v is settled. Either there is no sp ecial path to u
  • r
there is
  • ne.
If the fo rmer, then dist(u) = 1 is indeed the sho rtest
  • f
sp ecial paths to it b y denition. If the latter, then either v is pa rt
  • f
the sp ecial path
  • r
not. If v is pa rt
  • f
the sp ecial path, then it must b e the p enultimate no de (Why?). In this case, the l en(s ! u) = dist(v ) + l en(v ! u). If v is not pa rt
  • f
the sp ecial path, then the settling
  • f
v has no eect
  • n
the length
  • f
the path to u. Since the algo rithm sets dist(u) to the smaller
  • f
the
  • ld
value
  • f
dist(u) and dist(v ) + l eng th(v ! u), if settling v changes the sho rtest path to u then it will reset dist(u) acco rdingly . Q.E.D. 33
slide-34
SLIDE 34 COMMON POINT OF CONFUSION: Do not confuse \Sho rtest
  • f
all sp ecial paths to A NODE" with \Sho rtest
  • f
all sp ecial paths." The fo r- mer is used when w e have mo re than
  • ne
sp ecial path to a given no de (t ypically up
  • n
a settling a new no de). W e reset the dist() fo r that no de to b e the sho rtest
  • f
all sp ecial paths to it. The latter is the sho rtest
  • f
all sp ecial paths to any unsettled no de. This p
  • ints
to the next no de to b e settled. Final note: Investigate the follo wing w eb site: http://www.MapsOnUs.com T ry planning the sho rtest route from T
  • m
Bradley Intl Airp
  • rt,
LA to W all street, NY. What ab
  • ut
the fastest? Why a re they dierent? 34