Problems you shouldn’t tackle. Problem Complexity.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Problems and Their Classes
Discrete Structures CISC 2315
Lecture # 38 Algorithms & Problem Solving: How Hard Can it Get?
1 The Limits of Computation Intractable and Non-computable functions.
CS420 lecture one Problems, algorithms, decidability, tractability.
CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Tyler Robison Summer
CSE332: Data Abstractions Lecture 27: A Few Words on NP Dan Grossman Spring 2010.
Eleg667/2001-f/Topic-1a 1 A Brief Review of Algorithm Design and Analysis.
P, NP and more.
Cmpt-225 Algorithm Efficiency.
Analysis of Algorithms CS 477/677
Computational Complexity, Physical Mapping III + Perl CIS 667 March 4, 2004.
Chapter 11: Limitations of Algorithmic Power
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.
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
1 Section 2.3 Complexity of Algorithms. 2 Computational Complexity Measure of algorithm efficiency in terms of: –Time: how long it takes computer to solve.
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.
CSc /6 Week nine 1 CSc142 Algorithms and efficiency Week 9 Pete Bagnall Elizabeth Phillips
Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,
1 CSC 421: Algorithm Design & Analysis Spring 2013 Complexity & Computability  lower bounds on problems brute force, decision trees, adversary arguments,
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:
CSCE350 Algorithms and Data Structure
Computational Complexity Polynomial time O(n k ) input size n, k constant Tractable problems solvable in polynomial time(Opposite Intractable) Ex: sorting,
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.
Chapter 7 Inefficiency and Intractability CS 345 Spring Quarter, 2014.
Announcements NP-Complete Problems Decidable vs. Undecidable Problems Review.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
Analysis of Algorithms
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.
Unsolvability and Infeasibility. Computability (Solvable) A problem is computable if it is possible to write a computer program to solve it. Can all problems.
Cs3102: Theory of Computation Class 24: NP-Completeness Spring 2010 University of Virginia David Evans.
P and NP.
Complexity A decidable problem is computationally solvable. But what resources are needed to solve the problem? –How much time will it require? –How much.
CSC 413/513: Intro to Algorithms NP Completeness.
Computation, Complexity, and Algorithm IST 501 Fall 2014 Dongwon Lee, Ph.D.
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.
Algorithm Analysis (Algorithm Complexity). Correctness is Not Enough It isn’t sufficient that our algorithms perform the required tasks. We want them.
CSC 211 Data Structures Lecture 13
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.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
3.3 Complexity of Algorithms
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.
Computation, Complexity, and Algorithm IST 512 Spring 2012 Dongwon Lee, Ph.D.
Optimization Problems
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 15: Intractable Problems (Smiley.
The Beauty and Joy of Computing Lecture #23 Limits of Computing Researchers at Facebook and the University of Milan found that the avg # of “friends” separating.
Scalability for Search Scaling means how a system must grow if resources or work grows –Scalability is the ability of a system, network, or process, to.
Searching Topics Sequential Search Binary Search.
Optimization/Decision Problems Optimization Problems – An optimization problem is one which asks, “What is the optimal solution to problem X?” – Examples:
Big O David Kauchak cs302 Spring Administrative Assignment 1: how’d it go? Assignment 2: out soon… Lab code.
Pancakes, Puzzles, and Polynomials: Cracking the Cracker Barrel Game Christopher Frost Michael Peck.
Copyright © 2014 Curt Hill Algorithm Analysis How Do We Determine the Complexity of Algorithms.
1 Computability Tractable, Intractable and Non-computable functions.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 23: Intractable Problems (Smiley Puzzles.
Last time More and more information born digital
1.5 Intractable problems.
David Kauchak CS52 – Spring 2015
CS 2210 Discrete Structures Algorithms and Complexity
Scalability for Search and Big O
Class 14: Intractable Problems CS150: Computer Science
CS 2210 Discrete Structures Algorithms and Complexity
Chapter 11 Limitations of Algorithm Power
Scalability for Search and Big O
CSC 380: Design and Analysis of Algorithms
CSC 380: Design and Analysis of Algorithms
CS 2210 Discrete Structures Algorithms and Complexity
Presentation transcript:

Problems you shouldn’t tackle

Problem Complexity

Relations between Problems, Algorithms, and Programs Problem Algorithm Program....

Algorithmic Performance Thus Far Some examples thus far: –O(1) Insert to front of linked list –O(log N) Binary Search –O(N) Simple/Linear Search –O(N Log N)Merge/Quick/Heap Sort –O(N 2 )Insertion/Bubble Sort But it could get worse: –O(N 5 ), O(N 2000 ), etc.

An O(N 5 ) Example For N = 256 N 5 = = 1,100,000,000,000 If we had a computer that could execute a million instructions per second… 1,100,000 seconds = 12.7 days to complete But it could get worse…

The Power of Exponents A rich king and a wise peasant…

The Wise Peasant’s Pay Day(N)Pieces of Grain N2N 63 9,223,000,000,000,000, ,450,000,000,000,000,000

How Bad is 2 N ? Imagine being able to grow a billion (1,000,000,000) pieces of grain a second… It would take –585 years to grow enough grain just for the 64 th day –Over a thousand years to fulfill the peasant’s request! ?

So the King cut off the peasant’s head.

The Towers of Hanoi A B C Goal: Move stack of rings to another peg –Rule 1: May move only 1 ring at a time –Rule 2: May never have larger ring on top of smaller ring

Original State Move 1 Move 2 Move 3 Move 4 Move 5 Move 6 Move 7 Towers of Hanoi: Solution

Towers of Hanoi - Complexity For 3 rings we have 7 operations. To add a 4 th ring, you have to move the upper 3 rings to one peg, move the 4 th ring, then move the upper 3 rings on top of it – doubling the amount of work. In general, the cost is 2 N – 1 = O(2 N ) This grows incredibly fast!

Towers of Hanoi (2 N ) Runtime For N = 64 2 N = 2 64 = 18,450,000,000,000,000,000 If we had a computer that could execute a million instructions per second… It would take 584,000 years to complete But it could get worse…

The Bounded Tile Problem Match up the patterns in the tiles. Can it be done, yes or no?

The Bounded Tile Problem Matching tiles

Tiling a 5x5 Area 25 available tiles remaining

Tiling a 5x5 Area 24 available tiles remaining

Tiling a 5x5 Area 23 available tiles remaining

Tiling a 5x5 Area 22 available tiles remaining

Tiling a 5x5 Area 2 available tiles remaining

Analysis of the Bounded Tiling Problem Tile a 5 by 5 area (N = 25 tiles) 1st location: 25 choices 2nd location: 24 choices And so on… Total number of arrangements: –25 * 24 * 23 * 22 * 21 *.... * 3 * 2 * 1 –25! (Factorial) = 15,500,000,000,000,000,000,000,000 Bounded Tiling Problem is O(N!)

Tiling (N!) Runtime For N = 25 25! = 15,500,000,000,000,000,000,000,000 If we could “place” a million tiles per second… It would take 470 billion years to complete Why not a faster computer?

A Faster Computer If we had a computer that could execute a trillion instructions per second (a million times faster than our MIPS computer)… 5x5 tiling problem would take 470,000 years 64-ring Tower of Hanoi problem would take 213 days Why not an even faster computer!

Where Does this Leave Us? Clearly algorithms have varying runtimes. We’d like a way to categorize them: –Reasonable, so it may be useful –Unreasonable, so why bother running

Performance Categories of Algorithms Sub-linear O(Log N) Linear O(N) Nearly linear O(N Log N) Quadratic O(N 2 ) Exponential O(2 N ) O(N!) O(N N ) Polynomial

Cost and Complexity Algorithm complexity can be expressed in Order notation, e.g. “at what rate does work grow with N?”: –O(1)Constant –O(logN)Sub-linear –O(N)Linear –O(NlogN)Nearly linear –O(N 2 )Quadratic –O(X N )Exponential But, for a given problem, how do we know if a better algorithm is possible?

The Problem of Sorting For example, in discussing the problem of sorting: Two algorithms to solve: –Bubblesort – O(N 2 ) –Mergesort – O(N Log N) Can we do better than O(N Log N)?

Algorithm vs. Problem Complexity Algorithmic complexity is defined by analysis of an algorithm Problem complexity is defined by –An upper bound – defined by an algorithm –A lower bound – defined by a proof

The Upper Bound Defined by an algorithm Defines that we know we can do at least this well Perhaps we can do better Lowered by a better algorithm –“When I was a boy I knew only about Bubblesort with O(N 2 ). Today I am a man I have learned Mergesort with O(NlogN).” John Wayne in “True Algorithms” 1954

The Lower Bound Defined by a proof Defines that we know we can do no better than this It may be worse Raised by a better proof –“For comparison sorting you can probably prove that sorting must have a O(N). I can prove that sorting has O(NlogN).”

Upper and Lower Bounds The Upper bound is the best algorithmic solution that has been found for a problem. –“What’s the best that we know we can do?” The Lower bound is the best solution that is theoretically possible. –“What cost can we prove is necessary?”

Changing the Bounds Upper bound Lowered by better algorithm Lower bound Raised by better proof

Open Problems The upper and lower bounds differ. Upper bound Lowered by better algorithm Lower bound Raised by better proof Unknown

Closed Problems The upper and lower bounds are identical. Upper bound Lower bound

Closed Problems Better algorithms are still possible Better algorithms will not provide an improvement detectable by “Big O” Better algorithms can improve the constant costs hidden in “Big O” characterizations

Tractable vs. Intractable Problems are tractable if the upper and lower bounds have only polynomial factors. –O (log N) –O (N) –O (N K ) where K is a constant Problems are intractable if the upper and lower bounds have an exponential factor. –O (N!) –O (N N ) –O (2 N )

Problems that “Cross the Line” The upper bound implies intractable The lower bound implies a tractable Could go either way…

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 [sub-network frequencies] Scheduling – classes, airlines Matching (bin packing) 2-D arrangement problems Planning problems (pert planning) First-order Predicate Calculus

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 –No rooms double booked

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 there are a finite number of steps, but you don’t know which to take when.) 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).

Why are we telling you all this? If you are working on a tough problem and you can prove that it’s NP-Complete you can: –a. Take the rest of the day off. –b. Luck out and find a solution –c. Use an approximation algorithm

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.

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

Questions?