Transcript Lecture 3
Lecture 3: Classifying Problems
• One of the main themes of this course will be to
classify problems in various ways
– By solvability
• Solvable, “half-solvable”, unsolvable
• We will focus our study on decision problems
– function (one correct answer for every input)
– finite range (yes or no is the correct output)
1
Classification Process
• Take some set of problems and partition it
into two or more subsets of problems where
membership in a subset is based on some
shared problem characteristic
Subset 1
Set of Problems
Subset 2
Subset 3
2
Classify by Solvability
• Criteria used is whether or not the problem
is solvable
– that is, does there exist a C++ program which
solves the problem?
Set of All Problems
Solvable Problems Unsolvable Problems
3
Function Problems
• We will focus on problems where the
mapping from input to output is a function
Set of All Problems
Non-Function Problems Function Problems
4
General (Relation) Problem
• the mapping is a relation
– that is, more than one output is possible for a
given input
Inputs
Outputs
5
Criteria for Function Problems
• mapping is a function
– unique output for each input
Inputs
Outputs
6
Example Non-Function Problem
• Divisor Problem
– Input: Positive integer n
– Output: A positive integral divisor of n
9
Inputs
1
3
9
Outputs
7
Example
• Sorting
• Multiplication Problem
– Input: 2 integers x and y
– Output: xy
2,5
Inputs
10
Outputs
8
Another Example
• Maximum divisor problem
– Input: Positive integer n
– Output: size of maximum divisor of n smaller
than n
9
Inputs
1
3
9
Outputs
9
Decision Problems
• We will focus on function problems where
the correct answer is always yes or no
Set of Function Problems
Non-Decision Problems Decision Problems
10
Criteria for Decision Problems
• Output is yes or no
– range = {Yes, No}
• Note, problem must be a function problem
– only one of Yes/No is correct
Yes
No
Inputs
Outputs
11
Example
• Decision sorting
– Input: list of integers
– Yes/No question: Is the list in nondecreasing
order?
(1,3,2,4)
(1,2,3,4)
Inputs
Yes
No
Outputs
12
Another Example
• Decision multiplication
– Input: Three integers x, y, z
– Yes/No question: Is xy = z?
(3,5,14)
(3,5,15)
Inputs
Yes
No
Outputs
13
A Third Example
• Decision Divisor Problem
– Input: Two integers x and y
– Yes/No question: Is y a divisor of x?
(14,5)
(14,7)
Inputs
Yes
No
Outputs
14
Focus on Decision Problems
Set of All Problems
Solvable Problems Unsolvable Problems
Other
Probs
Decision
Problems
• When studying solvability, we are going to
focus specifically on decision problems
– There is no loss of generality, but we will not
explore that here
15
Finite Domain Problems
• These problems have only a finite number of
inputs
Set of All Problems
Finite Domain Problems Infinite Domain Problems
16
Lack of Generality
Set of All Problems
Solvable Problems Unsolvable Problems
Infinite
Domain
Finite
Domain
Empty
• All finite domain problems can be solved
using “table lookup” idea
17
Table Lookup Program
int main(string x) {
switch x {
case “Bill”: return(3);
case “Judy”: return(25);
case “Tom”: return(30);
default: cerr << “Illegal input\n”;
}
18
Key Concepts
• Classification Theme
• Decision Problems
– Important subset of problems
– We can focus our attention on decision
problems without loss of generality
– Same is not true for finite domain problems
• Table lookup
19