Top Banner
Complexity Theory CSE 331 Section 2 James Daly
25

Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Dec 19, 2015

Download

Documents

Barbra Kennedy
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Complexity Theory

CSE 331Section 2James Daly

Page 2: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Reminders

• Project 4 is out• Due Friday• Dynamic programming project

• Homework 6 is out• Due next week (on the last day of class)• Last homework• Covers greedy algorithms and dynamic

programming

Page 3: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Review: Sorting

• We discussed several sorting algorithms in class• Insertion Sort• Selection Sort• Quick Sort• Merge Sort• Heap Sort

• Each has various tradeoffs• Some are more efficient then others

Page 4: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Algorithm Theory

• An algorithm is a solution to a problem• Some problems have no efficient

algorithms to solve them• Some problems have no solution at all• The complexity of a problem is the

complexity of the best algorithm for solving the problem• Finding the max of an unsorted array: O(n)• Comparison-based sorting: O(n log n)

Page 5: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Finite Automata (FA)

• Very simple machine• Fixed number of states

• One starting state• Some “accepting” states

• Reads a string one symbol at a time• Moves to a new state based on the symbol• Returns whether it ends in an accepting

state

Page 6: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Example

SA

F11

1

00

0

0 1 0 0

Accept!

Page 7: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Example

SA

F11

1

00

0

0 1 1

Reject!

Page 8: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Nondeterministic Finite Automata (NFA)

• Special type of FA• States can have multiple transitions with

the same symbol• Takes all of them!

• Is in a superposition of states

• Accepts if any of them accept

Page 9: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Example

a b

*

Accepts any string ending in ab

Page 10: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Turing Machine

• An idealized computer capable of running any program

• Only slightly more powerful than an actual computer (they have infinite memory)

• Also has deterministic and non-deterministic versions

Page 11: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Class P

• An algorithm runs in polynomial time if its running time is O(nk) for some constant k• Polynomial time is better than exponential

time: O(2n)

• P is the class of problems solvable in polynomial time• We consider these to have “efficient” solutions

Page 12: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Class NP

• Class of problems solvable in polynomial time on a non-deterministic machine

• Can be verified but not necessarily solved in polynomial time on a normal (deterministic) machine

• Does not stand for “non-polynomial”

Page 13: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Decision Problems

• Yes / No (Boolean) problem• Can turn an optimization problem into a

decision problem by adding a target number

• Example:• Shortest path problem: Optimization problem• Decision version: Is there a path of size k or

less?

Page 14: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

NP-Complete (NPC)

• Class of decision problems• Properties

• Must be in class NP (verifiable in polynomial time)

• Must be in class NP-Hard (at least as difficult as anything in NP)

Page 15: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

NP

P

NP-Hard

NPC

P ≠ NP

NP-Hard

P = NP = NPC

P = NP

Page 16: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Completeness Theory

• If any NPC problem can be solved in polynomial time, then all NPC problems have polynomial time solutions (P = NP)• Whether this is the case or not is unknown

• One of the most important open problems• Millennium Prize: $1 million if you can answer it

• Most believe that P ≠ NP

Page 17: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Satisfiability (SAT)

• Let x1, x2, …, xn be Boolean variables

• Given a Boolean expression in conjunctive normal form (CNF), does there exist a variable assignment that makes it true?

• First known NP-complete problem

Page 18: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Maximum Clique

• A clique is a sub-graph of G where each vertex shares an edge with every other vertex

• Maximum clique problem: find the clique containing the largest number of vertices in G

• Decision problem: does a clique of at least k vertices exist within G?

Page 19: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Maximum Clique

Page 20: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Knapsack problem

• You can carry up to k kg in your backpack• There are a variety of items, each with

some value and weight• Maximize the value of the items you put in

your bag

15 kg capacity

$412 kg

$22 kg

$21 kg

$11 kg

$104 kg

Value: $15, Weight: 7 kg

Page 21: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Travelling Salesman Problem

• Give a list of cities and roads between them (a graph), find the shortest tour that visits each city

A B

C D

20

34

12

4230 35

Page 22: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Proving Hardness

• It is often helpful to prove a problem is NP-complete

• This is normally done by converting between problems• If you can solve the new problem, you can

solve the original

Page 23: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Proving Hardness

• If you can convert from an NP-complete problem to your problem, it must be NP-hard.

• If you can also convert back, then it is NP-complete

Page 24: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Maximum Independent Set (MIS)

• In a graph, an independent set is a set of vertices where no edge connects two vertices in the set.

• The MIS is the largest such set in the graph

Page 25: Complexity Theory CSE 331 Section 2 James Daly. Reminders Project 4 is out Due Friday Dynamic programming project Homework 6 is out Due next week (on.

Conversion

• Finding an independent set on G is the same as finding a clique on the complement of G (reversing whether edges exist)

• Since max clique is NP-complete, so is MIS

Max Clique MIS