Module #7: Algorithmic Complexity Rosen 5 th ed., §2.3.

Slides:



Advertisements
Similar presentations
College of Information Technology & Design
Advertisements

MATH 224 – Discrete Mathematics
Analysis of Algorithms
Discrete Structures CISC 2315
Lecture: Algorithmic complexity
CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
CompSci 102 Discrete Math for Computer Science
CSE115/ENGR160 Discrete Mathematics 02/28/12
Chapter 1 – Basic Concepts
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Tyler Robison Summer
Chapter 10 Algorithm Efficiency
CSC401 – Analysis of Algorithms Lecture Notes 1 Introduction
CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.
Eleg667/2001-f/Topic-1a 1 A Brief Review of Algorithm Design and Analysis.
Analysis of Algorithms CS 477/677
CS3381 Des & Anal of Alg ( SemA) City Univ of HK / Dept of CS / Helena Wong 2. Analysis of Algorithms - 1 Analysis.
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
CSE115/ENGR160 Discrete Mathematics 03/10/11
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
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.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis (Big O)
Algorithms. Problems, Algorithms, Programs Problem - a well defined task. –Sort a list of numbers. –Find a particular item in a list. –Find a winning.
Chapter Complexity of Algorithms –Time Complexity –Understanding the complexity of Algorithms 1.
How difficult is it to solve a problem?. Computability and Feasibility  Can a specific problem be solved by computation?  If so, can a suitably efficient.
Chapter 2.6 Comparison of Algorithms modified from Clifford A. Shaffer and George Bebis.
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.
Introduction to complexity. 2 Analysis of Algorithms Why do we need to analyze algorithms? –To measure the performance –Comparison of different algorithms.
Data Structures and Algorithms Lecture 5 and 6 Instructor: Quratulain Date: 15 th and 18 th September, 2009 Faculty of Computer Science, IBA.
2.3 Functions A function is an assignment of each element of one set to a specific element of some other set. Synonymous terms: function, assignment, map.
DISCRETE MATHEMATICS I CHAPTER 11 Dr. Adam Anthony Spring 2011 Some material adapted from lecture notes provided by Dr. Chungsim Han and Dr. Sam Lomonaco.
Lecture 30. P, NP and NP Complete Problems 1. Recap Data compression is a technique to compress the data represented either in text, audio or image form.
The Complexity of Optimization Problems. Summary -Complexity of algorithms and problems -Complexity classes: P and NP -Reducibility -Karp reducibility.
Analysis of Algorithms
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
Unsolvability and Infeasibility. Computability (Solvable) A problem is computable if it is possible to write a computer program to solve it. Can all problems.
Fundamentals CSE 373 Data Structures Lecture 5. 12/26/03Fundamentals - Lecture 52 Mathematical Background Today, we will review: ›Logs and exponents ›Series.
Fall 2002CMSC Discrete Structures1 Enough Mathematical Appetizers! Let us look at something more interesting: Algorithms.
MCA-2012Data Structure1 Algorithms Rizwan Rehman CCS, DU.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
CSCI 3160 Design and Analysis of Algorithms Tutorial 10 Chengyu Lin.
Cliff Shaffer Computer Science Computational Complexity.
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
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.)
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
Searching Topics Sequential Search Binary Search.
Chapter 12 Theory of Computation Introduction to CS 1 st Semester, 2014 Sanghyun Park.
Lecture 4 Jianjun Hu Department of Computer Science and Engineerintg University of South Carolina CSCE350 Algorithms and Data Structure.
Ch03-Algorithms 1. Algorithms What is an algorithm? An algorithm is a finite set of precise instructions for performing a computation or for solving a.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
CSE15 Discrete Mathematics 03/06/17
COT 3100, Spring 2001 Applications of Discrete Structures
CSE15 Discrete Mathematics 03/13/17
COMP108 Algorithmic Foundations Algorithm efficiency
Analysis of Algorithms & Orders of Growth
Enough Mathematical Appetizers!
Computation.
Efficiency (Chapter 2).
Module #7: Algorithmic Complexity
Applied Discrete Mathematics Week 6: Computation
Discrete Mathematics CS 2610
Discrete Mathematics and its Applications
Module #7: Algorithmic Complexity
Enough Mathematical Appetizers!
Enough Mathematical Appetizers!
Presentation transcript:

Module #7: Algorithmic Complexity Rosen 5 th ed., §2.3

What is complexity? The word complexity has a variety of technical meanings in different fields. There is a field of complex systems, which studies complicated, difficult-to- analyze non-linear and chaotic natural & artificial systems. We will study algorithmic complexity.

§2.3: Algorithmic Complexity The algorithmic complexity of a computation is some measure of how difficult it is to perform the computation. Measures some aspect of cost of computation (in a general sense of cost). Common complexity measures: –“Time” complexity: # of ops or steps required –“Space” complexity: # of memory bits req’d

Complexity Depends on Input Most algorithms have different complexities for inputs of different sizes. (E.g. searching a long list takes more time than searching a short one.) Therefore, complexity is usually expressed as a function of input length. This function usually gives the complexity for the worst-case input of any given length.

