Analysis of Algorithms CSCI 3110. Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it.

Slides:



Advertisements
Similar presentations
Algorithm Analysis Input size Time I1 T1 I2 T2 …
Advertisements

MATH 224 – Discrete Mathematics
HST 952 Computing for Biomedical Scientists Lecture 10.
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
Fundamentals of Python: From First Programs Through Data Structures
Reference: Tremblay and Cheston: Section 5.1 T IMING A NALYSIS.
Analysys & Complexity of Algorithms Big Oh Notation.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Chapter 3 Growth of Functions
Introduction to Analysis of Algorithms
Complexity Analysis (Part I)
Cmpt-225 Algorithm Efficiency.
The Efficiency of Algorithms
Algorithm Efficiency and Sorting Bina Ramamurthy CSE116A,B.
Data Structures and Algorithms1 Basics -- 2 From: Data Structures and Their Algorithms, by Harry R. Lewis and Larry Denenberg (Harvard University: Harper.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Elementary Data Structures and Algorithms
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis (Big O)
Spring2012 Lecture#10 CSE 246 Data Structures and Algorithms.
COMP s1 Computing 2 Complexity
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.
Program Performance & Asymptotic Notations CSE, POSTECH.
Week 2 CS 361: Advanced Data Structures and Algorithms
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
Mathematics Review and Asymptotic Notation
Analysis of Algorithms
Analysis of Algorithm Efficiency Dr. Yingwu Zhu p5-11, p16-29, p43-53, p93-96.
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.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
1 Lecture 5 Generic Types and Big O. 2 Generic Data Types A generic data type is a type for which the operations are defined but the types of the items.
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
Algorithm Analysis Data Structures and Algorithms (60-254)
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
CMSC 341 Asymptotic Analysis. 2 Complexity How many resources will it take to solve a problem of a given size? –time –space Expressed as a function of.
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)
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.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
Algorithm Analysis 1.
Algorithm Efficiency and Sorting
CS 302 Data Structures Algorithm Efficiency.
Analysis of Algorithms
Introduction to Analysis of Algorithms
Analysis of Algorithms
GC 211:Data Structures Week 2: Algorithm Analysis Tools
Analysis of Algorithms
Introduction to Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Big-O notation.
Courtsey & Copyright: DESIGN AND ANALYSIS OF ALGORITHMS Courtsey & Copyright:
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
Algorithm Efficiency Chapter 10.
Analysys & Complexity of Algorithms
Algorithm Efficiency and Sorting
Analysis of Algorithms
Chapter 2.
Algorithm Analysis Bina Ramamurthy CSE116A,B.
Searching, Sorting, and Asymptotic Complexity
Algorithm Efficiency and Sorting
Estimating Algorithm Performance
Analysis of Algorithms
Algorithm Efficiency and Sorting
Presentation transcript:

Analysis of Algorithms CSCI 3110

Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it solve only a specific case or will it work for the general case too? Robustness – will the algorithm recover following an error Portability Documentation & Style Efficiency – Does it accomplish its goals with a minimal usage of computer resources (time and space)?

New Way to Evaluate Memory efficiency: which algorithm requires less memory space during run time? Time efficiency: which algorithm requires less computational time to complete? When comparing the algorithms in terms of efficiency, we consider the amount of memory and time required as a function of the size of the input. Thus we can measure the rate of growth of the memory use or time use using that function.

What is the size of the input? Sorting a set of numbers  the number of items to be sorted Search for an item in a set of items  the number of items to search from Computation involved with a n x n matrix  size of the matrix – A list of strings (numStrings x string Length)

Time Complexity Best time – The minimum amount of time required by the algorithm for any input of size n. – Seldom of interest. Worst time  our focus – The maximum amount of time required by the algorithm for any input of size n Average time – The average amount of time required by the algorithm over all inputs of size n Similar definitions can be given for space complexity

Empirical vs. theoretical analysis Empirical approach: Measure Computer Clock Time – problem  difference in computer platforms, compiler, language, programmers – Machine instructions Theoretical approach: Count number of C++ statements executed during run time or obtain an acceptable approximation. – Therefore, the focus of this type of analysis is performing frequency counts : a count of how many times a statement is executed in an algorithm.

Look at Counting Examples

Algorithm Efficiency The efficiency of an algorithm is determined in terms of the order of growth of the function. Only compare the rate of growth (order of magnitude) of the functions and compare the orders. -- how fast does the algorithm grow as the size of input, N, grows? Normally, the growth function will approach some simpler function asymptotically. For growth functions having different orders of magnitude, exact frequency counts and the constants become insignificant.

The algorithms are grouped into groups according to the order of growth of the their time complexity functions, which include: O(1) < O(logN) < O(N) < O(NlogN) < O(N 2 ) < O(N 3 ) < … < O(e N ) look at the graph with all these functions plotted against each other

Determining the Order of Growth How does one determine which Big O category an algorithm’s growth rate function (GRF) falls into? This is determined by using the big O notation: Rules of Big O notations that help to simplify the analysis of an algorithm – Ignore the low order terms in an algorithm’s growth rate function – Ignore the multiplicative constants in the high order terms of GRF – When combining GRF, O(f(N))+O(g(N)) = O(f(N)+g(N)) (e.g., when two segments of code are analyzed separately and we want to know the time complexity of the total of the two segments

Examples F(n) = 10n + 3n is O(?) F(n) = 20nlogn + 3n + 2 is O(?) F(n) = 12nlogn + 2n 2 is O(?) F(n) = 2 n + 3 n is O(?)

Formal Definition of Big O Formal Definition of Big O function: F(n)= O(g(n)) (F(n) is Big O of g(n)) if there is are positive constant values C and n 0, such that: f(n) = n 0, where n 0 is non-negative integer Note: Some definitions of Big O read that |f(N)| = N 0, where N 0 is non-negative integer. However, we will use the “relaxed” version of the definition since we are dealing with frequency counts which should be positive anyway.

Example Show by definition that f(n) = 3n + 2 is O(n). By definition, we must show there exist C and n 0 such that 3n+2 n 0 where n 0 is a non- negative integer. Let C = 4. Why did I pick 4? If C = 4, 3n+2 < 4n when? Subtract 3n from both sides of the inequality: 3n + 2 – 3n < 4n – 3n or 2 < n. Thus n 0 is 2. Is this the only C and n 0 that will work?

Intuitive interpretation of growth functions A GFR of O(1) implies a problem – whose time requirement is constant & – thus independent of the problem’s size n. A GFR of O(log 2 n) implies a problem – For which the time requirement increases slowly as the problem size increases. – If you square the problem size, you only double its time requirement. – Often occurs in an algorithm that solves a problem by solving a smaller constant fraction of the problem (like the binary search)

Intuitive interpretation continued A GFR of O(1) implies a problem – For which the time requirement is directly proportional to the size of the problem. – In which if you square the problem size, you also square its time requirement – That often has a single loop from 1 to n A GFR of O(n log 2 n) implies a problem – For which the time requirement increases more rapidly than a linear algorithm. – That usually divides a problem into smaller problems that are each solved separately

Intuitive interpretation continued A GFR of O(n 2 ) is a problem – For which the time requirement increases rapidly with the size of the problem – That often has two nested loops A GFR of O(n 3 ) is a problem – That often has three nested loops – that is only practical for small problems A GFR of O(2 n ) is a problem – For which the time requirements are exponential – For which the time requirements increase too rapidly to be practical

Read “Keeping Your Perspective” – pages in the book.