INF4130 Algoritmer: Design og effektivitet 30th August 2018 - - PowerPoint PPT Presentation
INF4130 Algoritmer: Design og effektivitet 30th August 2018 - - PowerPoint PPT Presentation
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)
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
“Given a set of numbers, sort them.” Arranging elements / Sorting numbers 4, 8, 3, 13, 1, 5, 2, 3 1, 2, 3, 3, 4, 5, 8, 13 “Given a set of positive integers, sort them in ascending
- rder.”
Given a set I of n positive integers, I = {i1, i2, … in}, sort i1, i2, … in in ascending order.
INPUT: A set I ϵ Z+of n positive integers I = {i1, i2, … in}. OUTPUT: A permutation Iꞌ of I such that iꞌj ≤ iꞌj+1, 1 ≤ j ≤ n-1. SORTING INSTANCE: A set I ϵ Z+of n positive integers I = {i1, i2, … in}. QUESTION: Is I sorted in ascending order?
Modeling
Real world
Mathematical representation
Modeling
Delivery routes / Hamiltonian cycles INPUT: A graph G=(V, E), with V = {v1, v2, … vn}, and E ={e1, e2, … em}, OUTPUT: A permutation Vꞌ of V such that vꞌi vꞌi+1 ϵ E for all 1 ≤ i ≤ n-1, and vꞌn vꞌ1 ϵ E. HAMILTONICITY INSTANCE: A graph G=(V, E). QUESTION: Is there a Hamiltonian cycle in G?
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 “Interesting”, “Natural” Problems SORTING, HAMILTONICITY, HALTING, …
graphs, numbers, logical expressions, …
Functions Sets of I/O-pairs
input
- utput
Formal Languages Sets of YES-instances (strings)
- utput = YES/NO
Example, Formal Languages
SORTING
{ϵ; 1; 2; … 1,2; 1,3; 1,4; … 1,2,3; 1,2,4; 1,2,5; … …}
HAMILTONICITY
{C3; C4; … K3; K4; … …}
Problems
Problems can be very different Problems can be modeled mathematically and represented as formal languages All formal languages are objects
- f 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 = {i1, i2, … in}. 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 StringMatcher (P [0:m -1], T [0:n -1]) i ← 0 j ← 0 CreateNext(P [0:m - 1], Next [n - 1]) while i < n do if P [ j ] = T [ i ] then if j = m – 1 then return(i – m + 1) 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 T = Long string to search for a pattern in P = pattern program HelloWorld() start: print (“Hello World !”) goto start end HelloWorld
P1: I1: P2: I2:
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 can be divided into classes depending on how effieciently (fast, running time) they can be solved.
Problems and Algorithms
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 1 b b
… …
b b 1 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 Complexity Problems
- a few central ones
String Search Matching Dynamic Programming Search Strategies (A*) Game trees (Alpha – Beta, Chess) Priority Queues