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
Embed
1 Lecture 2 Topics –Importance of this material Fundamental Limitations –Connecting Problems and Languages Problems –Search, function and decision problems.
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
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?
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?
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
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
5
I) Search Problems
• (countably) infinite range
• the mapping may be a relation
Inputs Outputs
6
Examples
• Divisor– Input: Integer n– Output: An integral divisor of n
Inputs Outputs
9 13
9
7
II) Function Problems
• (countably) infinite range
• mapping is a function– unique solution per input
Inputs Outputs
8
Examples
• Sorting
• Multiplication Problem– Input: 2 integers x and y– Output: xy
Inputs Outputs
2,5 10
9
Examples
• Maximum divisor problem– Input: Integer n– Output: size of maximum divisor of n smaller
than n
Inputs Outputs
9 13
9
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
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)
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)
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)
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”
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”;
}
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
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
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;
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
20
Set Membership Problem
• Setting– Universe U– set S subset of U
• Input– Element x in U
• Yes/No Question– Is x in S?
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
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}
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
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
25
Decision divisor problem
• Fill in
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?
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
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
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