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.

Slides:



Advertisements
Similar presentations
Growth-rate Functions
Advertisements

Algorithms Algorithm: what is it ?. Algorithms Algorithm: what is it ? Some representative problems : - Interval Scheduling.
College of Information Technology & Design
MATH 224 – Discrete Mathematics
Lecture: Algorithmic complexity
CS50 SECTION: WEEK 3 Kenny Yu. Announcements  Watch Problem Set 3’s walkthrough online if you are having trouble.  Problem Set 1’s feedback have been.
Analysys & Complexity of Algorithms Big Oh Notation.
Chapter 1 – Basic Concepts
the fourth iteration of this loop is shown here
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Introduction to Analysis of Algorithms
Complexity Analysis (Part I)
Cmpt-225 Algorithm Efficiency.
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 COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
Data Structure & Algorithm Lecture 3 –Algorithm Analysis JJCAO.
Algorithm Analysis (Big O)
Data Structures Introduction Phil Tayco Slide version 1.0 Jan 26, 2015.
COMP s1 Computing 2 Complexity
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.
Program Performance & Asymptotic Notations CSE, POSTECH.
Discrete Mathematics Algorithms. Introduction  An algorithm is a finite set of instructions with the following characteristics:  Precision: steps are.
{ 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)
Chapter 12 Recursion, Complexity, and Searching and Sorting
Analysis of Algorithms
Chapter 19: Searching and Sorting Algorithms
Searching. RHS – SOC 2 Searching A magic trick: –Let a person secretly choose a random number between 1 and 1000 –Announce that you can guess the number.
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.
CMPT 438 Algorithms. Why Study Algorithms? Necessary in any computer programming problem ▫Improve algorithm efficiency: run faster, process more data,
Analysis of Algorithms CSCI Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
New Mexico Computer Science For All Algorithm Analysis Maureen Psaila-Dombrowski.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Computer Science 101 A Survey of Computer Science Timing Problems.
3.3 Complexity of Algorithms
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
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.
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.
1 Ch. 2: Getting Started. 2 About this lecture Study a few simple algorithms for sorting – Insertion Sort – Selection Sort (Exercise) – Merge Sort Show.
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.
Search Algorithms Written by J.J. Shepherd. Sequential Search Examines each element one at a time until the item searched for is found or not found Simplest.
Chapter 16: Searching, Sorting, and the vector Type.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
Complexity Analysis (Part I)
CMPT 438 Algorithms.
Analysis of Algorithms
Algorithmic Efficency
Computer Science 112 Fundamentals of Programming II
Lesson Objectives Aims Understand the following: The big O notation.
Sorting by Tammy Bailey
Algorithm Analysis CSE 2011 Winter September 2018.
Enough Mathematical Appetizers!
Efficiency (Chapter 2).
Algorithm Analysis (not included in any exams!)
Big O Notation.
Analysys & Complexity of Algorithms
Applied Discrete Mathematics Week 6: Computation
Programming and Data Structure
DS.A.1 Algorithm Analysis Chapter 2 Overview
Analyzing an Algorithm Computing the Order of Magnitude Big O Notation
Algorithmic Complexity
Enough Mathematical Appetizers!
Enough Mathematical Appetizers!
Complexity Analysis (Part I)
Complexity Analysis (Part I)
Presentation transcript:

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 are some different search algorithms? What are some different sorting algorithms?

How good is it? Measure performance by measuring resource usage time space Space should be consistent across different machines, but what about time? What if you ran an algorithm on both a Intel Pentium II and an Intel Core i7?

How many comparisons? Assume an array containing n=10 elements: 4, 2, 62, 6, 78, 8, 5, 91, 63, 13 Using the linear search algorithm: How many comparisons would we need to find something at the beginning (e.g., 4)? On average how many comparisons would we need to find something in the middle? How many comparisons would we need to find something at the end (e.g., 13)?

Linear Search Evaluation Assuming an array of n elements, linear search yields: Best case: 1 comparison Average case: n/2 comparisons Worst case: n comparisons

Big O! a mathematical representation of the complexity of an algorithm “on the order of...” usually used to estimate the upper bound performance O( # comparisons ) or O( # operations ) or O( # of times things happen)

Summary of Complexities O(1) : constant time not related to length of data set O(log 2 n) : log time and is fast O(n) : linear time O(n log 2 n) : “n log n” time O(n 2 ) : quadratic time, polynomial complexity O(n 3 ) : cubic time, polynomial complexity O(n n ) : not computable

A Simple Example k = 0 i = 0 while i < n: k += 1 n += 1 What’s my complexity?!? (Hint: use Big O notation)...on the order of...

A Simpler Example k = 0 k+=1 What’s my complexity?!? (Hint: use Big O notation)...on the order of...

Another Example for i in range(n): for j in range(n): for k in range(n): a++; What’s my complexity?!? (Hint: use Big O notation)...on the order of...

::sigh:: Another Example k = 0 for i in range(n): for x in range(n): k += 1 What’s my complexity?!? (Hint: use Big O notation)...on the order of...

Rules of Thumb one loop  O(n) two nested loops  O(n 2 ) three nested loops  O(n 3 )

Back to linear search... Best case: 1 comparison  O(1) Worst case: n comparisons  O(n) Average case: n/2 comparisons...wait...what if n is really, really, really big? O(n/2) reduces to O(n) Linear search’s complexity is O(n)

Complexity Reduction Rules of thumb: consider LARGE values of n  removes constants larger complexities overshadow smaller ones  removes smaller Os Examples: O(n/2)  O(n) O(2*n)  O(n) O(n + 5)  O(n) O(n )  O(n) O(n 2 ) + O(n)  O(n 2 + n)  O(n 2 )

Reduction Example k = 0 for i in range(n/2): k += 1 Notice the “n/2”! What’s the complexity?

Binary Search Algorithm Assume a sorted array containing n=10 elements: 2, 4, 5, 6, 8, 13, 62, 63, 78, 91 Using the binary search algorithm: What is the best case performance? What is the worst case performance? What is the O complexity?

Summary of Common Complexities linear search : O(n) binary search : O(log 2 n) bubble sort : O(n 2 ) selection sort : O(n 2 ) quick sort : O(n log 2 n)

IB Expectations Evaluate the efficiency of a given algorithm How many times does it run exactly? How do you improve the algorithm? Trace an algorithm (follow its steps) when given input Analyze an algorithm as pseudocode or flowchart