9.hard Problems
9.hard Problems
1
Limits to Computations
There can be inefficient algorithms for a particular problem. Eg. considering all possible
permutations of numbers to sort an array (n!). – time to sort is very high.
In real life, there are many computer problems that must be solved for which the best-
known algorithm takes a long time. (2n)
Having a problem with high running time Vs problem that cannot be solved !
2
Limits to Computations
reductions
Definition: Sorting
Output: a permutative y0, y1, y2, …, yn-1 such that yi <= yj whenever i < j
Definition: Pairing
Output: A pairing of the elements in the two sequences such that the least value in X is paired
with the least value in Y, the next value in X is paired with the next least value in Y, and so on.
3
Limits to Computations
One way of solving pairing is sorting the sequences and then pairing items based on their
position in sorted order. Technically, we say that Pairing is Reduced to Sorting, since
sorting is used to solve pairing.
3 steps in reduction:
4
Limits to Computations
Consider any 2 problems for which a suitable reduction from one to the other can
be found.
A method to solve the first problem, given that we already have a solution for the
second. 5
Limits to Computations
Problem of multiplying two n-digit numbers
1.multiply the last digit of the first number from the second number
2.multiply the second digit of the first number from the second number
3.……………….
O(n2)
( X Y )2 ( X Y )2
X Y
4
Hard Problems:
NP – completeness
Consider that given a particular guess for a solution, checking the solution to see
whether it is correct, can be done in polynomial time. Even if number of possible
solutions is exponential, any given guess can be checked in polynomial time.
Non-deterministic algorithm
7
Limits to Computations
NP problem: Any problem with an algorithm that runs on a non-deterministic machine in
polynomial time
many times, programming errors result in infinite loops. We don’t know whether the
program is slow or whether an infinite loop has occurred.
Can we design a program where it will warn infinite loops before running the program?
There cannot be a program that can positively determine if another program will halt for all
inputs: Halting Problem
8
Limits to Computations
A set is said to be countable if every member of the set can be uniquely assigned
to a positive integer. A set is said to be uncountable if it is not possible to assign
every member of the set to a positive integer.
Assign integer i to (bin i/2) assuming there are infinite row of bins.
String of any given length can be assigned to some bin. Thus, any program
which is a string of finite length is assigned to some bin. So, the set of all
programs are countable. 9
Limits to Computations
Consider all integer functions (functions that reads in a single positive
integer value and returns a single positive integer as output.
10