Announcements NP-Complete Problems Decidable vs. Undecidable Problems Review.

Slides:



Advertisements
Similar presentations
Traversing a Binary Tree Binary Search Tree Insertion Deleting from a Binary Search Tree.
Advertisements

Linked List: Traversal Insertion Deletion. Linked List Traversal LB.
NP-Complete Problems CIT 596, Spring Problems that Cross the Line What if a problem has: o An exponential upper bound o A polynomial lower bound.
Problems and Their Classes
Programming Languages Wrap-up. Your Toolkit Object-oriented Imperative Functional Logic.
1 The Limits of Computation Intractable and Non-computable functions.
CS420 lecture one Problems, algorithms, decidability, tractability.
© The McGraw-Hill Companies, Inc., Chapter 8 The Theory of NP-Completeness.
CSE332: Data Abstractions Lecture 27: A Few Words on NP Dan Grossman Spring 2010.
NP-Complete Problems Reading Material: Chapter 10 Sections 1, 2, 3, and 4 only.
The Theory of NP-Completeness
NP-Complete Problems Problems in Computer Science are classified into
Analysis of Algorithms CS 477/677
Chapter 11: Limitations of Algorithmic Power
Complexity Issues Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
CS10 The Beauty and Joy of Computing Lecture #23 : Limits of Computing Thanks to the success of the Kinect, researchers all over the world believe.
Halting Problem. Background - Halting Problem Common error: Program goes into an infinite loop. Wouldn’t it be nice to have a tool that would warn us.
Searching via Traversals Searching a Binary Search Tree (BST) Binary Search on a Sorted Array Data Structure Conversion and Helper Modules.
Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,
Chapter 11 Limitations of Algorithm Power. Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples:
Computational Complexity Polynomial time O(n k ) input size n, k constant Tractable problems solvable in polynomial time(Opposite Intractable) Ex: sorting,
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
Difficult Problems. Polynomial-time algorithms A polynomial-time algorithm is an algorithm whose running time is O(f(n)), where f(n) is a polynomial A.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
Searching Given a collection and an element (key) to find… Output –Print a message (“Found”, “Not Found) –Return a value (position of key ) Don’t modify.
Analysis of Algorithms These slides are a modified version of the slides used by Prof. Eltabakh in his offering of CS2223 in D term 2013.
Problems you shouldn’t tackle. Problem Complexity.
Cs3102: Theory of Computation Class 24: NP-Completeness Spring 2010 University of Virginia David Evans.
P and NP.
CSC 413/513: Intro to Algorithms NP Completeness.
CSC 172 P, NP, Etc. “Computer Science is a science of abstraction – creating the right model for thinking about a problem and devising the appropriate.
Complexity Non-determinism. NP complete problems. Does P=NP? Origami. Homework: continue on postings.
1 Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: b number of comparisons needed to find the.
CS 345: Chapter 8 Noncomputability and Undecidability Or Sometimes You Can’t Get It Done At All.
Cliff Shaffer Computer Science Computational Complexity.
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
Class Examples (Simple, Airplane, Queue, Pile) Copy vs. Clone.
Announcements Review problems Review Outline. Online Survey
Introduction to Classes and Objects Initializing Objects Making Use of Classes in Algorithms Class Examples.
CSE373: Data Structures & Algorithms Lecture 22: The P vs. NP question, NP-Completeness Lauren Milne Summer 2015.
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
Class 24: P=NP? David Evans cs302: Theory of Computation University of Virginia Computer Science PS6 (the last one) is.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
Beauty and Joy of Computing Limits of Computing Ivona Bezáková CS10: UC Berkeley, April 14, 2014 (Slides inspired by Dan Garcia’s slides.)
Problem Complexity and NP-Complete Problems Presented by Ming-Tsung Hsu.
Limits to Computation How do you analyze a new algorithm? –Put it in the form of existing algorithms that you know the analysis. –For example, given 2.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
Complexity & Computability. Limitations of computer science  Major reasons useful calculations cannot be done:  execution time of program is too long.
Review Problems. What is the Big O? i
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 15: Intractable Problems (Smiley.
LIMITATIONS OF ALGORITHM POWER
Graphs Arrays Iteration Combining Data Structures.
CSE 311 Foundations of Computing I Lecture 28 Computability: Other Undecidable Problems Autumn 2011 CSE 3111.
Stacks Queues Introduction to Trees. Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 8: Crash Course in Computational Complexity.
Optimization/Decision Problems Optimization Problems – An optimization problem is one which asks, “What is the optimal solution to problem X?” – Examples:
Review Linked List Insertion Description Deletion Description Basic Node Implementation Conclusion 1.
1 Computability Tractable, Intractable and Non-computable functions.
1 1. Which of these sequences correspond to Hamilton cycles in the graph? (a) (b) (c) (d) (e)
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 23: Intractable Problems (Smiley Puzzles.
CSE 332: NP Completeness, Part II Richard Anderson Spring 2016.
1.5 Intractable problems.
Lecture 14 Traversals of Linked Lists Preorder BST Traversal Postorder BST Traversal Miscellaneous BST Traversals Depth First vs Breadth First Array Traversals.
Simple Dynamic Data (Linked Lists)
CS 2210 Discrete Structures Algorithms and Complexity
Introduction to Recursion
CSC 380: Design and Analysis of Algorithms
CSC 380: Design and Analysis of Algorithms
CS 2210 Discrete Structures Algorithms and Complexity
Presentation transcript:

Announcements NP-Complete Problems Decidable vs. Undecidable Problems Review

Review Outline at

Online Survey The Spring term course/instructor opinion survey will be available during the period Monday, April 17th through Friday, April 28th from 6am to 11:59pm each day: LB

Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics L1 LB

Final Exam Schedule CS1311 Sections E/F Tuesday/Thursday 2:00 P.M. Exam Scheduled for 2:50 Wednesday May 3, 2000 Physics L1 LB

NP-Complete Problems

Problems that Cross the Line What if a problem has: –An exponential upper bound –A polynomial lower bound We have only found exponential algorithms, so it appears to be intractable. But... we can’t prove that an exponential solution is needed, we can’t prove that a polynomial algorithm cannot be developed, so we can’t say the problem is intractable...

NP-Complete Problems The upper bound suggests the problem is intractable The lower bound suggests the problem is tractable The lower bound is linear: O(N) They are all reducible to each other –If we find a reasonable algorithm (or prove intractability) for one, then we can do it for all of them!

Example NP-Complete Problems Path-Finding (Traveling salesman) Map coloring Scheduling and Matching (bin packing) 2-D arrangement problems Planning problems (pert planning) Clique

Traveling Salesman

5-Clique

Map Coloring

Class Scheduling Problem With N teachers with certain hour restrictions M classes to be scheduled, can we: –Schedule all the classes –Make sure that no two teachers teach the same class at the same time –No teacher is scheduled to teach two classes at once

Certificates Returning true: in order to show that the schedule can be made, we only have to show one schedule that works –This is called a certificate. Returning false: in order to show that the schedule cannot be made, we must test all schedules.

Oracles If we could make the ‘right decision’ at all decision points, then we can determine whether a solution is possible very quickly! –If the found solution is valid, then True –If the found solution is invalid, then False If we could find the certificates quickly, NP- complete problems would become tractable – O(N) This (magic) process that can always make the right guess is called an Oracle.

Determinism vs. Nondeterminism Nondeterministic algorithms produce an answer by a series of “correct guesses” Deterministic algorithms (like those that a computer executes) make decisions based on information.

NP-Complete “NP-Complete” comes from: – Nondeterministic Polynomial – Complete - “Solve one, Solve them all” There are more NP-Complete problems than provably intractable problems.

Proving NP-Completeness Show that the problem is in NP. (i.e. Show that a certificate can be verified in polynomial time.) Assume it is not NP complete Show how to convert an existing NPC problem into the problem that we are trying to show is NP Complete (in polynomial time). If we can do it we’ve done the proof! Why? If we can turn an exisiting NP-complete problem into our problem in polynomial time...  LB

Become Famous! To get famous in a hurry, for any NP- Complete problem: –Raise the lower bound (via a stronger proof) –Lower the upper bound (via a better algorithm) They’ll be naming buildings after you before you are dead!

Questions?

Decidable vs. Undecidable Problems

Decidable Problems We now have three categories: –Tractable problems –NP-Complete problems –Intractable problems All of the above have algorithmic solutions, even if impractical.

Undecidable Problems No algorithmic solution exists –Regardless of cost –These problems aren’t computable –No answer can be obtained in finite amount of time

The Unbounded Tiling Problem What if we took the tiling puzzle and removed the bounds: –For a given number (T) of different kinds of tiles –Can we arrive at an arrangement that will fill any size area? By removing the bounds, this problem becomes undecidable.

The Halting Problem Given an algorithm A and an input I, will the algorithm reach a stopping place? loop exitif (x = 1) if (even(x)) then x <- x div 2 else x <- 3 * x + 1 endloop In general, we cannot solve this problem in finite time.

Partially and Highly Undecidable Most undecidable problems have finite certificates. These are partially decidable. Some undecidable problems do not have finite certificates even with an oracle. These are called highly undecidable.

A Hierarchy of Problems For a given problem, is there or will there ever be an algorithmic solution? ProblemIn Theory In Application Highly Undecidable NO NO Partially Undecidable NO NO Intractable YES NO Tractable YES YES

Questions?

Review Problems What is the Big O? i <- N j <- 1 loop exitif(i <= 0) loop exitif(j > M) j <- j + 1 endloop i < i - 1 endloop

Review problems Circle and Identify the 3 parts of recursion: Function Fact returnsa Num(N iot in Num) if(N = 0) then Fact returns 1 else Fact returns N * Fact(N - 1) endif endfunction // Fact

Review problems Circle and Identify the 3 parts of recursion: Function Fact returnsa Num(N iot in Num) if(N = 0) then Fact returns 1 else Fact returns N * Fact(N - 1) endif endfunction // Fact Check for termination Call self Move one step closer

Review Problems Recall that a leaf is a node in a binary tree with no children. Write a module that when passed a pointer to a binary tree will return the number of leaves. The module should use recursion

Leaves Function Leaves returnsa Num (current iot Ptr toa TNode) if(current = NIL) then Leaves returns 0 elseif(current^.left = NIL AND current^.right = NIL) then Leaves returns 1 else Leaves returns Leaves(current^.right) + Leaves(current^.left) endif endfunction // Leaves

Review Problems How many “time chunks” will be required to run this algorithm on 2 processors? S1 S4 S2 S5 S8 S3 S6 S9 S7 IIIIII

Review Problems S1 S4 S2 S5 S8 S3 S6 S9 S7 III

Review Problems Write a module to convert an unsorted linked list to a sorted linked list. Use data structure conversion as opposed to a sort algorithm such as Bubble Sort or Merge Sort

Review problems Algorithm Pain a,b,c iot Char a <- ‘b’ b <- ‘c’ c <- ‘a’ Agony(c,a,’b’) print(a,c,b) b <- funky(a,c) print(a,b,c) endalgorithm Procedure Agony(a iot in/out Char, b iot out Char, c iot in Char) t iot Char if(c = ‘c’) then c <- ‘d’ t <- b b <- a a <- t else b <- a a <- ‘b’ endif endprocedure Function funky returnsa Char (x,y isoftype in Char) if(x = y) then funky returns ‘a’ else finky returns ‘b’ endif endfunction

Review problems Write a vector class It should be generic and support (at least) the following methods in the public section AddToEnd AddAt(nth) Remove(nth) Size Get(nth)

class Vector(DT) public Procedure AddToEnd(din iot in DT) // PPP Procedure AddAt(nth iot in Num, din iot in DT) // PPP Procedure Remove(nth iot in Num) // PPP Function Size returnsa Num() // PPP Function Get returnsa DT(nth iot in Num) // PPP Procedure Initialize() // PPP

protected Node definesa record data iot DT next iot Ptr toa Node endrecord head isoftype Ptr toa Node count isoftype Num Procedure AddToEnd(din iot in DT) AddToEndHelper(head, din) endprocedure // AddToEnd

Procedure AddToEndHelper (cur iot in/out Ptr toa Node, din iot in DT) // PPP if(cur = NIL) then cur = new(Node) cur^.data <- din cur^.next <- NIL count <- count + 1 else AddToEndHelper(cur^.next, din) endif endprocedure // AddToEndHelper Procedure AddAt(nth iot in Num, din iot in DT) AddAtHelper(head, nth, din, 1) endprocedure // AddAt

Procedure AddAtHelper(cur iot in/out Ptr toa Node, nth iot in Num, din iot in DT,kount iot in Num) // PPP temp iot Ptr toa Node if(cur = NIL OR nth = kount) then temp <- new(Node) temp^.data <- din temp^.next <- cur cur <- temp count <- count + 1 else AddAtHelper(cur^.next, nth, din, kount + 1) endif endprocedure // AddAtHelper

Procedure Remove(nth iot in Num) RemoveHelper(head, nth, 1) endprocedure // Remove Procedure RemoveHelper(cur iot in/out Ptr toa Node, nth iot in Num, kount iot in Num) // PPP if(cur <> NIL) then if(nth = kount) then cur <- cur^.next count <- count - 1 else RemoveHelper(cur^.next, nth, kount + 1) endif endprocedure // RemoveHelper

Function Size returnsa Num() Size returns count endfunction // Size Function Get returnsa DT(nth iot in Num) Get returns GetHelper(head, nth, kount) endfunction Function GetHelper returnsa DT (cur iot in Ptr toa Node, nth, kount iot in Num) // Precon: User must not request item > Size ** // PP if(nth = kount) then GetHelper returns cur^.data else GetHelper returns GetHelper (cur^.next, nth, kount + 1) endif endfunction // GetHelper

Procedure Initialize() head <- NIL count <- 0 endprocedure // Initialize endclass // Vector

Review problems Use the generic Vector class you just wrote to write a baseball roster program. It should manage baseball player records consisting of –Name –Position It should support the following operations –Add a player –Remove a player –Add a player at position N –Print a roster (only if there are 9 players otherwise print an error message) Assume that the record is named Player Assume that you have modules called –Procedure GetPlayer(data isoftype out Player) –Procedure PrintPlayer(data isoftype in Player)

Procedure Menu(Choice iot out Num) print(“1-Add a player”) print(“2-Remove a player”) print(“3-Add a player at position N”) print(“4-Print a roster”) print(“5-Quit”) read(Choice) endprocedure // Menu Player definesa record Name iot String Position iot String endrecord // Player Procedure GetPlayer(data isoftype out Player) Procedure PrintPlayer(data isoftype in Player) TEAMSIZE is 9

Algorithm Roster uses Vector(DT) Team isoftype Vector(Player) // Make the Vector!!! Choice iot Num Loop Menu(Choice) exitif(Choice = 5) if(Choice = 1) then Add(Team) elseif(Choice = 2) then Remove(Team) elseif(Choice = 3) then AddAt(Team) elseif(Choice = 4) then PrntRoster(Team) endif endalgorithm // Roster

Procedure Add(Team iot in/out Vector(Player)) temp iot Player GetPlayer(temp) Team.AddToEnd(temp) endprocedure // Add procedure Remove(Team iot in/out Vector(Player)) i iot Num print(“Line number to remove?”) read(i) Team.Remove(i) endprocedure // Remove Procedure AddAt(Team iot in/out Vector(Player)) i iot Num temp iot Player print(“Enter at what line number”) GetPlayer(temp) Team.AddAt(i, temp) endprocedure // AddAt

Procedure PrntRoster(Team iot in/out Vector(Player))) i iot Num if(Team.Size() <> TEAMSIZE) print(“Wrong size team”) else i < 1 Loop exitif(i > TEAMSIZE) PrintPlayer(Team.Get(i)) i <- i + 1 endloop endif endprocedure // PrntRoster

Questions?