Iductio Iductio is vey useul poo techique Iductio d Recusio CSC-59 Discete Stuctues I compute sciece, iductio is used to pove popeties o lgoithms Iductio d ecusio e closely elted Recusio is desciptio method o lgoithms Iductio is poo method suitble o ecusive lgoithms Kostti Busch - LSU Kostti Busch - LSU Use iductio to pove tht popositio P() is tue: Iductive Bsis: Pove tht P() is tue Iductive ypothesis: Assume P() is tue (o y positive itege ) Iductive Step: Pove tht P( ) is tue Iductive ypothesis: Assume P() is tue (o y positive itege ) Iductive Step: Pove tht P( ) is tue I othe wods i iductive step we pove: P( ) P( ) o evey positive itege Kostti Busch - LSU Kostti Busch - LSU
Iductive bsis P() Tue Iductive Step P( ) P( ) Tue Iductio s ule o ieece: [ P() ( P( ) P( ))] P( ) Popositio tue o ll positive iteges P( ) P() P() P() Kostti Busch - LSU 5 Kostti Busch - LSU 6 Theoem: P( ) : ( ) Poo: Iductive Bsis: P() : ( ) Iductive ypothesis: ssume tht it holds P( ) : ( ) Iductive Step: We will pove P( ) : ( )(( ) ) ( ) K. Busch - LSU 7 Iductive Step: P( ) : ( ) ( ) ( ) ( ) ( ) ( )(( ) ) (iductive hypothesis) Ed o Poo Kostti Busch - LSU 8
Kostti Busch - LSU 9 moic umbes j j 5 Exmple:,,, j Kostti Busch - LSU Theoem: Poo: Iductive Bsis: Kostti Busch - LSU Iductive ypothesis: Suppose it holds: Iductive Step: We will show: Kostti Busch - LSU Ed o Poo om iductive hypothesis
Theoem: Iductive ypothesis: Poo: Suppose it holds: Iductive Bsis: Iductive Step: We will show: ( ) Kostti Busch - LSU Kostti Busch - LSU om iductive hypothesis ( ) Ed o Poo Kostti Busch - LSU 5 We hve show: log It holds tht: log log (log ) Kostti Busch - LSU 6 log
Tiomios Theoem: Evey, checebod with oe sque emoved c be tiled with tiomioes Poo: Iductive Bsis: hole hole hole Kostti Busch - LSU 7 hole Kostti Busch - LSU 8 Iductive ypothesis: Assume tht checebod c be tiled with the hole ywhee Iductive Step: ole c be ywhee Kostti Busch - LSU 9 Kostti Busch - LSU 5
By iductive hypothesis with hole c be tiled sques x cse: dd thee tiicil holes Kostti Busch - LSU Kostti Busch - LSU x cse: Replce the thee holes with tiomio Now, the whole e c be tiled Kostti Busch - LSU Ed o Poo Kostti Busch - LSU 6
Iductive Bsis: Stog Iductio Iductive ypothesis: Assume P() To pove : Iductive Step: Pove tht Pove tht P() P( ) P() P( ) P( ) is tue is tue is tue Kostti Busch - LSU 5 Theoem: Evey itege is poduct o pimes (t lest oe pime i the poduct) Poo: Iductive Bsis: Numbe is pime Iductive ypothesis: Suppose tht evey itege betwee d is poduct o pimes (Stog Iductio) Kostti Busch - LSU 6 Iductive Step: b, b I is pime the the poo is iished By the iductive hypothesis: I is ot pime the it is composite: b, b i, j p p b q q pimes p i q j b p p q pimes i q j Ed o Poo Kostti Busch - LSU 7 Kostti Busch - LSU 8 7
Theoem: Evey postge mout c be geeted by usig -cet d 5-cet stmps Poo: (Stog Iductio) Iductive Bsis: 5 We exmie ou cses (becuse o the iductive step) 5 5 5 5 5 5 Iductive ypothesis: Assume tht evey postge mout betwee d c be geeted by usig -cet d 5-cet stmps Iductive Step: b 5 I the the iductive step ollows diectly om iductive bsis Kostti Busch - LSU 9 Kostti Busch - LSU Coside: 5 ( ) ( ) Iductive hypothesis ( ) b5 ( ) ( ) b5 Ed o Poo Kostti Busch - LSU Recusio Recusio is used to descibe uctios, sets, lgoithms Exmple: Fctoil uctio ( )! Recusive Bsis: ( ) Recusive Step: ( ) ( ) ( ) Kostti Busch - LSU 8
Recusive lgoithm o ctoil ctoil( ) { i the //ecusive bsis etu else //ecusive step etu ctoil(-) Recusive Bsis: Recusive Step: Fibocci umbes,,,,,,,, Kostti Busch - LSU Kostti Busch - LSU 7 5 5 6 5 5 8 8 5 6 5 Recusive lgoithm o Fibocci uctio ibocci( ) { i {, the //ecusive bsis etu else //ecusive step etu ibocci( -) ibocci( -) Kostti Busch - LSU 5 Kostti Busch - LSU 6 9
Itetive lgoithm o Fibocci uctio ibocci( ) { i the else { x y o to do { etu y i z x y x y y z y Kostti Busch - LSU 7 Theoem: o 5 Poo: Poo by (stog) iductio Iductive Bsis: (golde tio) Kostti Busch - LSU 8 Iductive ypothesis: is the solutio to equtio x x Suppose it holds Iductive Step: ( ) We will pove ( ) o Kostti Busch - LSU 9 iductio hypothesis Ed o Poo Kostti Busch - LSU
Getest commo diviso Recusive lgoithm o getest commo diviso Recusive Bsis: gcd(,) Recusive Step: gcd(, b) gcd( b, mod b) b gcd(,b ) { //ssume >b i the //ecusive bsis etu else //ecusive step etu gcd(b, mod b) b Kostti Busch - LSU Kostti Busch - LSU Lmes Theoem: The Euclidi lgoithm o gcd(, b), b uses t most 5log b divisios (itetios) Poo: We show tht thee is Fibocci eltio i the divisios o the lgoithm divisios / / / / gcd( b q q q q ist zeo emide, ) gcd(, ) gcd(,) esult gcd(, b) gcd(, ) gcd(, ) gcd(, ) Kostti Busch - LSU Kostti Busch - LSU
Kostti Busch - LSU 5 q q q q This holds sice d is itege q Kostti Busch - LSU 6 5 This holds sice ), gcd( b Kostti Busch - LSU 7 b 5 b log ) ( log b log 5 log log b b b 5log Ed o Poo Kostti Busch - LSU 8 Algoithm Megesot 8 6 9 7 5 8 6 9 7 5 6 8 9 5 7 5 6 7 8 9 split sot sot mege
Iput vlues o ecusive clls sot(,,, ) { i the { A sot(,,, m) B sot( m, m,, ) etu mege( A, B) else etu m / Kostti Busch - LSU 9 8 6 9 7 5 8 6 9 7 5 8 6 9 7 5 8 6 9 8 7 7 5 Kostti Busch - LSU 5 Iput d output vlues o megig 5 6 7 8 9 6 8 9 5 7 8 6 9 7 5 8 6 9 8 7 7 5 Kostti Busch - LSU 5 mege( ) { //two soted lists L while A d B do { Remove smlle ist elemet o om its list d iset it to i A o B the { pped emiig elemets to L etu L A, B A, B Kostti Busch - LSU 5 L
A 8 8 8 8 megig B 6 9 6 9 6 9 9 9 6 8 9 8 6 9 L Compiso <6 <6 6 6<8 6 8 8<9 6 8 9 The totl umbe o compisos to mege two lists is t most: A, B Meged size # compisos A B Legth o A Legth o B Kostti Busch - LSU 5 Kostti Busch - LSU 5,,, Recusive ivoctio tee,,,,,,,,,,,,,,,,,,,,,, Recusive ivoctio tee / / / / / Elemets pe list / / / log log log log (log ) log (log ) log log Assume Kostti Busch - LSU 55 Assume #levels o tee = log Kostti Busch - LSU 56
,,,,,, megig tee,,,,,,,,,,,,,,,,,,, megig tee / / / / / / Elemets pe list / / Kostti Busch - LSU 57 Kostti Busch - LSU 58 megig tee / / / / / Totl cost: (# levels -) log Compisos pe level / / / / / Elemets pe mege Meges pe level Kostti Busch - LSU 59 I the umbe o compisos is t most log I the umbe o compisos is t most mlog m O( log ) m log Time complexity o mege sot: O( log ) Kostti Busch - LSU 6 5