Top Banner
1 Lecture 2 • Topics Importance of this material • Fundamental Limitations Connecting Problems and Languages • Problems Search, function and decision problems • Languages Encodings of Problems » Encode input instances of problem as strings Language Recognition Problem » Is an input string in the language?
29

1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

1

Lecture 2

• Topics– Importance of this material

• Fundamental Limitations

– Connecting Problems and Languages• Problems

– Search, function and decision problems

• Languages– Encodings of Problems

» Encode input instances of problem as strings

– Language Recognition Problem

» Is an input string in the language?

Page 2: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

2

Importance: Philosophy

• Phil. of life– What is the purpose of

life?

– What is achievable in life?

– What is NOT achievable in life?

• Phil. of computing– What is the purpose of

programming?

– What is solvable through programming?

– What is NOT solvable through programming?

Page 3: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

3

Importance: Science

• Physics– Study of fundamental

physical laws and phenomenon like gravity and electricity

• Engineering– Governed by physical

laws

• Our material– Study of fundamental

computational laws and phenomenon like undecidability and universal computers

• Programming– Governed by

computational laws

Page 4: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

4

Problem Types

• We classify problems based on– range (output set) size

• infinite

• binary

– mapping type• function

– unique output per input

• relation– more than one output per input

Page 5: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

5

I) Search Problems

• (countably) infinite range

• the mapping may be a relation

Inputs Outputs

Page 6: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

6

Examples

• Divisor– Input: Integer n– Output: An integral divisor of n

Inputs Outputs

9 13

9

Page 7: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

7

II) Function Problems

• (countably) infinite range

• mapping is a function– unique solution per input

Inputs Outputs

Page 8: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

8

Examples

• Sorting

• Multiplication Problem– Input: 2 integers x and y– Output: xy

Inputs Outputs

2,5 10

Page 9: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

9

Examples

• Maximum divisor problem– Input: Integer n– Output: size of maximum divisor of n smaller

than n

Inputs Outputs

9 13

9

Page 10: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

10

III) Decision Problems• Output is yes or no

– range = {Yes, No}

• unique solution– only one of Yes/No is correct

Inputs Outputs

Yes

No

Page 11: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

11

Examples

• Decision sorting– Input: list of numbers– Yes/No question: Is list in nondecreasing

order?

Inputs Outputs

Yes

No

(1,3,2,4)

(1,2,3,4)

Page 12: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

12

Examples

• Decision multiplication– Input: Three numbers x,y, z– Yes/No question: Is xy = z?

Inputs Outputs

Yes

No

(3,5,14)

(3,5,15)

Page 13: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

13

Examples

• Decision Divisor Problem– Input: Two numbers x and y– Yes/No question: Is y a divisor of x?

Inputs Outputs

Yes

No

(14,5)

(14,7)

Page 14: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

14

What about finite domain problems?

• Note all problems described above have infinite domains (input set)– size of range varies from 2 to countably infinite

• What happens if we had a problem with only a finite domain?– “Table lookup”

Page 15: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

15

Table Lookup Program

string x;

cin >> x;

switch x {

case “Kona”: cout << 3; break;

case “Eric”: cout << 31; break;

case “Cliff”: cout << 36; break;

default: cout << “Illegal input\n”;

}

Page 16: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

16

Generality of Decision Problems

• We now show that we can focus only on decision problems

– Having yes/no outputs is not limiting.– If we can solve a decision version of a problem,

we can typically solve the function and search versions of the same problem as well

Page 17: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

17

Example

• Decision divisor problem– Input: Integers x and y– Yes/No Question: Is y a divisor of x?– Assumption: Alg. A solves this problem

• Function divisor problem– Input: Integer x– Output: Largest divisor of x that is not x– Goal: Construct alg. A’ to solve this problem

Page 18: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

18

Program A’

integer x, max, j;

cin >> x;

max = 1;

for (j=2; j<x; j++)

if (A(x,j)) // using A as a procedure

max = j;

return max;

Page 19: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

19

Connecting Problems and Languages

• Start with any problem P

• Convert P to equivalent decision problem P’

• Convert P’ to equiv set membership problem SP– Reinterpret P’

• Convert SP to language recognition problem L– Encoding scheme

Page 20: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

20

Set Membership Problem

• Setting– Universe U– set S subset of U

• Input– Element x in U

• Yes/No Question– Is x in S?

Page 21: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

21

Decision Problems to Set Membership Problems

• Reformulate/interpret a decision problem as a set membership problem– Universe U: set of all input instances– Set S: either set of all YES or all NO input

instances

Page 22: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

22

Example

• Decision divisor problem– Input: Integers x and y– Yes/No Question: Is y a divisor of x?

• Set membership problem– Universe U = {(x,y) | x and y are integers}– Set S = {(x,y) | y divides x}

Page 23: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

23

Sets to Languages

• How do we represent an input instance of a set membership problem?– We use an encoding scheme

• Each input instance is mapped to a unique string over some finite alphabet

• Think ASCII

• Corresponding language L: the set of strings corresponding to yes instances

Page 24: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

24

Decision multiplication problem

• Alphabet 1= {0,1,2,3,4,5,6,7,8,9,;}

– 7;10;25 NO instance– 3;4;12 YES instance

• Binary Alphabet 2 = {0,1}

– Encode alphabet 1

• 11 characters in 1

• 4 bits per character of 1

– Encoding of 3;4;12• 001110110100101100010010

Page 25: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

25

Decision divisor problem

• Fill in

Page 26: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

26

Language recognition problem (LRP)

• Input Instance Description– Finite length string x in * (why finite?)

• Yes/No Question – Is input string x in language L?

• How does the language recognition problem for L relate to corresponding set membership problem?

Page 27: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

27

Decision Addition Problem

• Illegal strings easily recognized– Thus two problems essentially identical

*

Yes No

3;4;7

1;1;3 ;;1111;31;1;27;5;1

111;1111

Illegal

Page 28: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

28

Every decision problem can be formulated as an LRP

• First convert to set membership problem

• Then convert to language recognition problem using an encoding scheme– Illegal strings easily recognized

Page 29: 1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.

29

Key Concepts

• Different types of problems– always countably infinite domain

• Decision problems– binary range = {YES, NO}– still general despite limited range

• Set membership problem• Language recognition problem

– encoding scheme