What is Computer Science About? Part 2: Algorithms

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

What is Computer Science About? Part 2: Algorithms.
P, NP, NP-Complete Problems
Introduction to Algorithms NP-Complete
NP-Hard Nattee Niparnan.
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Lecture 24 Coping with NPC and Unsolvable problems. When a problem is unsolvable, that's generally very bad news: it means there is no general algorithm.
Chapter 4 The Greedy Approach. Minimum Spanning Tree A tree is an acyclic, connected, undirected graph. A spanning tree for a given graph G=, where E.
The Theory of NP-Completeness
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
Introduction to Approximation Algorithms Lecture 12: Mar 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.
CSE 326: Data Structures NP Completeness Ben Lerner Summer 2007.
Chapter 11: Limitations of Algorithmic Power
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Approximation Algorithms Motivation and Definitions TSP Vertex Cover Scheduling.
Programming & Data Structures
1 Introduction to Approximation Algorithms. 2 NP-completeness Do your best then.
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:
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 11 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
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.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
Complexity Classes (Ch. 34) The class P: class of problems that can be solved in time that is polynomial in the size of the input, n. if input size is.
What is Computer Science About? Part 2: Algorithms.
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
CSE 024: Design & Analysis of Algorithms Chapter 9: NP Completeness Sedgewick Chp:40 David Luebke’s Course Notes / University of Virginia, Computer Science.
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.
1 Chapter 34: NP-Completeness. 2 About this Tutorial What is NP ? How to check if a problem is in NP ? Cook-Levin Theorem Showing one of the most difficult.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
Lecture. Today Problem set 9 out (due next Thursday) Topics: –Complexity Theory –Optimization versus Decision Problems –P and NP –Efficient Verification.
1. For minimum vertex cover problem in the following graph give
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
Algorithm Complexity By: Ashish Patel and Alex Golebiewski.
The NP class. NP-completeness Lecture2. The NP-class The NP class is a class that contains all the problems that can be decided by a Non-Deterministic.
Exhaustive search Exhaustive search is simply a brute- force approach to combinatorial problems. It suggests generating each and every element of the problem.
Approximation algorithms
TU/e Algorithms (2IL15) – Lecture 11 1 Approximation Algorithms.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
The Theory of NP-Completeness
Limitation of Computation Power – P, NP, and NP-complete
The NP class. NP-completeness
NP-completeness Ch.34.
Chapter 10 NP-Complete Problems.
Introduction to Approximation Algorithms
EMIS 8373: Integer Programming
Data Structures Lab Algorithm Animation.
CSCE 411 Design and Analysis of Algorithms
Optimization problems such as
Hard Problems Introduction to NP
Design & Analysis of Algorithm Greedy Algorithm
Lecture 22 Complexity and Reductions
NP-Completeness Yin Tat Lee
Analysis and design of algorithm
ICS 353: Design and Analysis of Algorithms
Approximation Algorithms
CLASSES P AND NP.
Graph Searching.
Chapter 11 Limitations of Algorithm Power
NP-Complete Problems.
CSC 380: Design and Analysis of Algorithms
NP-Completeness Reference: Computers and Intractability: A Guide to the Theory of NP-Completeness by Garey and Johnson, W.H. Freeman and Company, 1979.
P, NP and NP-Complete Problems
The Theory of NP-Completeness
P, NP and NP-Complete Problems
CSC 380: Design and Analysis of Algorithms
Major Design Strategies
Approximation Algorithms
Algorithms CSCI 235, Spring 2019 Lecture 36 P vs
Our old list of problems
Presentation transcript:

What is Computer Science About? Part 2: Algorithms

Design and Analysis of Algorithms Why we study algorithms: Many tasks can be reduced to abstract problems If we can recognize them, we can use known solutions

Example: Graph Algorithms Graphs could represent friendships among people, or adjacency of states on a map, or links between web pages... Determining connected components (reachability) Finding shortest path between two points MapQuest; Traveling Salesman Problem Finding cliques completely connected sub-graphs Uniquely matching up pairs of nodes e.g. a buddy system based on friendships Determining whether 2 graphs have same connectivity (isomorphism) Finding a spanning tree (acyclic tree that touches all nodes) minimal-cost communication networks

Kruskal’s Algorithm for Minimum-Spanning Trees // input: graph G with a set of vertices V // and edges (u,v) with weights (lengths) KRUSKAL(G): A = ∅ foreach vi  V: cluster[vi]  i // singletons foreach edge (u,v) ordered by increasing weight: if cluster[u] ≠ cluster[v]: A = A  {(u, v)} foreach w  V: if cluster[w] = cluster[u]: cluster[w]  cluster[v] // merge return A // subset of edges It is greedy Is it correct? (always produce MST?) Is it optimal? (how long does it take?)

