0% found this document useful (0 votes)
8 views

9.hard Problems

Uploaded by

rgn12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

9.hard Problems

Uploaded by

rgn12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10

Limits to Computations

1
Limits to Computations

We use efficient algorithms to solve computer problems.

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)

For some problems, we do not know whether efficient algorithms exists.

Having a problem with high running time Vs problem that cannot be solved !

2
Limits to Computations
reductions

reductions allows us to solve one problem in terms of another

Definition: Sorting

Input: a sequence of integers x0, x1, x2, …, xn-1

Output: a permutative y0, y1, y2, …, yn-1 such that yi <= yj whenever i < j

Definition: Pairing

Input: two sequences of integers X = (x0,x2,…,xn-1) and Y = (y0,y1,…yn-1)

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:

1.Convert an instance of pairing into two instances of sorting


2.Sort the two sequences
3.Convert the output of sorting into output of pairing

4
Limits to Computations

Consider any 2 problems for which a suitable reduction from one to the other can
be found.

First problem takes an arbitrary instance of its input: I


transform I to a solution: SOL

Second problem takes an arbitrary instance of its input: I’


transform I’ to a solution: SOL’

Reduction is more formally defined as:

1.There must be a transformation from any instance I of the first problem to an


instance of I’ in the second problem
2.Apply an algorithm for the second problem to the instance I’, yielding a solution
SOL’
3.Transform SOL’ to the solution I, known as SOL.

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.……………….

4.Add the intermediate results

O(n2)

Q? Is squaring an n-digit number as difficult as multiplying two n-digit numbers?

( X  Y )2  ( X  Y )2
X Y 
4

the above formula allows us to convert arbitrary instance of multiplication to a


series of operations involving three additions/substractions (each of which takes
linear time), two squarings and a division by 4. Hence, squaring is “as hard as”
multiplying.
6
Limits to Computations
the earlier reduction show us that if a linear time algorithm for squaring can be found, it
can be used to construct a linear time algorithm for multiplication too.

Hard Problems:

An algorithms that runs in exponential time, O(cn) where c > 1 is a constant

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.

Guessing the correct answer to a problem ( checking all possible answers in


parallel) to determine which is correct – Non-Determinism.

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

while (n > 1) every input halts. Is there an input that does


if (ODD (n)) not halt? Does this program halt for all values
n = 3xn + 1; of n?
else
n = n/2

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.

Eg 1. Consider the set of positive even integers (2,4,6…).

Assign integer i to (bin i/2) assuming there are infinite row of bins.

Eg 2. Are the number of computer programs countable or not?

Program = string of P characters (in ASCII, P = 128)

Assign null = bin 1


Assign all the strings with 1 character to next P bins
Assign all the strings with 2 characters to next P2 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.

Are all integer functions countable?

bin1 bin2 bin3 bin4


x f1(x) x f2(x) x f3(x) x f4(x) x fnew(x)
1 1 1 1 1 7 1 15 1 2
2 1 2 2 2 9 2 1 2 3
3 1 3 3 3 11 3 11 ….. 3 12
4 1 4 4 4 13 4 13 4 14
5 1 5 5 5 15 5 2 5 .
6 1 6 6 6 17 6 1 6 .
. . . . . . . . . .

all integer functions are un-acountable.

10

You might also like