INF4130 – Algoritmer: Design og effektivitet 30th August 2018 Petter Kristiansen
Praktisk info • Gruppeundervisning Gruppe 1: tirsdag 12:15-14:00 Gruppe 2: torsdag 12:15-14:00, siste gang 4/10 • Obliger (ca datoer, ikke fastlagt) Oblig 1: tidlig i oktober Oblig 2: sist i oktober Oblig 3: sent i november • Eksamen 18. desember kl. 09:00 (4 timer)
What is This Course Really All About? Problems Algorithms
Problems
Modeling Arranging elements / Sorting numbers 4, 8, 3, 13, 1, 5, 2, 3 1, 2, 3, 3, 4, 5, 8, 13 “Given a set of numbers, sort them.” “Given a set of positive integers, sort them in ascending Given a set I of n positive integers, I = { i 1 , i 2 , … i n }, INPUT: A set I ϵ Z + of n positive integers I = { i 1 , i 2 , … i n }. SORTING OUTPUT: A permutation I ꞌ of I such that i ꞌ j ≤ i ꞌ j +1 , 1 ≤ j ≤ n-1. order.” sort i 1 , i 2 , … i n in ascending order . INSTANCE: A set I ϵ Z + of n positive integers I = { i 1 , i 2 , … i n }. QUESTION: Is I sorted in ascending order?
Modeling Mathematical Real world representation
Modeling Delivery routes / Hamiltonian cycles INPUT: A graph G =( V , E ), with V = { v 1 , v 2 , … v n }, and HAMILTONICITY INSTANCE: A graph G =( V , E ). E ={ e 1 , e 2 , … e m }, OUTPUT: A permutation V ꞌ of V such that v ꞌ i v ꞌ i +1 ϵ E for QUESTION: Is there a Hamiltonian cycle in G ? all 1 ≤ i ≤ n-1 , and v ꞌ n v ꞌ 1 ϵ E .
Modeling Software verification / The halting problem HALTING INSTANCE: A computer program P , and input to the program I . QUESTION: Does program P halt when run on input I ?
Problems, Formal Languages Computer Science Problems graphs, numbers, logical expressions, … SORTING, HAMILTONICITY, “Interesting”, “Natural” Problems HALTING, … input output Functions Sets of I/O-pairs output = YES/NO Formal Languages Sets of YES-instances (strings)
Example, Formal Languages SORTING HAMILTONICITY { ϵ ; { C 3 ; C 4 ; … 1; 2; … K 3 ; K 4 ; … 1,2; 1,3; 1,4; … …} 1,2,3; 1,2,4; 1,2,5; … …}
Problems Problems can be very different Problems can be modeled mathematically and represented as formal languages All formal languages are objects of the same type – A common theory and common methods become possible Set of all Problems (Formal languages)
Exercise: Describe Algorithms Sorting integers INPUT: A set I ϵ Z + of n positive integers I = { i 1 , i 2 , … i n }. OUTPUT: A permutation I ꞌ of I such that i ꞌ j ≤ i ꞌ j +1 , 1 ≤ j ≤ n-1. INPUT: {4, 8, 3, 13, 1, 5, 2, 3}
Exercise: Describe Algorithms HAMILTONICITY INSTANCE: A graph G =( V , E ). QUESTION: Is there a Hamiltonian cycle in G ? INSTANCE1: INSTANCE2:
Exercise: Describe Algorithms HALTING INSTANCE: A computer program P , and input to the program I. QUESTION: Does program P halt when run on input I ? program HelloWorld() program StringMatcher ( P [0: m -1], T [0: n -1]) P1: P2: start: i ← 0 print (“Hello World !”) j ← 0 goto start CreateNext ( P [0: m - 1], Next [ n - 1]) end HelloWorld while i < n do if P [ j ] = T [ i ] then if j = m – 1 then return ( i – m + 1) I1: endif i ← i + 1 j ← j + 1 else j ← Next [ j ] if j = 0 then if T [ i ] ≠ P [0] then i ← i + 1 endif endif endif endwhile return (-1) end StringMatcher I2: T = Long string to search for a pattern in P = pattern
Problems and Algorithms SORTING, HAMILTONICITY and HALTING are very different problems. • We found (knew?) a fast algorithm for SORTING. • We came up with a naive algorithm for HAMILTONICITY. • We really didn’t get anywhere whith HALTING.
Problems and Algorithms Problems can be divided into classes depending on how effieciently (fast, running time) they can be solved. Problems
Undecidability 1900s: Metamathematics (Mathematical studies of mathematics itself, its possibilities and limitations ) 1930s: Results on the existence and non-existence of algorithms for certain problems – Kurt Gödel (1931): Incompleteness results. – Alan Turing (1936): « On computable numbers, with an application to the Entscheidungsproblem ». Turing’s results and techniques
Complexity John von Neumann (ca 1945): modern computer Jack Edmonds (1965): Paths, Trees, and Flowers Cook / Levin (1972): NP-completeness Cook / Levin’s results and techniques
Algorithms and Turing Machines b b 0 b 1 1 0 0 b b b b … … … … http://aturingmachine.com/
Church’s Thesis Algorithm ≈ Turing machine Turing machines can calculate any function that can be calculated by an algorithm, a computer program or a computer. Expressive power of programming languages A programming language (Java, C, Lisp, …) is Turing complete if it can do the same calculations as a Turing machine. If we can implement a Turing machine with our programming language, it is Turing complete. Universal computer models A computer model is Turing complete if it can do the same calculations as a Turing machine. McCulloch and Pitts have shown that neural nets can simulate Turing machines. Uncomputability If a function f can not be computed by a Turing machine, then no computer can compute f.
Course Topics Undecidability Dynamic Programming Search Strategies (A*) Complexity Game trees (Alpha – Beta, Chess) String Search Priority Queues Matching Problems - a few central ones
Recommend
More recommend