Algorithm Analysis.

Slides:



Advertisements
Similar presentations
Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University
Advertisements

Intro to Algorithm analysis
MATH 224 – Discrete Mathematics
The Efficiency of Algorithms Chapter 4 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Lecture: Algorithmic complexity
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 2: Basics Data Structures.
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
CMPT 225 Sorting Algorithms Algorithm Analysis: Big O Notation.
Analysis And Algorithms CMSC 201. Search Sometimes, we use the location of a piece of information in a list to store information. If I have the list [4,
the fourth iteration of this loop is shown here
CS 206 Introduction to Computer Science II 09 / 10 / 2008 Instructor: Michael Eckmann.
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
Cmpt-225 Algorithm Efficiency.
Analysis of Algorithms (pt 2) (Chapter 4) COMP53 Oct 3, 2007.
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
Data Structures and Algorithms1 Basics -- 2 From: Data Structures and Their Algorithms, by Harry R. Lewis and Larry Denenberg (Harvard University: Harper.
Elementary Data Structures and Algorithms
Cmpt-225 Simulation. Application: Simulation Simulation  A technique for modeling the behavior of both natural and human-made systems  Goal Generate.
Spring2012 Lecture#10 CSE 246 Data Structures and Algorithms.
Analysis of Performance
Asymptotic Notations Iterative Algorithms and their analysis
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.
Array operations II manipulating arrays and measuring performance.
SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Fall 2009.
Algorithm Input Output An algorithm is a step-by-step procedure for solving a problem in a finite amount of time. Chapter 4. Algorithm Analysis (complexity)
Iterative Algorithm Analysis & Asymptotic Notations
L. Grewe.  An array ◦ stores several elements of the same type ◦ can be thought of as a list of elements: int a[8]
Analysis of Algorithms These slides are a modified version of the slides used by Prof. Eltabakh in his offering of CS2223 in D term 2013.
Complexity of Algorithms
Copyright © 2014 Curt Hill Growth of Functions Analysis of Algorithms and its Notation.
1 Asymptotic Notations Iterative Algorithms and their analysis Asymptotic Notations –Big O,  Notations Review of Discrete Math –Summations –Logarithms.
Georgia Institute of Technology Speed part 4 Barb Ericson Georgia Institute of Technology May 2006.
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
CS321 Data Structures Jan Lecture 2 Introduction.
Searching Topics Sequential Search Binary Search.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
Design and Analysis of Algorithms
Analysis of Algorithms
Algorithmic complexity: Speed of algorithms
COMP108 Algorithmic Foundations Algorithm efficiency
Algorithm Analysis The case of recursion.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to complexity
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.
COMP 53 – Week Seven Big O Sorting.
Analysis of Algorithms
Algorithm Analysis CSE 2011 Winter September 2018.
Complexity and Big-O.
Algorithmic Complexity CSE 120 Winter 2018
Analysis of Algorithms
CS 2210 Discrete Structures Algorithms and Complexity
Efficiency (Chapter 2).
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Introduction to Data Structures
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Analysis of Algorithms
DS.A.1 Algorithm Analysis Chapter 2 Overview
Algorithmic complexity: Speed of algorithms
Analyzing an Algorithm Computing the Order of Magnitude Big O Notation
Searching, Sorting, and Asymptotic Complexity
Performance Evaluation
Algorithmic complexity: Speed of algorithms
Analysis of Algorithms
The Efficiency of Algorithms
Analysis of Algorithms
Complexity and Big-O.
CS 2210 Discrete Structures Algorithms and Complexity
Presentation transcript:

Algorithm Analysis

Pretend we had a list with x different names. We build the following method to see if a name is in our list: def is_name_in_list(my_list, search_name): for item in my_list: if item == search_name: return True return False What do we need to know in order to determine how fast this will run? How do we measure the “speed” of a program? What do we need to know to determine how fast this will run?

Why does this matter? Computers are so fast! But… Large Scale Data Google, Twitter, Facebook.. Big Data Limited Resources phones, watches, wearable computing High Performance Environments milliseconds matter

Measure the work instead of timing If we actually measure time, e.g., using the Linux time command, we can’t account for the speed differences among different computers. Rather, we’d measure the steps an algorithm or a program will take when comparing them. Try a few examples with the time command …

Big-O Notation No need to count precise number of steps Classify algorithms by order of magnitude Execution time Space requirements Big O gives us a rough upper bound Goal is to give you intuition

How do we know what matters in code? 1 1 * (10) 1 n+2

How do we know what matters in code? O(n) Pay attention to what changes as the variables increases

Describing Growth Let’s Visualize It See for example: http://science.slc.edu/jmarshall/courses/2002/spring/cs50/BigO/index.html

Does it REALLY matter? Try out two examples bubblesort.py quicksort.py

Code Examples

What is the Big O? 3 n^2 + 10 n log n O(n^2) n log n + n/2 O(n log n)

Code Evaluation #1 def ex1( n ): count = 0 for i in range( n ): count += i return count

Code Evaluation #2 def ex2( n ): count = 0 for i in range( n ): for j in range( n ): return count

Code Evaluation #3 def ex3( n ): count = 0 for i in range( n ): for j in range( n ): count += 1 return count def ex3b( n ): count = 0 for i in range( n ): count += ex3( n ) return count

Code Evaluation #4 def ex4( n ): count = 0 for i in range( n ): for j in range( 25 ): count += 1 return count

Code Evaluation #6 def ex6( n ): count = 0 i = n while i >= 1 : i = i // 2 return count

Code Evaluation #7 def ex6( n ): count = 0 i = n while i >= 1 : i = i // 2 return count def ex7( n ): count = 0 for i in range( n ) : count += ex6( n ) return count