Algorithmic Complexity Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.

Slides:



Advertisements
Similar presentations
Growth-rate Functions
Advertisements

Fundamentals of Python: From First Programs Through Data Structures
CMPT 225 Sorting Algorithms Algorithm Analysis: Big O Notation.
Chapter 9: Searching, Sorting, and Algorithm Analysis
Algorithmic Complexity Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
CS 206 Introduction to Computer Science II 09 / 10 / 2008 Instructor: Michael Eckmann.
Midterm 2 Overview Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Introduction to Analysis of Algorithms
Scott Grissom, copyright 2004 Chapter 5 Slide 1 Analysis of Algorithms (Ch 5) Chapter 5 focuses on: algorithm analysis searching algorithms sorting algorithms.
Complexity Analysis (Part I)
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
Object (Data and Algorithm) Analysis Cmput Lecture 5 Department of Computing Science University of Alberta ©Duane Szafron 1999 Some code in this.
Algorithmic Complexity 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Algorithmic Complexity 2 Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
Final Overview Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 3: The Efficiency of Algorithms Invitation to Computer Science, C++ Version, Third Edition Additions by Shannon Steinfadt SP’05.
CS2336: Computer Science II
Algorithmic Complexity 3 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Algorithm Analysis (Big O)
CSE 5311 DESIGN AND ANALYSIS OF ALGORITHMS. Definitions of Algorithm A mathematical relation between an observed quantity and a variable used in a step-by-step.
COMP s1 Computing 2 Complexity
COMPSCI 102 Introduction to Discrete Mathematics.
Time Complexity Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
Algorithm Analysis & Complexity We saw that a linear search used n comparisons in the worst case (for an array of size n) and binary search had logn comparisons.
Introduction to Analysing Costs 2015-T2 Lecture 10 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Rashina.
{ CS203 Lecture 7 John Hurley Cal State LA. 2 Execution Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
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.
Analysis of Algorithms CSCI Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it.
Grading Exams 60 % Lab 20 % Participation 5% Quizes 15%
Algorithm Analysis (Algorithm Complexity). Correctness is Not Enough It isn’t sufficient that our algorithms perform the required tasks. We want them.
Asymptotic Notation (O, Ω, )
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified for use by MSU Dept. of Computer Science.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Computer Science and Software Engineering University of Wisconsin - Platteville 8. Comparison of Algorithms Yan Shi CS/SE 2630 Lecture Notes Part of this.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Sorting.
CS 206 Introduction to Computer Science II 09 / 18 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 01 / 30 / 2009 Instructor: Michael Eckmann.
Algorithm Analysis (Big O)
Complexity Analysis. 2 Complexity The complexity of an algorithm quantifies the resources needed as a function of the amount of input data size. The resource.
CS 150: Analysis of Algorithms. Goals for this Unit Begin a focus on data structures and algorithms Understand the nature of the performance of algorithms.
Searching Topics Sequential Search Binary Search.
Algorithm Analysis Lakshmish Ramaswamy. What Constitutes Good Software? Code correctness Good design Code reusability OO design can help us in achieving.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
Algorithm Analysis 1.
COP 3503 FALL 2012 Shayan Javed Lecture 15
Algorithmic Efficency
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Computer Science 112 Fundamentals of Programming II
Introduction to Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Sorting by Tammy Bailey
Algorithm Analysis (not included in any exams!)
Building Java Programs
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
CS 201 Fundamental Structures of Computer Science
Chapter 2.
Algorithm Analysis Bina Ramamurthy CSE116A,B.
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Introduction to Discrete Mathematics
8. Comparison of Algorithms
Analysis of Algorithms
At the end of this session, learner will be able to:
Sum this up for me Let’s write a method to calculate the sum from 1 to some n public static int sum1(int n) { int sum = 0; for (int i = 1; i
Presentation transcript:

Algorithmic Complexity Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park

Where We Are OO software development Algorithms & data structures Asymptotic analysis Data structures Linear Hierarchical Unstructured Advanced Java Collections Threads So far Coming up

Algorithm Efficiency Efficiency Amount of resources used by algorithm Time, space Measuring efficiency Benchmarking Asymptotic analysis

Benchmarking Approach Pick some desired inputs Actually run implementation of algorithm Measure time & space needed Industry benchmarks SPEC – CPU performance MySQL – Database applications WinStone – Windows PC applications MediaBench – Multimedia applications Linpack – Numerical scientific applications

Benchmarking Advantages Precise information for given configuration Implementation, hardware, inputs Disadvantages Affected by configuration Data sets (usually too small) Hardware Software Affected by special cases (biased inputs) Does not measure intrinsic efficiency

Asymptotic Analysis Approach Mathematically analyze efficiency Calculate time as function of input size n T  O[ f(n) ] T is on the order of f(n) “Big O” notation Advantages Measures intrinsic efficiency Dominates efficiency for large input sizes

Search Example Number guessing game Pick a number between 1…n Guess a number Answer “correct”, “too high”, “too low” Repeat guesses until correct number guessed

Linear Search Algorithm Algorithm 1. Guess number = 1 2. If incorrect, increment guess by 1 3. Repeat until correct Example Given number between 1…100 Pick 20 Guess sequence = 1, 2, 3, 4 … 20 Required 20 guesses

Linear Search Algorithm Analysis of # of guesses needed for 1…n If number = 1, requires 1 guess If number = n, requires n guesses On average, needs n/2 guesses Time = O( n ) = Linear time

Binary Search Algorithm Algorithm 1. Set  to n/4 2. Guess number = n/2 3. If too large, guess number –  4. If too small, guess number +  5. Reduce  by ½ 6. Repeat until correct

Binary Search Algorithm Example Given number between 1…100 Pick 20 Guesses = 50,  = 25,Answer = too large, subtract  25,  = 12,Answer = too large, subtract  13,  = 6,Answer = too small, add  19,  = 3,Answer = too small, add  22,  = 1,Answer = too large, subtract  21,  = 1,Answer = too large, subtract  20 Required 7 guesses

Binary Search Algorithm Analysis of # of guesses needed for 1…n If number = n/2, requires 1 guess If number = 1, requires log 2 ( n ) guesses If number = n, requires log 2 ( n ) guesses On average, needs log 2 ( n ) guesses Time = O( log 2 ( n ) ) = Log time

Search Comparison For number between 1…100 Simple algorithm = 50 steps Binary search algorithm = log 2 ( n ) = 7 steps For number between 1…100,000 Simple algorithm = 50,000 steps Binary search algorithm = log 2 ( n ) = 77 steps Binary search is much more efficient!

Asymptotic Complexity Comparing two linear functions SizeRunning Time n/24n

Asymptotic Complexity Comparing two functions n/2 and 4n+3 behave similarly Run time roughly doubles as input size doubles Run time increases linearly with input size For large values of n Time(2n) / Time(n) approaches exactly 2 Both are O(n) programs

Asymptotic Complexity Comparing two log functions SizeRunning Time log 2 ( n )5 * log 2 ( n )

Asymptotic Complexity Comparing two functions log 2 ( n ) and 5 * log 2 ( n ) + 3 behave similarly Run time roughly increases by constant as input size doubles Run time increases logarithmically with input size For large values of n Time(2n) – Time(n) approaches constant Base of logarithm does not matter Simply a multiplicative factor log a N = (log b N) / (log b a) Both are O( log(n) ) programs

Asymptotic Complexity Comparing two quadratic functions SizeRunning Time n2n2 2 n

Asymptotic Complexity Comparing two functions n 2 and 2 n behave similarly Run time roughly increases by 4 as input size doubles Run time increases quadratically with input size For large values of n Time(2n) / Time(n) approaches 4 Both are O( n 2 ) programs

Observations Big O categories O(log(n)) O(n) O(n 2 ) For large values of n Any O(log(n)) algorithm is faster than O(n) Any O(n) algorithm is faster than O(n 2 ) Asymptotic complexity is fundamental measure of efficiency

Comparison of Complexity