Analyzing an Algorithm Computing the Order of Magnitude Big O Notation

Slides:



Advertisements
Similar presentations
Chapter 20 Computational complexity. This chapter discusses n Algorithmic efficiency n A commonly used measure: computational complexity n The effects.
Advertisements

Growth-rate Functions
College of Information Technology & Design
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 2: Basics Data Structures.
11.2 Complexity Analysis. Complexity Analysis As true computer scientists, we need a way to compare the efficiency of algorithms. Should we just use a.
Analysys & Complexity of Algorithms Big Oh Notation.
Complexity Analysis (Part I)
Lecture 3 Aug 31, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis discussion of lab – permutation generation.
Elementary Data Structures and Algorithms
Lecture 3 Feb 7, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis Image representation Image processing.
Algorithm Analysis (Big O)
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
1 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
{ 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)
Data Structures and Algorithms Lecture 5 and 6 Instructor: Quratulain Date: 15 th and 18 th September, 2009 Faculty of Computer Science, IBA.
Analysis of Algorithms
Algorithm Evaluation. What’s an algorithm? a clearly specified set of simple instructions to be followed to solve a problem a way of doing something What.
Big Oh Algorithms are compared to each other by expressing their efficiency in big-oh notation Big O notation is used in Computer Science to describe the.
Analysis of Algorithms CSCI Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it.
Algorithm Analysis (Big O)
COSC 1P03 Data Structures and Abstraction 2.1 Analysis of Algorithms Only Adam had no mother-in-law. That's how we know he lived in paradise.
Algorithm Analysis. What is an algorithm ? A clearly specifiable set of instructions –to solve a problem Given a problem –decide that the algorithm is.
Searching Topics Sequential Search Binary Search.
CISC220 Spring 2010 James Atlas Lecture 07: Big O Notation.
Comp 245 Data Structures Analysis of Algorithms. Purpose A professional programmer must be able to determine how efficient his code is. Efficiency, as.
Algorithm Analysis with Big Oh ©Rick Mercer. Two Searching Algorithms  Objectives  Analyze the efficiency of algorithms  Analyze two classic algorithms.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
LECTURE 9 CS203. Execution Time Suppose two algorithms perform the same task such as search (linear search vs. binary search) and sorting (selection sort.
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
Algorithm Analysis 1.
Complexity Analysis (Part I)
Analysis of Algorithms
Analysis of Algorithms
GC 211:Data Structures Week 2: Algorithm Analysis Tools
Introduction to complexity
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Analysis of Algorithms
Introduction to Algorithms
Big O notation Big O notation is used in Computer Science to describe the performance or complexity of an algorithm. Big O specifically describes the worst-case.
Introduction to Analysis of Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Lesson Objectives Aims Understand the following: The big O notation.
Introduction to Algorithms
Efficiency (Chapter 2).
Big-Oh and Execution Time: A Review
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
GC 211:Data Structures Algorithm Analysis Tools
Introduction to Data Structures
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Big O Notation.
CSC 205 Java Programming II
Comparing Algorithms Unit 1.2.
CS 201 Fundamental Structures of Computer Science
Analysys & Complexity of Algorithms
Programming and Data Structure
Analysis of Algorithms
DS.A.1 Algorithm Analysis Chapter 2 Overview
Programming and Data Structure
Algorithmic Complexity
CSE 373 Data Structures and Algorithms
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Revision of C++.
CSE 1342 Programming Concepts
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
Algorithmic complexity
CSE 373: Data Structures and Algorithms
Complexity Analysis (Part I)
Analysis of Algorithms
Algorithms and data structures: basic definitions
Complexity Analysis (Part I)
Presentation transcript:

Analyzing an Algorithm Computing the Order of Magnitude Big O Notation

Measuring the Performance of an Algorithm Order of magnitude describes the growth/running time of an algorithmic process. Example: As the size of the array gets larger, what is the increase in processing time? What happens when we double the data? The running time of an algorithm is the number of primitive operations executed. Big-O notation is used to describe the worst-case scenario of an algorithm.

Computing the runtime of an algorithm It's hard to compute the exact runtime of an algorithm. Runtime depends on: The speed of the processor Additional tasks being performed and executed in the background. Instead of talking about the runtime directly, we use big O notation to show how quickly the runtime grows.

Measuring how quickly runtime grows It is only possible to use units of time, such as seconds, when the runtime is measured directly. Algorithms are measured by how quickly the runtime grows, not speed time. Order of magnitude uses the size of the data. Data can become arbitrarily large. An algorithm may seem inefficient when the data size is small but becomes more efficient when the data size increases. Big O notation examines the worst case scenario.

Example: What is the runtime of this algorithm? int sum = 0; int k = 0; while (k < n){ sum += a[k]; k++; } Task 1: Determine the number of operations processed by this algorithm.

Counting the operations in an algorithm int sum = 0; int k = 0; while (k < n){ sum += a[k]; k++; } Initialization: 2 operations Loop Statement: n + 1 iterations of two operations 2 + 2 * (n + 1)

Count only basic operations in an algorithm int sum = 0; int k = 0; while (k < n){ sum += a[k]; k++; } Initialization should be counted as a single basic operation. Loop Statement: Each loop iteration represents a single basic operation 1 + n

Simplify the further O(n) int sum = 0; int k = 0; while (k < n){ Rule 1: For larger data sizes, constants become insignificant. Rule 2: Only the most dominant term of the expression is useful. int sum = 0; int k = 0; while (k < n){ sum += a[k]; k++; } 1 + n Final Answer: O(n)

Practice : Examine the efficiency expression of an algorithm Practice : Examine the efficiency expression of an algorithm. Determine the Big O notation: Ans : 1000n O(n) 8n log2 n + 14n O(n log2 n) n3 – n2 – 3 ? 4n2 + 7n + 2 ? 3 log2 n + 1 ?

Answers to Practice Problems : Examine the efficiency expression of an algorithm. Determine the Big O notation: 1000n O(n) 8n log2 n + 14n O(n log2 n) n3 – n2 – 3 O (n3) 4n2 + 7n + 2 O(n2) 3 log2 n + 1 O(log2 n)

Searching Efficiency for a Linear Search Describe the worst case scenario when asked to perform a linear search. How many comparisons are required? How many comparisons are required for performing a linear search in an average situation? What is the order of magnitude of efficiency for both the worst and the average case for the linear search?

Searching Efficiency for a Binary Search Describe the worst case scenario when asked to perform a binary search. How many comparisons are required? How many comparisons are required for performing a binary search in an average situation? What is the order of magnitude of efficiency for both the worst and the average case for the binary search?