Title: Problem solving
1Lecture 4
- Topics
- Problem solving
- Subroutine Theme
- REC language class
- The class of solvable problems
- Closure properties
2Problem Solving
- Solving problems
- In this course, we spend a lot of time proving
there are unsolvable problems - In todays class, we will spend time doing the
opposite solving problems - Subroutines
- Using an algorithm for one problem to help build
an algorithm to solve a second problem
3Problem 1
- Prime Number Problem
- Input Positive integer n
- Yes/No Question Is n a prime number?
- Questions
- What kind of problem is this?
- Construct a solution to this problem
4Problem 2
- Maximum clique problem
- Input Graph G (V,E)
- list of nodes and edges
- Output Size of maximum clique in G
- Definitions
- V Set of n nodes vi 1 lt i lt n
- E Set of edges (vi, vj)
- Clique subset C of V such that there is an edge
between all nodes in C
5Example
v1
v2
v3
v6
v4
v5
V v1, v2, v3, v4, v5, v6 E (v1, v2), (v1,
v5), (v1, v6), (v2, v3), (v2, v4), (v3, v4),
(v4, v5), (v5, v6) Question How could we
encode a graph as a string?
6Example 2
v1
v2
v3
v5
v6
v4
V v1, v2, v3, v4, v5, v6 E Max clique
size? Smallest number of edges needed to increase
m. c. size?
7Algorithm 1
- Construct an algorithm for solving the max clique
problem
8Problem 2
- Decision clique problem
- Input Graph G (V,E), integer k
- Note the extra input object k
- Yes/No question
- Does the maximum clique in G have size at least k?
9Subroutine Theme
- Assume that algorithm A solves the decision
clique problem - Construct an algorithm A for solving the max
clique problem that uses A as a subroutine
10Example from divisor problem
- integer x, max, j
- cin gtgt x
- max 1
- for (j2 jltx j)
- if (A(x,j)) // using A as a procedure
- max j
- return max
11Problem 3
- Connected graph problem
- Input Graph G (V,E)
- list of nodes and edges
- Yes/No Question Is there a path of edges between
every pair of nodes? - Construct an algorithm to solve this problem
12REC
- The class of solvable problems
13Programs and Inputs
- Suppose we have a language L
- In order for P to solve the language recognition
problem associated with L, what should P do on a
given string x - P should halt after a finite amount of time
- P should correctly respond yes/no with respect to
Is x in L?
14REC
- Formal Definition
- A C program P decides language L iff
- 1) Program P halts on all input strings
- 2) Program P correctly labels all strings it
halts on as in or not in L. - A language L is recursive or decidable iff there
exists a C program P which decides L. - What if there is a Java program P which decides
L? - REC the set of recursive languages
15Churchs Thesis
- What is our modified Churchs Thesis?
- Any algorithm can be written as a C program
- Any problem which cannot be solved by a C
program cannot be solved by any algorithm. - Importance?
- The definition of REC is robust.
- We could use other models of computation
- Turing machines, Java programs, Lisp Programs,...
16Languages
Question Is REC a proper subset of the set of
all languages/problems?
17Summary
- Solving problems
- Subroutine theme
- REC
- The class of solvable problems/languages
- Churchs Thesis
- Specific model of computation is not important
- Question Are all problems solvable?