Presentation is loading. Please wait.

Presentation is loading. Please wait.

 2004 SDU 1 Algorithm Informally speaking, an algorithm is a collection of simple instructions for carrying out a task. Example:  Elementary arithmetic.

Similar presentations


Presentation on theme: " 2004 SDU 1 Algorithm Informally speaking, an algorithm is a collection of simple instructions for carrying out a task. Example:  Elementary arithmetic."— Presentation transcript:

1  2004 SDU 1 Algorithm Informally speaking, an algorithm is a collection of simple instructions for carrying out a task. Example:  Elementary arithmetic algorithms for adding and multplying etc.  Algorithms for computing students’ grades.  Algortihms for classes scheduling. We need a strict mathematical definition of an algorithm. The above “definition” obviously does not qualify.

2  2004 SDU 2 Algorithms should deal with strings The structure of an algorithm: Input(s) Output or Input(s) Yes (accept) or No (reject) The attempt to formalize the notion of algorithm should start from strictly specifying what kind of objects can be inputs/outputs. These are going to be only.strings No loss of generality: non-string objects can be easily represented with strings. A tuple of such objects can also be represented with a (one single) string. After all, computers exclusively deal with strings --- strings over the alphabet {0,1} !

3  2004 SDU 3 Encoding Encoding numbers: 0,1,2,3,…,34,…, or 0,1,10,11,…,100010,… Encoding pairs of numbers: (4,2), (1,3), …, or 4#2, 1#3,…, or aaaabb, abbb, … Encoding --- representing objects as strings in some standard way. There are usually many ways to encode; as one encoding can be easily (algorithmically) converted into another, it does not matter which encoding we choose. Encoding people: “David Stewart”, “Dongfei Wei”, …, or “Stewart, David”, “Wei, Dungfei”, or 315-21-5541, 326-11-1521… If O is an object, will stand for a (the) encoding of O.

4  2004 SDU 4 1 2 3 4 Consider the graph in figure 1 Figure 1 a connected graph The encoding of a graph as a string is a list of nodes followed by a list of edges. Each node is a decimal number, and each edge is a pair of decimal numbers that represent the nodes that edge connects. Example encoding: the graph in Figure 1 is encoded by the string: = (1, 2, 3, 4) ((1, 2), (2, 3), (3, 1), (1, 4)) Encoding a graph

5  2004 SDU 5 Algorithmically solvable problems vs language recognition Thus, 1.Every problem for which we are trying to design a yes/no algorithm is of the type “Is string w in language L?”, --- the sort of problems solved by TMs. E.g., the problem of graph connectedness is the problem w  {u | u is the encoding of a graph G and G is connected}? Every problem for which we are trying to design an algorithm that produces an output is of the type “What string is the value of function f for string w?”, --- the sort of problems solved by TMOs. E.g., the problem of adding two numbers is the problem f(w)=? where f is the function defined by f( )=

6  2004 SDU 6 The Church-Turing thesis (the intuitive notion of) Algorithm = Turing machine The Church-Turing thesis: It can never been mathematically proven! Importance: Without the Church-Turing thesis, you can never prove that a certain problem has no algorithmic solution. Example - Hilbert’s 10th problem (see page 142).

7  2004 SDU 7 A turning point We continue to speak of Turing machines, but our real focus is on algorithms. Question: what is the right level of detail to give when describing a Turing machine algorithm? The three possibilities are: 1.Formal description: Spell out in full all 7 components of a Turing machine. This is the lowest, most detailed level of description. 2.Implementation description: Use English prose to describe the way Turing machine moves its head and the way it stores data on its tape. No details of state transitions are given. 3.High-level description: Use English prose to describe the algorithm, ignoring the implementation model. No need to mention how machine manages its head and tape.

8  2004 SDU 8 Encoding an object Here we set up a format and notation for describing Turing machine while approaching decidability or computability theory. Definition: An algorithm is a TM in the standard representation: 1.The input to a Turing machine is always a string ; 2.If we want an object, other than a string as input, we must first represent that object as a string. 3.If we have several objects O 1, O 2, …, O k, we denote their encoding into a string by.

9  2004 SDU 9 Description of a TM A Turing machine algorithm is described with an indented segment of text in quotes. The algorithm is broken into stages, each stage involving many individual steps of computation. The block structure of the algorithm is indicated by further indentation The first line of the algorithm describes the input which is a string w If the input is the encoding of an object such as the Turing machine first implicitly test whether the input properly encodes O and rejects if it does not. Example. A = { | G is a connected undirected graph} A TM deciding A is: M = “on input, the encoding of a graph G: 1.Select the first node of G and mark it; 2.Repeat the following stage until no new nodes are marked: 3. For each node in G, mark it if it is attached by an edge to a node that is already marked; 4.Scan all the nodes of G to determine whether they all are marked. If they are, accept; otherwise reject.”

10  2004 SDU 10 M computes on G 1 1. (1,2,3,4)((1,2),(1,3),(1,4),(2,3)) 2. (1,2,3,4)((1,2),(1,3),(1,4),(2,3)) 3. (1,2,3,4)((1,2),(1,3),(1,4),(2,3)) 4. (1,2,3,4)((1,2),(1,3),(1,4),(2,3)) 1 2 3 4

11  2004 SDU 11 M computes on G 1 1. (1,2,3,4)((1,2),(1,3),(1,4),(2,3)) 1 2. (1,2,3,4)((1,2),(1,3),(1,4),(2,3)) 1 2 3 4

12  2004 SDU 12 M computes on G 1 1. (1,2,3,4)((1,2),(1,3),(1,4),(2,3)) 1 2. (1,2,3,4)((1,2),(1,3),(1,4),(2,3)) 1 3. (1,2,3,4)((1,2),(1,3),(1,4),(2,3)) 1 2 3 4

13  2004 SDU 13 M computes on G 1 1. (1,2,3,4)((1,2),(1,3),(1,4),(2,3)) 1 2. (1,2,3,4)((1,2),(1,3),(1,4),(2,3)) 1 3. (1,2,3,4)((1,2),(1,3),(1,4),(2,3)) 1 2 3 4 1 0. (1,2,3,4)((1,2),(1,3),(1,4),(2,3)) Accept

14  2004 SDU 14 M computes on G 1 1. (1,2,3,4,5,6)((1,2),(1,3),(1,4),(2,3),(5,6)) 1 2. (1,2,3,4,5,6)((1,2),(1,3),(1,4),(2,3),(5,6)) 1 3. (1,2,3,4,5,6)((1,2),(1,3),(1,4),(2,3),(5,6)) 1 4. (1,2,3,4,5,6)((1,2),(1,3),(1,4),(2,3),(5,6)) 1 5. (1,2,3,4,5,6)((1,2),(1,3),(1,4),(2,3),(5,6)) 1 6. (1,2,3,4,5,6)((1,2),(1,3),(1,4),(2,3),(5,6)) 1 7. (1,2,3,4,5,6)((1,2),(1,3),(1,4),(2,3),(5,6)) 1 8. (1,2,3,4,5,6)((1,2),(1,3),(1,4),(2,3),(5,6)) 1 0. (1,2,3,4,5,6)((1,2),(1,3),(1,4),(2,3),(5,6)) 1 2 3 4 56 Reject


Download ppt " 2004 SDU 1 Algorithm Informally speaking, an algorithm is a collection of simple instructions for carrying out a task. Example:  Elementary arithmetic."

Similar presentations


Ads by Google