Save the Gnomes! Rules Gnomes stand on staircase Gnomes can see gnomes below them Gnomes may not speak unless asked to Gnomes can hear the response of others Gnomes cannot see their own hat

Save the Gnomes! Game Start at top gnome Ask for the color of his hat (blue or red)

Save the Gnomes! Game Start at top gnome Ask for the color of his hat (blue or red) If he gets it wrong, he dies Continue to next gnome

Save the Gnomes! Game Start at top gnome Ask for the color of his hat (blue or red) If he gets it wrong, he dies Continue to next gnome Come up with a strategy that saves the most gnomes

Save the Gnomes! Game Start at top gnome Ask for the color of his hat (blue or red) If he gets it wrong, he dies Continue to next gnome Come up with a strategy that saves the most gnomes What’s the expected number of surviving gnomes? What’s the worst case?

Characterize algorithms in terms of efficiency Note: we count number of steps, rather than seconds Time is dependent on machine, compiler, load, etc... Optimizations are important for real-time sys., games Are there faster ways to sort a list? invert a matrix? find a completely connected sub-graph? Scalability for larger inputs (think: human genome): how much more time/memory does the algorithm take? Polynomial vs. exponential run-time (in the worst case) Depends a lot on the data structure (representation) Hash tables, binary trees, etc. can help a lot Proofs of correctness

Why do we care so much about polynomial run-time? Consider 2 programs that take an input of size n (e.g. length of a string, number of nodes in graph, etc.) Run-time of one scales up as n2 (polynomial), and the other as 2n (exponential)

Why do we care so much about polynomial run-time? Consider 2 programs that take an input of size n (e.g. length of a string number of nodes in graph, etc.) Run-time of one scales up as n2 (polynomial), and the other as 2n (exponential) Exponential algorithms are effectively “unsolvable” for n>~16 even if we used computers that were 100 times as fast! a computational “cliff”

Helpful rules of thumb: 210 ~ 1 thousand (1,024) (1 KB) 3 9 8 16 5 25 32 6 36 64 7 49 128 256 81 512 10 100 1024 11 121 2048 12 144 4096 13 169 8192 14 196 16384 15 225 32768 65536 17 289 131072 18 324 262144 19 361 524288 20 400 1048576 Helpful rules of thumb: 210 ~ 1 thousand (1,024) (1 KB) 220 ~ 1 million (1,048,576) (1 MB) 230 ~ 1 billion (1,073,741,824) (1 GB)

Moore’s Law (named after Gordon Moore, founder of Intel) Number of transistors on CPU chips appears to double about once every 18 months Similar statements hold for CPU speed, network bandwidth, disk capacity, etc. But waiting a couple years for computers to get faster is not an effective solution to NP-hard problems

P vs. NP (CSCE 411) Problems in “P”: solvable in polynomial time with a deterministic algorithm Examples: sorting a list, inverting a matrix... Problems in “NP”: solvable in polynomial time with a non-deterministic algorithm Given a “guess”, can check if it is a solution in polynomial time No known polynomial-time algorithm exists, and they would take exponential time to enumerate and try all the guesses in the worst case Example: given a set of k vertices in a graph, can check if they form a completely connected clique; but there are exponentially many possible sets to choose from

P vs. NP (CSCE 411) Most computer scientists believe P≠NP, though it has yet to be rigorously proved What does this mean? That there are intrinsically “hard” problems for which a polynomial-time algorithm will never be found P NP even harder problems (complexity classes) graph clique, subset cover, Traveling Salesman Problem, satisfiability of Boolean formulas, factoring of integers... sorting a list, inverting a matrix, minimum-spanning tree...

Many combinatorial problems are in NP Being able to recognize whether a problem is in P or NP is fundamentally important to a computer scientist Many combinatorial problems are in NP Knapsack problem (given n items with size wi and value vi, fit as many as possible items into a knapsack with a limited capacity of L that maximizes total value. Traveling salesman problem (shortest circuit visiting every city) Scheduling – e.g. of machines in a shop to minimize a manufacturing process Finding the shortest path in a graph between 2 nodes is in P There is an algorithm that scales-up polynomially with size of graph: Djikstra’s algorithm However, finding the longest path is in NP! Applications to logistics, VLSI circuit layout...

Not all hope is lost... Even if a problem is in NP, there might be an approximation algorithm to solve it efficiently (in polynomial time) However, it is important to determine the error bounds. For example, an approx. alg. might find a subset cover that is “no more than twice the optimal size” A simple greedy algorithm for the knapsack problem: Put in item with largest weight-to-value ratio first, then next largest, and so on... Can show that will fill knapsack to within 2 times the optimal value