Complexity Theory ChapterTwo 2 Computability
Complexity Theory ChapterTwo 2 Computability
Complexity Theory ChapterTwo 2 Computability
COMPUTABILITY
1
Topics that we will be discuss:
Computability Theory
Recursive Functions
Types of Recursive functions
Enumerable Languages
Turing Computable
2
Computability Theory
Certain basic problems cannot be solved by computers.
Example, “the problem of determining whether a mathematical statement is true or false”.
The theories of computability and complexity are closely related.
In complexity theory, the objective is to classify problems as easy ones and hard ones; whereas:
In computability theory, the classification of problems is by those that are solvable and those
that are not.
What makes some problems computationally hard and others easy?
Computer problems come in different varieties; some are easy, and some are hard.
For example:
The sorting problem is an easy one.
The scheduling problem seems to be much harder than the
sorting problem.
3
Introduction to Recursion
Recursive function: a function that calls itself
times it repeats
5
Problem Solving with Recursion
Recursion is a powerful tool for solving repetitive problems
with a loop
Recursive algorithms usually less efficient than iterative ones
6
Problem Solving with Recursion (cont’d.)
Some repetitive problems are more easily solved with recursion
If the problem can be solved now without recursion, solve and return
7
Using Recursion to Calculate the Factorial of a Number
In mathematics, the n! notation represents the factorial of a
number n
For n = 0, n! = 1
For n > 0, n! = 1 x 2 x 3 x … x n
The above definition lends itself to recursive programming
n = 0 is the base case
n > 0 is the recursive case
factorial(n) = n x factorial(n-1)
8
Using Recursion (cont’d.)
9
Examples of Recursive Algorithms
Summing a range of list elements with recursion
Recursive case:
return current_number + sum(list, start+1, end)
11
Examples of Recursive Algorithms (cont’d.)
12
The Fibonacci Series
Fibonacci series: has two base cases
if n = 0 then Fib(n) = 0
if n = 1 then Fib(n) = 1
if n > 1 then Fib(n) = Fib(n-1) + Fib(n-2)
13
Finding the Greatest Common Divisor
Calculation of the greatest common divisor (GCD) of two positive integers
If x can be evenly divided by y, then
gcd(x,y) = y
Otherwise, gcd(x,y) = gcd(y, remainder of x/y)
Corresponding function code:
14
The Towers of Hanoi
Mathematical game commonly used to illustrate the
power of recursion
Uses three pegs and a set of discs in decreasing sizes
Goal of the game: move the discs from leftmost peg to
rightmost peg
Only one disc can be moved at a time
A disc cannot be placed on top of a smaller disc
All discs must be on a peg except while being moved
15
The Towers of Hanoi (cont’d)
Problem statement: move n discs from peg 1 to peg 3 using peg 2 as a
temporary peg
Recursive solution:
16
The Towers of Hanoi (cont’d.)
17
Recursion versus Looping
Reasons not to use recursion:
Less efficient: entails function calling overhead that is not necessary with a loop
Usually a solution using a loop is more evident than a recursive solution
Loop is when the compiter do instruction repeatedly when some condition is
fullfilled
Some problems are more easily solved with recursion than with a loop
A recursive function is called total recursive function if it is defined for its all arguments.
Let f(a1, a2, …an) be a function defined on function g(b1, b2, …bn).
function g.
A total function is called recursive or primitive recursive if and only if it is an initial
function over n,
or it is obtained by applying composition or recursion with finite number of times to the
20
Partial Recursive Functions:
A function f(a1, a2, ….an)computed by a TM is known as partial
recursive function.
if f is defined for some but not all values of a1, a2, ….an.Let f(a1, a2,
21
Partial Recursive Function
A partial function is recursive if it is an initial function over N, or it is
function.
22
Primitive Recursive function ? Total function ? Partial recursive Functions
Recursively Enumerable Recursive Languages
A recursively enumerable language is a recursively
enumerable subset in the set of all possible words over
the alphabet of the language.
A recursively enumerable language is a formal
language for which there exists a Turing machine (or
other computable function) which will enumerate all
valid strings of the language.
A language is called Recursively Enumerable if there
is a Turing Machine that accepts on any input within the
23
language.
Recursively enumerable languages are the formal languages that can
Recursive languages
27
Turing Computable
A (real) number is Turing computable if there exists a Turing machine which
more power than that surely is irrelevant to any useful definition of human rationality.
A slightly stricter boundary is posed by computational complexity, especially in its
28
Computable Functions
Computable functions are used to discuss computability without referring to any concrete
model of computation such as Turing machines or register machines.
Any definition, however, must make reference to some specific model of computation but
all valid definitions yield the same class of functions.
According to the Ch-Turing thesis, computable functions are exactly functions that
calculated using a mechanical calculation device given unlimited amounts of time and
storage space.
Equivalently, this thesis states that a function is computable if and only if it has an
algorithm.
Note that an algorithm in this sense is understood to be a sequence of steps a person with
29
unlimited time and an unlimited supply of pen and paper could follow.
w o
r T
p te
h a
f C
d o
E n
30