Bigointro1 Algorithm Analysis & Program Testing An introduction.

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

Efficiency of Algorithms
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 2: Basics Data Structures.
Chapter 1. The Phases of Software Development. Data Structure 2 Chapter outline  Objectives  Use Javadoc to write a method’s complete specification.
Fundamentals of Python: From First Programs Through 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.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Chapter 10 Algorithm Efficiency
Branching Constructs Review l what are branching constructs? what type of branching constructs have we studied? l what is nested if? l what is multiway.
Complexity Analysis (Part I)
CS 307 Fundamentals of Computer Science 1 Asymptotic Analysis of Algorithms (how to evaluate your programming power tools) based on presentation material.
CS107 Introduction to Computer Science
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
© 2006 Pearson Addison-Wesley. All rights reserved6-1 More on Recursion.
Lecture 4 Feb 5 completion of recursion (inserting into a linked list as last item) analysis of algorithms – Chapter 2.
Lecture 4 Sept 4 Goals: chapter 1 (completion) 1-d array examples Selection sorting Insertion sorting Max subsequence sum Algorithm analysis (Chapter 2)
Loops, Summations, Order Reduction Chapter 2 Highlights.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 2. 2 Running time of Basic operations Basic operations do not depend on the size of input, their running time is.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Analysis of Algorithm.
CS107 Introduction to Computer Science Lecture 7, 8 An Introduction to Algorithms: Efficiency of algorithms.
 2006 Pearson Education, Inc. All rights reserved Searching and Sorting.
COMP s1 Computing 2 Complexity
Pointers (Continuation) 1. Data Pointer A pointer is a programming language data type whose value refers directly to ("points to") another value stored.
© Janice Regan, CMPT 128, Feb CMPT 128: Introduction to Computing Science for Engineering Students Running Time Big O Notation.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
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.
Chapter 2.6 Comparison of Algorithms modified from Clifford A. Shaffer and George Bebis.
Week 2 CS 361: Advanced Data Structures and Algorithms
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
Introduction to complexity. 2 Analysis of Algorithms Why do we need to analyze algorithms? –To measure the performance –Comparison of different algorithms.
1 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
CSC 201 Analysis and Design of Algorithms Lecture 04: CSC 201 Analysis and Design of Algorithms Lecture 04: Time complexity analysis in form of Big-Oh.
Analysis of Algorithms
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.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
Chapter 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
Chapter 8 Iteration Dept of Computer Engineering Khon Kaen University.
Computer Science and Software Engineering University of Wisconsin - Platteville 8. Comparison of Algorithms Yan Shi CS/SE 2630 Lecture Notes Part of this.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
CPS120 Introduction to Computer Science Iteration (Looping)
Analysis of algorithms. What are we going to learn? Need to say that some algorithms are “better” than others Criteria for evaluation Structure of programs.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
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.
C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
Searching Topics Sequential Search Binary Search.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
CSC 143Q 1 CSC 143 Program Efficiency [Chapter 9, pp ]
Design and Analysis of Algorithms & Computational Complexity CS490 Koji Tajii.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
Section 1.7 Comparing Algorithms: Big-O Analysis.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
1 Algorithms Searching and Sorting Algorithm Efficiency.
Computer Programming -1-
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
Algorithm Analysis 1.
Introduction to Analysis of Algorithms
Analysis of Algorithms
Introduction to complexity
CS 201 Fundamental Structures of Computer Science
Programming and Data Structure
Programming and Data Structure
Analyzing an Algorithm Computing the Order of Magnitude Big O Notation
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Algorithmic complexity
Presentation transcript:

bigointro1 Algorithm Analysis & Program Testing An introduction

bigointro2 Time Analysis: reasoning about speed of algorithm Need to decide how time will be measured –actual performance time: not always accurate different system same system, different time –number of operations performed -- more accurate measure

bigointro3 What’s an operation? Declaration Assignment statement: x = 2; // one operation x = y + 2; // two operations Input/Output statement Function call Most conditional statements

bigointro4 Big-O notation Can use number of operations in an algorithm to determine rough measure of amount of time needed to perform it Size of data set (amount of input) largely determines relative speed, so Big-O takes this into account

bigointro5 Big-O examples An algorithm executes in constant time if it contains statements that don’t depend of size of data set -- said to be O(1) An algorithm executes in linear time if the number of operations is equal to the size of the data set -- O(N)

bigointro6 Big-O is an approximation Algorithm is still O(1) if it takes 20 constant statements or 20,000 A loop is linear if it depends of size of data set, but constant if it terminates at a pre-set value Constant values are ignored -- O(N ) is still O(N)

bigointro7 Analysis example -- loops For any loop, analysis has two parts: –number of iterations –amount of work done during each iteration Example: int sum=0, j; for (j=0; j<N; j++) sum=sum+j; Loop executes N times 4 operations in loop: –j<N –sum+j –sum= –j++ O(4) == O(1) Total is N * O(1) or O(N)

bigointro8 Another loop example int sum = 0,j; for (j=0; j<100; j++) sum=sum+j; Loop executes 100 times Work inside loop is still O(4), which is O(1) Total is 100*O(1), or O(100), which is still O(1)

bigointro9 Nested Loops Treat like single loop, evaluating each level of nesting as needed: int j,k, sum=0; for (j=0; j<N; j++) for (k=N; k>0; k--) sum+=k+j; Start with outer loop -- N iterations -- amount of work depends on inner loop Inner loop is O(N) Total is N * O(N), or O(N 2 )

bigointro10 Conditional Statements To evaluate an if-statement, compute costs of “then” & “else” parts, then take larger: if (InputDone) { for (j=0; j<N; j++) cout << Data[j]; } else cout << “Not done yet” << endl; Would be O(N) because O(N) > O(1)

bigointro11 Function Calls Treat function like any other block of code, use its complexity function (Big-O) wherever it is called If function call occurs in a loop, determine cost of function call & use to determine cost of loop

bigointro12 Common Orders of Magnitude Constant: O(1) Logarithmic: O(log N) Linear: O(N) Quadratic: O(N 2 ) Exponential: O(k N )

bigointro13 Big-O Only One Measure to Consider Number of inputs can differ wildly from one run of the program to another Useful to think in terms of 3 possible cases to analyze: –worst-case: maximum number of required operations –best-case: minimum number –average case: average of best & worst

bigointro14 Program Testing & Debugging Testing: running a program to observe its behavior Need to select & use good test data to determine whether or not run-time errors will occur Purpose of testing is to find bugs so they can be eliminated; not to prove bugs don’t exist

bigointro15 Properties of Good Test Data Known expected output for given input Include inputs most likely to cause error Test boundary values

bigointro16 Fully Exercising Code Make sure each line of code is executed at least once by some of your test data If some portion of code should be skipped under certain conditions, make sure you include test data that creates those conditions, and that the code gets skipped

bigointro17 Debugging Do’s Limit code changes to corrections of known errors Rerun test cases each time a change is made Keep track of changes as you make them Isolate potential problem areas –commenting out –using breakpoints

bigointro18 Algorithm Analysis & Program Testing -ends-