170 likes | 300 Views
This lecture focuses on the classification of solvable problems and the use of subroutines in algorithm design. We'll investigate key examples, including the Prime Number Problem and the Maximum Clique Problem, while understanding the principles behind defining and solving these problems. We'll also analyze the Connected Graph Problem and explore the concepts of recursive languages and Church's Thesis. The course emphasizes practical algorithm development, showing how existing algorithms can aid in building solutions for complex problems.
E N D
Lecture 4 • Topics • Problem solving • Subroutine Theme • REC language class • The class of solvable problems • Closure properties
Problem Solving • Solving problems • In this course, we spend a lot of time proving there are unsolvable problems • In today’s 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
Problem 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
Problem 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 <= i <= n} • E: Set of edges {(vi, vj)} • Clique: subset C of V such that there is an edge between all nodes in C
Example v1 v2 v3 v6 v5 v4 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?
Example 2 v1 v2 v3 v6 v5 v4 V = {v1, v2, v3, v4, v5, v6} E = { Max clique size? Smallest number of edges needed to increase m. c. size?
Algorithm 1 • Construct an algorithm for solving the max clique problem
Problem 2’ • Decision clique problem • Input: Graph G = (V,E), integerk • Note the extra input object k • Yes/No question: • Does the maximum clique in G have size at least k?
Subroutine 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
Example from divisor problem 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;
Problem 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
REC The class of solvable problems
Programs 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?”
REC • Formal Definition • A C++ program Pdecides 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
Church’s Thesis • What is our modified Church’s 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,...
REC Languages Question: Is REC a proper subset of the set of all languages/problems?
Summary • Solving problems • Subroutine theme • REC • The class of solvable problems/languages • Church’s Thesis • Specific model of computation is not important • Question: Are all problems solvable?