1 / 14

Algorithm

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.

hetal
Download Presentation

Algorithm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. 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. Encoding 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 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 people:“David Stewart”, “Dongfei Wei”, …, or “Stewart, David”, “Wei, Dungfei”, or 315-21-5541, 326-11-1521… If O is an object, <O> will stand for a (the) encoding of O.

  4. Encoding a graph • Consider the graph in figure 1 4 • The encoding <G> 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: • <G> = (1, 2, 3, 4) ((1, 2), (2, 3), (3, 1), (1, 4)) 1 2 3 Figure 1 a connected graph

  5. Algorithmically solvable problems vs language recognition • Thus, • 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(<a,b>)=<a+b>

  6. The Church-Turing thesis The Church-Turing thesis: (the intuitive notion of) Algorithm = Turing machine 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. 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: • Formal description: Spell out in full all 7 components of a Turing machine. This is the lowest, most detailed level of description. • 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. • 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. 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: • The input to a Turing machine is always a string ; • If we want an object, other than a string as input, we must first represent that object as a string. • If we have several objects O1, O2, …, Ok, we denote their encoding into a string by <O1, O2, …, Ok>.

  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 <O> the Turing machine first implicitly test whether the input properly encodes O and rejects if it does not. • Example . A = {<G> | G is a connected undirected graph} • A TM deciding A is: • M = “on input <G>, the encoding of a graph G: • Select the first node of G and mark it; • Repeat the following stage until no new nodes are marked: • For each node in G, mark it if it is attached by an edge to a node that is already marked; • Scan all the nodes of G to determine whether they all are marked. If they are, accept; otherwise reject.”

  10. M computes on G 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)) 4 1 2 3

  11. M computes on G 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)) 4 1 2 3

  12. M computes on G 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

  13. M computes on G 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 0. (1,2,3,4)((1,2),(1,3),(1,4),(2,3)) 2 3 Accept

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

More Related