Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.

Slides:



Advertisements
Similar presentations
Discrete Structures CISC 2315
Advertisements

HST 952 Computing for Biomedical Scientists Lecture 10.
ALG0183 Algorithms & Data Structures Lecture 7 Big-Oh, Big-Omega, Big-Theta, Little-Oh 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
CS 206 Introduction to Computer Science II 09 / 10 / 2008 Instructor: Michael Eckmann.
Introduction to Analysis of Algorithms
CS 307 Fundamentals of Computer Science 1 Asymptotic Analysis of Algorithms (how to evaluate your programming power tools) based on presentation material.
1 TCSS 342, Winter 2005 Lecture Notes Course Overview, Review of Math Concepts, Algorithm Analysis and Big-Oh Notation Weiss book, Chapter 5, pp
25 June 2015Comp 122, Spring 2004 Asymptotic Notation, Review of Functions & Summations.
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 2 Elements of complexity analysis Performance and efficiency Motivation: analysis.
CS2420: Lecture 4 Vladimir Kulyukin Computer Science Department Utah State University.
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
Algorithm Efficiency and Sorting Bina Ramamurthy CSE116A,B.
Data Structures CS 310. Abstract Data Types (ADTs) An ADT is a formal description of a set of data values and a set of operations that manipulate the.
Data Structure Algorithm Analysis TA: Abbas Sarraf
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Cpt S 223 – Advanced Data Structures
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 COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis (Big O)
CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis Aaron Bauer Winter 2014.
Chapter 6 Algorithm Analysis Bernard Chen Spring 2006.
1 Chapter 2 Program Performance – Part 2. 2 Step Counts Instead of accounting for the time spent on chosen operations, the step-count method accounts.
Algorithm Analysis. Algorithm An algorithm is a clearly specified set of instructions which, when followed, solves a problem. recipes directions for putting.
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
Analysis of Algorithms
Analysis of Algorithm Efficiency Dr. Yingwu Zhu p5-11, p16-29, p43-53, p93-96.
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Introduction to Analysis of Algorithms COMP171 Fall 2005.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Zeinab EidAlgorithm Analysis1 Chapter 4 Analysis Tools.
Algorithm Analysis Data Structures and Algorithms (60-254)
Computer Science and Software Engineering University of Wisconsin - Platteville 8. Comparison of Algorithms Yan Shi CS/SE 2630 Lecture Notes Part of this.
3.3 Complexity of Algorithms
Algorithm Analysis Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Algorithm Analysis O Ω.
Recap Introduction to Algorithm Analysis Different Functions Function’s Growth Rate Three Problems Related to Algorithm Running Time Find Minimum in an.
Introduction to Analysis of Algorithms CS342 S2004.
Algorithmic Analysis Charl du Plessis and Robert Ketteringham.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 2 Prepared by İnanç TAHRALI.
Algorithm Analysis Part of slides are borrowed from UST.
Sorting.
Algorithm Analysis Chapter 5. Algorithm An algorithm is a clearly specified set of instructions which, when followed, solves a problem. –recipes –directions.
CISC 235: Topic 1 Complexity of Iterative Algorithms.
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.
2-0 Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 2 Theoretical.
Algorithm Analysis (Big O)
تصميم وتحليل الخوارزميات عال311 Chapter 3 Growth of Functions
Algorithm Analysis. What is an algorithm ? A clearly specifiable set of instructions –to solve a problem Given a problem –decide that the algorithm is.
CISC220 Spring 2010 James Atlas Lecture 07: Big O Notation.
DS.A.1 Algorithm Analysis Chapter 2 Overview Definitions of Big-Oh and Other Notations Common Functions and Growth Rates Simple Model of Computation Worst.
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 4.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
LECTURE 2 : fundamentals of analysis of algorithm efficiency Introduction to design and analysis algorithm 1.
Algorithm Analysis 1.
Introduction to complexity
Introduction to Algorithms
CS 201 Fundamental Structures of Computer Science
Programming and Data Structure
DS.A.1 Algorithm Analysis Chapter 2 Overview
Chapter 2.
Programming and Data Structure
8. Comparison of Algorithms
Presentation transcript:

Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2

Department of Computer Science2 Lectures - Today - Algorithm Analysis (Chapter 5 of Weiss)

Department of Computer Science3 Efficient Solutions An algorithm is efficient if:  Produces the desired solution  It is fast (low time complexity)  It consumes little memory (low space complexity) Algorithm analysis studies the time and space complexity of algorithms Mainly study time Appropriate data structures can reduce complexity

Department of Computer Science4 Basics Running time of an algorithm depends on the amount of data that needs to be processed We study the running time as a function of the size of the input Analysis of algorithms ignores:  Computing platform  Compiler  Quality of implementation

Department of Computer Science5 Growth Rates What matters for large input sizes is the growth rate  We can ignore constants and lower-order terms in polynomials The Big-Oh notation is used to capture the most dominant term  Used to represent the growth rate  Makes a mathematically sound statement

Department of Computer Science6 Functions and Growth FunctionName cConstant log NLogarithmic NLinearN log N N 2 Quadratic N 3 Cubic 2 N Exponential

Department of Computer Science7 Example Problems Consider  A = { -2, 11, -4, 13, -5, 2 } Problem: Find the maximum contiguous subsequence sum Solution: = 20

Department of Computer Science8 Solution 1 Brute force solution Compute all subsequences and save the one with the greatest sum Use 3 nested loops Simplest and most obvious solution (often the case) Complexity?

Department of Computer Science9 Solution 2 Remove innermost loop via observation that the sum can be done incrementally (rather than starting from scratch each time) This removes a loop so now we have only 2 Complexity?

Department of Computer Science10 Solution 3 Remove another loop via the observation that negative subsequences are never going to yield useful results Getting rid of loops like this is not always possible and most of the time gets harder as each loop is removed as with this problem

Department of Computer Science11 Big-Oh and Being Formal Big-Oh notation states that the running time T(N) is at most O(F(N)) where T(N) is within a constant of F(N) Big-Omega notation is used to express that T(N) grows at least as quickly as F(N) Big-Theta notation states that the growth rates of T(N) and F(N) are the same Little-Oh notation states that the growth rate of T(N) is strictly less than that of F(N)

Department of Computer Science12 Average and Worst-Case Actual runtime also depends on the type of input – not just size Worst-case bounds are based on the assumption of encountering the worst possible input  Eg Finding a person in phone book when you know their number (actual example would be last num in book!) Average-case bounds are based on the average or expected case  Usually harder to establish

Department of Computer Science13 Logarithms Many algorithms have bounds involving logs Two observations  Log (base B) N = K if B power K = N  Log (base B) N = O( log N) So base is irrelevant (we normally have B = 2)

Department of Computer Science14 Importance of Logs Number of bits used to represent N consecutive integers Gives the number of times we can double a number starting from 1 before we reach N (repeated doubling principle) – if I save $1 a year and double it how many years will it take to save $1,000,000? Repeated halving principle  Phonebook?

Department of Computer Science15 Searching Sequential search  O(N) comparisons in the worst and average case Binary search  O(log N) comparisons in the worst and average case (rep halving) Interpolation search  O(N) in worst-case  O(log log N) in average case

Department of Computer Science16 Limitations Big-Oh no good for small input (use simplest algorithm in this case) Constants can matter for some problems