Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Definition of Algorithm

Similar presentations


Presentation on theme: "The Definition of Algorithm"— Presentation transcript:

1 The Definition of Algorithm
Lecture 29 Section 3.3 Mon, Oct 29, 2007

2 The Definition of Algorithm
An algorithm is a Turing machine that always halts. In other words, an algorithm is a Turing machine that decides a language.

3 Algorithms and Problems
We think of algorithms as procedures used to solve problems. How does a Turing machine that decides a language solve a problem?

4 Algorithms and Problems
The key is to represent a problem as a string in a language.

5 The Primality Problem Suppose the problem is to determine whether a given integer is prime. Then the “problem” is encoded as the integer n, written on the input tape. The algorithm would be to test every integer from 2 to n – 1 to see whether it is a divisor of n.

6 The Primality Problem The language would be the set of all binary representations of primes. LPrime = {10, 11, 101, 111, …}.

7 The Primality Problem Then, given the binary representation of an integer, we answer the question of whether it is in the language LPrime.

8 Decision Problems Most of the problems that we will consider will be decision problems. A decision problem is a problem whose solution is a yes or no answer.

9 Euler Circuits Suppose the problem is to determine whether a given graph has an Euler circuit. An Euler circuit is a closed path that traverses every edge exactly once.

10 Euler Circuits Theorem: A graph has an Euler circuit if and only if it is connected and every vertex has even degree.

11 Euler Circuits We may represent the graph as
An integer n representing the number of vertices. A list of pairs (i, j) representing edges between vertices i and j.

12 Euler Circuits A Turing machine could solve the problem by scanning the tape to determine the index of each vertex. If any vertex has odd degree, then the graph does not have an Euler circuit.

13 Euler Circuits How would we determine whether the graph was connected?
If the graph is connected (and every vertex has even degree), then the answer is yes, it has an Euler Circuit.

14 Instances of Problems When we solve a specific problem, we are solving an instance P of a general problem. We will use the notation P to stand for the binary representation of the instance P.

15 Instances of Problems In the case of the Primality Problem, if n = 29,
then n =

16 Example In the Euler circuit problem, let the graph G be 1 4 3 5 6 2

17 Example The representation of G could be
6,{(1,2),(1,3),(2,3),(2,4),(2,5),(3,4),(3,5),(4,5),(4,6),(5,6)} This entire input could be written in ASCII:

18 The Language of the Problem
Now we create the language of all graphs G that have Euler circuits. Let LEuler be the language {G | G has an Euler circuit}. Let MEuler be a Turing machine that decides LEuler.

19 The Language of the Problem
Given a graph G, we solve the Euler circuit problem for G by letting MEuler decide whether G  LEuler.


Download ppt "The Definition of Algorithm"

Similar presentations


Ads by Google