CSCI 333 The Hard and Impossible - PowerPoint PPT Presentation

About This Presentation
Title:

CSCI 333 The Hard and Impossible

Description:

Or use the card analogy. Hard Problems. Requires (cn) for c 1. Time = 420 ... Examples of proven hard problems. Few exist. And they seem rather contrived... – PowerPoint PPT presentation

Number of Views:86
Avg rating:3.0/5.0
Slides: 19
Provided by: clif67
Learn more at: https://www.cs.unca.edu
Category:

less

Transcript and Presenter's Notes

Title: CSCI 333 The Hard and Impossible


1
CSCI 333The Hard and Impossible
  • Chapter 15
  • 4 and 6 December 2002

2
The Worst Sort
  • BumbleSort(int A, int Size)
  • while (NotSorted(A, Size))
  • int i Random(Size)
  • unt j Random(Size)
  • Swap(AI, Aj)
  • Solves the problems in average time of O(n!)
  • That is, in centuries for decent sized lists

3
The Best Sort
  • n! different permutations of the data
  • Decision tree could cover all possibilities
  • n! leaves
  • O(log n!) height
  • O(log n!) O(n log n)
  • No sort can be better than O(n log n)

4
Reduction
Input transformation
Problem A
Problem B
Output transformation
5
Whats wrong with this picture?
Input transformation O(n)
Sorting
Pairing O(n)
Output transformation O(n)
6
Why some problemsare unsolvable
  • More problems than programs
  • Programs are countable
  • Problems are uncountable
  • Halting problem is unsolvable
  • Cant write a function Halt such that
  • Halt(f) is true if f(0) returns a value
  • Halt(f) is false if f(0) gets in a loop

7
Post Correspondence Problem
  • Given two equal size vectors of strings
  • S s1, s2, , sn
  • T t1, t2, , tn
  • Can you find a sequence of indices
  • i1, i2, im
  • Such that
  • si1 si2 sim ti1 ti2 tim
  • Or use the card analogy

8
Hard Problems
  • Requires ?(cn) for c gt 1

9
Examples of proven hard problems
  • Few exist
  • And they seem rather contrived
  • So, whats the problem?
  • For the lack of problems

10
Knapsack problem
  • Given a collection, W, of items of weight
  • w1, w2, wn
  • And a target weight K
  • Is there are subset of W whose sum is K?

11
Exponential solution
  • bool KnapSack(int W, int N, int K)
  • bool ChoicesN
  • initPerm(Choices, N) // all false
  • foundSolution false
  • morePerms false
  • while (! foundSolution morePerms) // 2N
  • if (exactFit(W, Choices, N, K))
  • foundSolution true
  • else
  • morePerms nextPerm(Choices, N)
  • return foundSolution

12
Exponential solution part 2
  • void initPerm(int Choices, int N)
  • for (int i0 iltN i)
  • ChoicesN false
  • bool nextPerm(int Choices, int N)
  • int i
  • for (int i0 iltN Choicesi i)
  • Choicesi false
  • if (i N)
  • return false // All permutations are done!
  • ChoicesI true
  • return true

13
Exponential solution part 3
  • bool exactFit(int W, bool C,
  • int N, int K)
  • int sum 0
  • for (int i0 iltN i)
  • if Choicesi)
  • sum sum Wi
  • return sum W

14
Exponential solution part 3
  • bool exactFit(int W, bool C,
  • int N, int K)
  • int sum 0
  • for (int i0 iltN i)
  • if Choicesi)
  • sum sum Wi
  • return sum W

15
Non-deterministic solution
  • Quija bool KnapSack(int W, int N,
  • int K)
  • bool ChoicesN
  • for (int I0 IltN I)
  • ChoicesI Quija(false, true)
  • return exactFit(W, Choices, N, K)

16
P NP?
  • Clearly NP includes P
  • Is there a problem that is in NP,
  • but not in P?

17
NP Completeness
  • A Problem is NP complete if
  • It is NP
  • All other NP programs can be reduced to it
  • In polynomial time

18
NP Complete Problems
  • Knapsack
  • Traveling salesman
  • Hamiltonian cycle
  • Boolean satisfiability
  • Class scheduling problem
  • Minesweeper consistency problem
Write a Comment
User Comments (0)
About PowerShow.com