Complexity & Orders of Growth Suppose algorithm A has worst-case time complexity (w.c.t.c., or just time) f(n) for inputs of length n, while algorithm B (for the same task) takes time g(n). Suppose that f  (g), also written as Which algorithm will be fastest on all sufficiently-large, worst-case inputs?

Example 1: Max algorithm Problem: Find the simplest form of the exact order of growth (  ) of the worst- case time complexity (w.c.t.c.) of the max algorithm, assuming that each line of code takes some constant time every time it is executed (with possibly different times for different lines of code).

Complexity analysis of max procedure max(a 1, a 2, …, a n : integers) v := a 1 t 1 for i := 2 to nt 2 if a i > v then v := a i t 3 return vt 4 What’s an expression for the exact total worst-case time? (Not its order of growth.) Times for each execution of each line.

Complexity analysis, cont. procedure max(a 1, a 2, …, a n : integers) v := a 1 t 1 for i := 2 to nt 2 if a i > v then v := a i t 3 return vt 4 w.c.t.c.: Times for each execution of each line.

Complexity analysis, cont. Now, what is the simplest form of the exact (  ) order of growth of t(n)?

Example 2: Linear Search procedure linear search (x: integer, a 1, a 2, …, a n : distinct integers) i := 1t 1 while (i  n  x  a i )t 2 i := i + 1t 3 if i  n then location := it 4 else location := 0t 5 return locationt 6

Linear search analysis Worst case time complexity order: Best case: Average case, if item is present:

Review §2.3: Complexity Algorithmic complexity = cost of computation. Focus on time complexity (space & energy are also important.) Characterize complexity as a function of input size: Worst-case, best-case, average-case. Use orders of growth notation to concisely summarize growth properties of complexity fns.

Example 3: Binary Search procedure binary search (x:integer, a 1, a 2, …, a n : distinct integers) i := 1 j := n while i a m then i := m+1 else j := m end if x = a i then location := i else location := 0 return location  (1) Key question: How many loop iterations?

Binary search analysis Suppose n=2 k. Original range from i=1 to j=n contains n elems. Each iteration: Size j  i+1 of range is cut in half. Loop terminates when size of range is 1=2 0 (i=j). Therefore, number of iterations is k = log 2 n =  (log 2 n)=  (log n) Even for n  2 k (not an integral power of 2), time complexity is still  (log 2 n) =  (log n).

Names for some orders of growth  (1)Constant  (log c n)Logarithmic (same order  c)  (log c n)Polylogarithmic  (n)Linear  (n 2 )quadratic  (n 3 )cubic  (n c )Polynomial  (c n ), c>1Exponential  (n!)Factorial (With c a constant.)

Problem Complexity The complexity of a computational problem or task is (the order of growth of) the complexity of the algorithm with the lowest order of growth of complexity for solving that problem or performing that task. E.g. the problem of searching an ordered list has at most logarithmic time complexity. (Complexity is O(log n).)

Tractable vs. intractable A problem or algorithm with at most polynomial time complexity is considered tractable (or feasible). P is the set of all tractable problems. A problem or algorithm that has more than polynomial complexity is considered intractable (or infeasible). Note that n 1,000,000 is technically tractable, but really impossible. n log log log n is technically intractable, but easy. Such cases are rare though.

Unsolvable problems Turing discovered in the 1930’s that there are problems unsolvable by any algorithm. –Or equivalently, there are undecidable yes/no questions, and uncomputable functions. Example: the halting problem. –Given an arbitrary algorithm and its input, will that algorithm eventually halt, or will it continue forever in an “infinite loop?”

The Halting Problem (Turing ’36) The function is Halt(P) –Given program P, it can determine whether P eventually terminates.” –True if P terminates; False otherwise Theorem: Halt is uncomputable! –I.e., There does not exist any algorithm A that computes Halt correctly for all possible inputs. Corollary: General impossibility of predictive analysis of arbitrary computer programs. Textbook p

The Proof Consider algorithm Paradox, defined as: procedure Paradox if Halt(Paradox) then while T begin end If Paradox halts, then Halt(Paradox) = T –Then total procedure loops forever! Nonsense! If Paradox loops forever, then Halt(Paradox) = F –Then total procedure halts! Nonsense either! So there cannot exist a function Halt!

Another version Consider algorithm K, defined as: procedure K(P) if Halt(P) then while T begin end How about K(K)? If Halt(K) is false, then K(K) terminates. –Nonsense! If Halt(K) is true, then K(K) loops forever –Nonsense, either!

P vs. NP P is the set of problems solved by a tractable algorithm P stands for polynomial (time) NP is the set of problems for which there exists a tractable algorithm for checking solutions to see if they are correct. NP stands for nondeterministic polynomial (time)

P vs. NP We know P  NP, but the most famous unproven conjecture in computer science is that this inclusion is proper (i.e., that P  NP rather than P=NP). Whoever first proves it will be famous!

Computer Time Examples Assume time = 1 ns (10  9 second) per op, problem size = n bits, #ops a function of n as shown. (125 kB)(1.25 bytes)

Things to Know Definitions of algorithmic complexity, time complexity, worst-case complexity; names of orders of growth of complexity. How to analyze the worst case, best case, or average case order of growth of time complexity for simple algorithms.