Presentation is loading. Please wait.

Presentation is loading. Please wait.

04/04/13 Algorithms and NP Discrete Structures (CS 173) Derek Hoiem, University of Illinois 1.

Similar presentations


Presentation on theme: "04/04/13 Algorithms and NP Discrete Structures (CS 173) Derek Hoiem, University of Illinois 1."— Presentation transcript:

1 04/04/13 Algorithms and NP Discrete Structures (CS 173) Derek Hoiem, University of Illinois 1

2 Outline Algorithms – Karatsuba multiplication (maybe) – Example of dynamically created arrays Algorithm complexity – Sublinear, linear, linearithmic, quadratic, cubic, exponential, factorial – Worst case vs. average case NP vs. Exponential 2

3 Administrative Mini-homework released yesterday Long-form homework – Problems released on website today – Moodle boxes available on Friday Note: mini-hw is long, and long-form homework is short Tests will be released next week’s discussion – Do not discuss with those who haven’t taken it yet 3

4 This class Review of algorithms and big-O – Computing factorial series – Multiplying large numbers The master theorem Algorithmic complexity P vs. NP 4

5 Example: factorialSeries.m 5 See code Lesson 1: Be careful of implementation details that hide computational complexity Lesson 2: Knowing complexity of algorithm can help find major implementation flaws

6 Master theorem 6

7 7 Leaf term dominates (hyper expansion) Each level costs the same (balanced expansion) Top node dominates (slow expansion)

8 Master theorem 8 Example algorithm: multiplying large numbers

9 Master theorem 9 Example algorithm: sorting

10 Master theorem 10

11 Example: multiplying large numbers 11 Complexity:

12 Example: multiplying large numbers 12 Complexity:

13 Algorithm complexity constant, sublinear, linear, linearithmic, quadratic, cubic, exponential, factorial 13 time problem size http://en.wikipedia.org/wiki/Computational_complexity_of_mathematical_operations

14 Average-case vs. worst-case complexity Sometimes worst case is unlikely or avoidable – E.g., quicksort Average-case complexity describes behavior for a typical case 14

15 P vs. NP A problem is class P if a polynomial-time solution exists A problem is class NP (non-deterministic polynomial time) if a solution can be checked in polynomial time, but no known algorithm can generate the solution in polynomial time 15

16 Examples 16

17 Examples Sorting a set of integers How fast can you find a solution? How fast can you check a solution? P: sorting takes linearithmic time, and checking takes linear time 17

18 Examples 18

19 P = NP? 19

20 NP-complete and NP-hard 20

21 Examples Traveling salesman problem: determine an order of cities to visit that minimizes total travel time NP-hard: finding solution takes exponential time, checking solution is NP-complete 21

22 Things to remember Be able to analyze code for computational cost – Tools: finding loops and recursive calls, using recursion trees – Sometimes need to know inner-workings of a library to determine (e.g., factorialSeries) Be able to convert to big-O or big-Theta and be familiar with basic complexity terms – E.g., linear, nlogn, polynomial, exponential Problems in NP can be checked in polynomial time but probably not solved in polynomial time – P=NP is open problem, most think not 22


Download ppt "04/04/13 Algorithms and NP Discrete Structures (CS 173) Derek Hoiem, University of Illinois 1."

Similar presentations


Ads by Google