complexity of algorithms
play

Complexity of Algorithms Stefan Hetzl Laboratoire Preuves, - PowerPoint PPT Presentation

Complexity of Algorithms Stefan Hetzl Laboratoire Preuves, Programmes et Syst` emes (PPS) Universit e Paris Diderot Paris 7 7th International Tbilisi Summer School in Logic and Language Tbilisi, Georgia September 2011 1/ 33 Outline


  1. Complexity of Algorithms Stefan Hetzl Laboratoire Preuves, Programmes et Syst` emes (PPS) Universit´ e Paris Diderot – Paris 7 7th International Tbilisi Summer School in Logic and Language Tbilisi, Georgia September 2011 1/ 33

  2. Outline ◮ Algorithmic problems ◮ Sorting algorithms ◮ Assymptotic run-time of algorithms ◮ Decision problems, Turing-machines ◮ The class P ◮ Propositional Logic, non-deterministic computation, NP ◮ Reductions ◮ Some graph theory ◮ NP -completeness ◮ Circuits ◮ Cook-Levin theorem: SAT is NP -complete 2/ 33

  3. Algorithmic Problems 1. An algorithmic problem: Sorting: Input: A list x 1 , . . . , x n of natural numbers Output: A list x π (1) , . . . , x π ( n ) where π is a permutation such that x π ( i ) ≤ x π ( i +1) mathematically: a function 2. Solution: an algorithm mathematically: a program, formalised later 3/ 33

  4. Selection Sort for i = 1 → n − 1 do m ← i ; for j = i + 1 → n do if A [ j ] < A [ m ] then m ← j ; end if end for t ← A [ m ]; A [ m ] ← A [ i ]; A [ i ] ← t ; end for 4/ 33

  5. Merge Sort mergesort(l,r) if r − l > 1 then m ← ( r + l ) div 2; mergesort( l , m ); mergesort( m + 1 , r ); for i = m → l do B [ i ] ← A [ i ]; endfor for j = m + 1 → r do B [ r + m + 1 − j ] ← A [ j ]; endfor for k = l → r do if B [ i ] < B [ j ] then A [ k ] ← B [ i ]; i ← i + 1; else A [ k ] ← B [ j ]; j ← j − 1; end if end for end if 5/ 33

  6. Complexity of Algorithms ◮ Empirical run-time: average run-time Seq1 Seq2 Test1 Selection Sort 1.2ms 3.5ms 12.3ms Merge Sort 1.3ms 2.8ms 4.5ms on an Athlon Dual-Core X2 250 2x3GHz ◮ Assymptotic complexity analysis: Use of resources depending on input size ◮ Resources: time , space, energy,... ◮ Worst-case / Average-case ◮ Definition. Let f , g : N → N . We write g ∈ O( f ) if there are k , n 0 ∈ N s.t. for all n ≥ n 0 : g ( n ) < k · f ( n ). “ g is O( f )” 6/ 33

  7. Outline √ Algorithmic problems √ Sorting algorithms √ Assymptotic run-time of algorithms ◮ Decision problems, Turing-machines ◮ The class P ◮ Propositional Logic, non-deterministic computation, NP ◮ Reductions ◮ Some graph theory ◮ NP -completeness ◮ Circuits ◮ Cook-Levin theorem: SAT is NP -complete 7/ 33

  8. Computation, more formally ◮ Formal algorithms ⇒ a machine model ◮ Fix alphabet to 0 , 1. ◮ Encoding ◮ Fix possible results to “yes” and “no”. ◮ Definition. A set L ∈ { 0 , 1 } ∗ is called language . Its decision problem is: Input: x ∈ { 0 , 1 } ∗ Output: “yes” if x ∈ L and “no” otherwise ◮ PALINDROME : Input: ( x 1 , . . . , x n ) = x ∈ { 0 , 1 } ∗ Output: “yes” if ( x 1 , . . . , x n ) = ( x n , . . . , x 1 ), “no” otherwise 8/ 33

  9. Turing Machines (1/2) ◮ A Turing machine works on a tape using a cursor ◮ Symbols 0, 1, blank and first ⊲ ◮ Initial configuration for input x = ( x 1 , . . . , x n ) ∈ { 0 , 1 } ∗ ⊲ x 1 x 2 · · · x n . . . ↑ ◮ Definition. A Turing machine is a tuple M = ( K , s , δ ) where ◮ K is a finite set of states ◮ s ∈ K is the initial state ◮ δ is the transition function δ : K ×{ 0 , 1 , , ⊲ } − → ( K ∪{ yes , no } ) ×{ 0 , 1 , , ⊲ }×{← , → , −} 9/ 33

  10. Turing Machines (2/2) ◮ Definition. A configuration is a tuple ( q , u , v ) where ◮ q is a state ◮ u is the tape left of and including the cursor ◮ v is the tape right of the cursor The initial configuration for x ∈ { 0 , 1 } ∗ is ( s , ⊲, x ). ◮ Definition. ( q , u , v ) → M 1 ( q ′ , u ′ , v ′ ) if the configuration ( q , u , v ) yields the configuration ( q ′ , u ′ , v ′ ) in one step. → M is the transitive closure of → M 1 ◮ Definition. L language, M machine. M decides L if for all x ∈ { 0 , 1 } ∗ : ◮ x ∈ L implies that ( s , ⊲, x ) → M (yes , u , v ) for some u , v , and ∈ L implies that ( s , ⊲, x ) → M (no , u , v ) for some u , v . ◮ x / ◮ Definition. M decides L in time f ( n ) if M halts after at most f ( n ) steps for all x ∈ { 0 , 1 } n . 10/ 33

  11. � � � � � � � � � � � � A Turing Machine for Palindromes 0 : (0 , → ) , 1 : (1 , → ) ���� ���� � ���� ���� : ( , ← ) q 0 q ′ 0 � � � ���������������� � � � � � � � � � 0 : ( ⊲, → ) ⊲ : ( ⊲, → ) 0 : ( , ← ) � � � � � �� �� � � 1 : (1 , − ) � � � � � � � � � ⊲ : ( ⊲, → ) ���� ���� ���� ���� ���� ���� ���� ���� ���� ���� � � � � � � : ( , − ) � yes q s no � � ���������������� � � � � � � � � � � ⊲ : ( ⊲, → ) 0 : (0 , ← ) , 1 : (1 , ← ) ⊲ : ( ⊲, → ) � � � � � 0 : (0 , − ) � � � � � 1 : ( ⊲, → ) 1 : ( , ← ) � � � � ���� ���� � ���� ���� � � � � � � : ( , ← ) � q 1 q ′ 0 : (0 , → ) , 1 : (1 , → ) 1 ⊲ 0 1 0 . . . ↑ 11/ 33

  12. � � � � � � � � � � � � A Turing Machine for Palindromes 0 : (0 , → ) , 1 : (1 , → ) ���� ���� � ���� ���� : ( , ← ) q 0 q ′ 0 � � � ���������������� � � � � � � � � � 0 : ( ⊲, → ) ⊲ : ( ⊲, → ) 0 : ( , ← ) � � � � � �� �� � � 1 : (1 , − ) � � � � � � � � � ⊲ : ( ⊲, → ) ���� ���� ���� ���� ���� ���� ���� ���� ���� ���� � � � � � � : ( , − ) � yes q s no � � ���������������� � � � � � � � � � � ⊲ : ( ⊲, → ) 0 : (0 , ← ) , 1 : (1 , ← ) ⊲ : ( ⊲, → ) � � � � � 0 : (0 , − ) � � � � � 1 : ( ⊲, → ) 1 : ( , ← ) � � � � ���� ���� � ���� ���� � � � � � � : ( , ← ) � q 1 q ′ 0 : (0 , → ) , 1 : (1 , → ) 1 ⊲ 0 1 0 . . . ↑ 11/ 33

  13. � � � � � � � � � � � � A Turing Machine for Palindromes 0 : (0 , → ) , 1 : (1 , → ) ���� ���� ���� ���� � ���� ���� : ( , ← ) q 0 q ′ 0 � � � ���������������� � � � � � � � � � 0 : ( ⊲, → ) ⊲ : ( ⊲, → ) 0 : ( , ← ) � � � � � �� �� � � 1 : (1 , − ) � � � � � � � � � ⊲ : ( ⊲, → ) ���� ���� ���� ���� ���� ���� ���� ���� � � � � � � : ( , − ) � yes q s no � � ���������������� � � � � � � � � � � ⊲ : ( ⊲, → ) 0 : (0 , ← ) , 1 : (1 , ← ) ⊲ : ( ⊲, → ) � � � � � 0 : (0 , − ) � � � � � 1 : ( ⊲, → ) 1 : ( , ← ) � � � � ���� ���� � ���� ���� � � � � � � : ( , ← ) � q 1 q ′ 0 : (0 , → ) , 1 : (1 , → ) 1 ⊲ ⊲ 1 0 . . . ↑ 11/ 33

  14. � � � � � � � � � � � � A Turing Machine for Palindromes 0 : (0 , → ) , 1 : (1 , → ) ���� ���� ���� ���� � ���� ���� : ( , ← ) q 0 q ′ 0 � � � ���������������� � � � � � � � � � 0 : ( ⊲, → ) ⊲ : ( ⊲, → ) 0 : ( , ← ) � � � � � �� �� � � 1 : (1 , − ) � � � � � � � � � ⊲ : ( ⊲, → ) ���� ���� ���� ���� ���� ���� ���� ���� � � � � � � : ( , − ) � yes q s no � � ���������������� � � � � � � � � � � ⊲ : ( ⊲, → ) 0 : (0 , ← ) , 1 : (1 , ← ) ⊲ : ( ⊲, → ) � � � � � 0 : (0 , − ) � � � � � 1 : ( ⊲, → ) 1 : ( , ← ) � � � � ���� ���� � ���� ���� � � � � � � : ( , ← ) � q 1 q ′ 0 : (0 , → ) , 1 : (1 , → ) 1 ⊲ ⊲ 1 0 . . . ↑ 11/ 33

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