problems solu ons algorithms
play

Problems, solu=ons, algorithms CS420 lecture one In this - PDF document

5/25/10 Problems, solu=ons, algorithms CS420 lecture one In this course we study ques=ons such as: Problems, algorithms, given a problem, how do


  1. 5/25/10 ¡ Problems, ¡solu=ons, ¡algorithms ¡ CS420 ¡lecture ¡one ¡ • In ¡this ¡course ¡we ¡study ¡ques=ons ¡such ¡as: ¡ Problems, ¡algorithms, ¡ ¡ – given ¡a ¡problem, ¡how ¡do ¡we ¡find ¡an ¡(efficient) ¡ decidability, ¡tractability ¡ algorithm ¡solving ¡it? ¡ – How ¡do ¡we ¡measure ¡the ¡ complexity ¡(=me, ¡space ¡ requirements) ¡of ¡an ¡algorithm. ¡ • Problem : ¡set ¡of ¡instances ¡of ¡a ¡ques=on ¡ – is ¡2 ¡a ¡prime?, ¡.., ¡is ¡4 ¡a ¡prime?, ¡is ¡2 100000 ¡ ¡a ¡prime ¡ • Solu0on : ¡set ¡of ¡answers ¡ – yes, ¡.., ¡no, ¡no ¡ ¡ Algorithm ¡ Is ¡there ¡an ¡algorithm ¡for ¡each ¡problem? ¡ • Problem: ¡ques=on ¡+ ¡input(s) ¡ No ¡ • Algorithm: ¡ effec0ve ¡ procedure ¡ 1. the ¡problem ¡needs ¡to ¡be ¡ effec0vely ¡specified ¡ ¡ – ¡mapping ¡input ¡to ¡output ¡ "how ¡many ¡angels ¡can ¡dance ¡on ¡the ¡head ¡of ¡a ¡ • effec=ve: ¡unambiguous, ¡executable ¡ pin?" ¡ ¡not ¡effec=ve ¡ – Turing ¡defined ¡it ¡as: ¡"like ¡a ¡Turing ¡machine" ¡ 2. even ¡if ¡ it ¡is ¡effec=vely ¡specified, ¡there ¡is ¡not ¡ always ¡an ¡algorithm ¡to ¡provide ¡an ¡answer ¡ – program ¡= ¡effec=ve ¡procedure ¡ • the ¡ size ¡of ¡the ¡problem: ¡an ¡integer ¡n, ¡ • # ¡inputs ¡ ¡(for ¡sor=ng ¡problem) ¡ • #digits ¡of ¡input ¡(for ¡prime ¡problem) ¡ • some=mes ¡more ¡than ¡one ¡integer ¡ 1 ¡

  2. 5/25/10 ¡ Ulam's ¡problem ¡ Ulam's ¡problem ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡f(n): ¡ ¡ ¡if ¡(n==1) ¡return ¡1 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡f(n): ¡ ¡ ¡if ¡(n==1) ¡return ¡1 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡else ¡if ¡(odd(n)) ¡return ¡f(3*n+1) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡else ¡if ¡(odd(n)) ¡return ¡f(3*n+1) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡else ¡return ¡f(n/2) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡else ¡return ¡f(n/2) ¡ ¡ ¡ ¡ ¡ f(1) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡f(2), ¡ ¡f(4), ¡ ¡f(8), ¡ ¡f(2 n ) ¡.... ¡ Try ¡a ¡few ¡inputs, ¡does ¡f(n) ¡ always ¡stop? ¡ ¡ ¡ ¡ ¡ ¡f(3) ¡ ¡ ¡ ¡ ¡ ¡ ¡f(5) ¡ ¡ ¡ ¡ ¡ ¡f(7) ¡ ¡ ¡ ¡ ¡ ¡f(9) ¡ Ulam's ¡problem ¡ Hal=ng ¡problem ¡is ¡undecidable ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ f(n): ¡ ¡ ¡if ¡(n==1) ¡return ¡1 ¡ • Given ¡a ¡program ¡P ¡an ¡an ¡input ¡x ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡else ¡if ¡(odd(n)) ¡return ¡f(3*n+1) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡will ¡P(x) ¡stop? ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡else ¡return ¡f(n/2) ¡ we ¡can ¡prove: ¡ ¡ -­‑Nobody ¡has ¡ever ¡found ¡an ¡n ¡for ¡which ¡f ¡does ¡not ¡stop ¡ ¡ ¡the ¡hal0ng ¡problem ¡cannot ¡be ¡solved ¡ -­‑Nobody ¡has ¡ever ¡found ¡a ¡proof: ¡ ∀ n : f ( n ) stops ie ¡there ¡is ¡no ¡algorithm ¡Halt(P,x) ¡that ¡for ¡any ¡ ¡ ¡ ¡(so ¡there ¡can ¡be ¡no ¡algorithm ¡deciding ¡this.) ¡ ¡ program ¡P ¡and ¡input ¡x ¡decides ¡whether ¡P(x) ¡ ¡ stops. ¡ 2 ¡

  3. 5/25/10 ¡ Undecidability ¡ Hal=ng ¡problem ¡is ¡undecidable ¡ Assume ¡there ¡is ¡a ¡program ¡P(P1,D) ¡that ¡ ¡ ¡ ¡ ¡ ¡for ¡any ¡P1 ¡and ¡D, ¡outputs ¡ ¡ ¡ ¡ ¡ Yes ¡(if ¡P1(D) ¡halts) ¡ ¡or ¡ No ¡(if ¡P1(D) ¡loops) ¡ ¡ A ¡problem ¡P(x) ¡is ¡undecidable, ¡if ¡there ¡is ¡no ¡ Then ¡construct ¡ algorithm ¡solving ¡P ¡for ¡any ¡legal ¡x ¡ ¡ ¡ ¡ ¡ ¡ ¡Q ' (P2): ¡ ¡if ¡(P(P2,P2)) ¡loop ¡else ¡halt ¡ ¡ Now ¡execute ¡Q ' (Q ' ) ¡ ¡ ¡ ¡ ¡ ¡ ¡if ¡P(Q ' , ¡Q ' ) ¡says ¡ ¡Q ' (Q ' ) ¡halts ¡it ¡loops ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡if ¡P(Q ' , ¡Q ' ) ¡says ¡ ¡Q ' (Q ' ) ¡loops ¡it ¡halts ¡ CONTRADICTION ¡ ¡-­‑> ¡P ¡does ¡not ¡exist!! ¡ Intractability ¡ Verifica=on/equivalence ¡undecidable ¡ ¡ • Given ¡any ¡specifica=on ¡S ¡and ¡any ¡program ¡P, ¡ • Suppose ¡we ¡have ¡a ¡program, ¡ ¡ there ¡is ¡no ¡algorithm ¡that ¡decides ¡whether ¡P ¡ – does ¡it ¡execute ¡a ¡in ¡a ¡reasonable ¡=me? ¡ ¡ ¡ executes ¡according ¡to ¡S ¡ – Eg, ¡towers ¡of ¡Hanoi. ¡ ¡ • Given ¡any ¡two ¡programs ¡P1 ¡and ¡P2, ¡there ¡is ¡no ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Three ¡pegs, ¡one ¡with ¡n ¡smaller ¡and ¡smaller ¡disks, ¡move ¡(1 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡disk ¡at ¡the ¡=me) ¡to ¡another ¡peg ¡without ¡ever ¡placing ¡a ¡ ¡ algorithm ¡that ¡decides ¡ ¡ ¡ ¡ ¡ ¡ ¡x: ¡P1(x)=P2(x) ¡ ∀ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡larger ¡disk ¡on ¡a ¡smaller ¡ ¡ ¡ ¡ ¡f(n) ¡= ¡# ¡moves ¡for ¡tower ¡of ¡size ¡n ¡ • Does ¡this ¡mean ¡we ¡should ¡not ¡build ¡program ¡ ¡ ¡ ¡ ¡Monk: ¡before ¡a ¡tower ¡of ¡Hanoi ¡of ¡size ¡100 ¡is ¡ verifiers? ¡ moved, ¡the ¡world ¡will ¡have ¡vanished ¡ ¡ ¡ ¡ ¡ 3 ¡

  4. 5/25/10 ¡ ¡ Example: ¡Tower ¡of ¡Hanoi, ¡move ¡all ¡disks ¡to ¡third ¡peg ¡without ¡ever ¡ ¡ Example: ¡Tower ¡of ¡Hanoi, ¡move ¡all ¡disks ¡to ¡third ¡peg ¡without ¡ever ¡ placing ¡a ¡larger ¡disk ¡on ¡a ¡smaller ¡one. ¡ placing ¡a ¡larger ¡disk ¡on ¡a ¡smaller ¡one. ¡ 13 ¡ 14 ¡ Recursive ¡Algorithms ¡ ¡ Example: ¡Tower ¡of ¡Hanoi, ¡move ¡all ¡disks ¡to ¡third ¡peg ¡without ¡ever ¡ ¡ Example: ¡Tower ¡of ¡Hanoi, ¡move ¡all ¡disks ¡to ¡third ¡peg ¡without ¡ever ¡ placing ¡a ¡larger ¡disk ¡on ¡a ¡smaller ¡one. ¡ placing ¡a ¡larger ¡disk ¡on ¡a ¡smaller ¡one. ¡ ¡ ¡ ¡ ¡f(n) ¡= ¡f(n-­‑1) ¡+ ¡… ¡ ¡ ¡ ¡ ¡ ¡ ¡f(n) ¡= ¡f(n-­‑1) ¡+ ¡1 ¡+ ¡… ¡ 15 ¡ 16 ¡ 4 ¡

  5. 5/25/10 ¡ f(n): ¡#moves ¡ ¡ Example: ¡Tower ¡of ¡Hanoi, ¡move ¡all ¡disks ¡to ¡third ¡peg ¡without ¡ever ¡ • f(n) ¡= ¡2f(n-­‑1) ¡+ ¡1, ¡f(1)=1 ¡ placing ¡a ¡larger ¡disk ¡on ¡a ¡smaller ¡one. ¡ • f(1) ¡= ¡1, ¡ ¡f(2) ¡= ¡3, ¡ ¡f(3) ¡= ¡7, ¡f(4) ¡= ¡15 ¡ • f(n) ¡= ¡2 n -­‑1 ¡ ¡ ¡ ¡ ¡How ¡can ¡you ¡show ¡that? ¡ ¡ ¡ ¡ ¡f(n) ¡= ¡f(n ¡-­‑ ¡1) ¡+ ¡1 ¡+ ¡f(n ¡-­‑ ¡1) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡f(n) ¡= ¡2f(n ¡-­‑ ¡1) ¡+ ¡1, ¡ ¡ ¡ ¡ ¡f(1) ¡= ¡ ¡1 ¡ • Can ¡you ¡write ¡an ¡itera=ve ¡Hanoi ¡algorithm? ¡ 17 ¡ Was ¡the ¡monk ¡right? ¡ Was ¡the ¡monk ¡right? ¡ • 2 100 ¡moves, ¡say ¡1 ¡per ¡second..... ¡ • 2 100 ¡moves, ¡say ¡1 ¡per ¡second..... ¡ ¡ ¡ ¡ ¡How ¡many ¡years??? ¡ ¡ ¡ ¡ ¡2 100 ¡ ¡~ ¡10 30 ¡ ¡ ¡~ ¡10 25 ¡days ¡~ ¡3.10 22 ¡years ¡ ¡ ¡ ¡ ¡more ¡than ¡the ¡age ¡of ¡the ¡universe ¡ 5 ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend