Data Structures Using C++ 2E

Slides:



Advertisements
Similar presentations
Data Structures Using C++ 2E
Advertisements

Lecture 11: Algorithms and Time Complexity I Discrete Mathematical Structures: Theory and Applications.
Data Structures Using C++ 2E The Big-O Notation. Data Structures Using C++ 2E2 Algorithm Analysis: The Big-O Notation Analyze algorithm after design Example.
CSCE 2100: Computing Foundations 1 Running Time of Programs
Algorithm Analysis.
Lecture: Algorithmic complexity
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
CS 3610/5610N data structures Lecture: complexity analysis Data Structures Using C++ 2E1.
Chapter 3 Growth of Functions
Chapter 10 Algorithm Efficiency
Analyzing algorithms & Asymptotic Notation BIO/CS 471 – Algorithms for Bioinformatics.
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
Analysis of Algorithms (pt 2) (Chapter 4) COMP53 Oct 3, 2007.
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.
Analysis of Performance
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.
Chapter 2.6 Comparison of Algorithms modified from Clifford A. Shaffer and George Bebis.
Week 2 CS 361: Advanced Data Structures and Algorithms
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.
Mathematics Review and Asymptotic Notation
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.
Analyzing algorithms & Asymptotic Notation BIO/CS 471 – Algorithms for Bioinformatics.
Department of Computer Science 1 COSC 2320 Section Room 104 AH 5:30 – 7:00 PM TTh Professor Olin Johnson Office 596 PGH
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
COSC 2P03 Week 11 Reasons to study Data Structures & Algorithms Provide abstraction Handling of real-world data storage Programmer’s tools Modeling of.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Software Engineering Review CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science.
Data Structures Using C++ 2E Chapter 1 Software Engineering Principles and C++ Classes.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Introduction to Analysis of Algorithms CS342 S2004.
General rules: Find big-O f(n) = k = O(1) f(n) = a k n k + a k-1 n k a 1 n 1 + a 0 = O(n k ) Other functions, try to find the dominant term according.
Data Structures Using C++ 2E
David Luebke 1 1/6/2016 CS 332: Algorithms Asymptotic Performance.
Asymptotic Performance. Review: Asymptotic Performance Asymptotic performance: How does algorithm behave as the problem size gets very large? Running.
Algorithm Analysis (Big O)
Algorithm Analysis (Time complexity). Software development cycle -Four phases: 1.Analysis 2.Design Algorithm Design an algorithm to solve the problem.
CISC220 Spring 2010 James Atlas Lecture 07: Big O Notation.
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.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
Data Structures & Algorithm CS-102 Lecture 12 Asymptotic Analysis Lecturer: Syeda Nazia Ashraf 1.
Chapter 2 Algorithm Analysis
Analysis of Algorithms
Reasons to study Data Structures & Algorithms
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
Chapter 1 The Phases of Software Development
Introduction to Algorithms
Data Structures Using The Big-O Notation 1.
Analysis of Algorithms: Methods and Examples
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
Analysis of Algorithms
Programming and Data Structure
Analyzing an Algorithm Computing the Order of Magnitude Big O Notation
Reasons to study Data Structures & Algorithms
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
Algorithm Analysis How can we demonstrate that one algorithm is superior to another without being misled by any of the following problems: Special cases.
Presentation transcript:

Data Structures Using C++ 2E The Big-O Notation

Algorithm Analysis: The Big-O Notation Analyze algorithm after design Example 50 packages delivered to 50 different houses 50 houses one mile apart, in the same area FIGURE 1-1 Gift shop and each dot representing a house Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation (cont’d.) Example (cont’d.) Driver picks up all 50 packages Drives one mile to first house, delivers first package Drives another mile, delivers second package Drives another mile, delivers third package, and so on Distance driven to deliver packages 1+1+1+… +1 = 50 miles Total distance traveled: 50 + 50 = 100 miles FIGURE 1-2 Package delivering scheme Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation (cont’d.) Example (cont’d.) Similar route to deliver another set of 50 packages Driver picks up first package, drives one mile to the first house, delivers package, returns to the shop Driver picks up second package, drives two miles, delivers second package, returns to the shop Total distance traveled 2 * (1+2+3+…+50) = 2550 miles FIGURE 1-3 Another package delivery scheme Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation (cont’d.) Example (cont’d.) n packages to deliver to n houses, each one mile apart First scheme: total distance traveled 1+1+1+… +n = 2n miles Function of n Second scheme: total distance traveled 2 * (1+2+3+…+n) = 2*(n(n+1) / 2) = n2+n Function of n2 Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation (cont’d.) Analyzing an algorithm Count number of operations performed Not affected by computer speed TABLE 1-1 Various values of n, 2n, n2, and n2 + n Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation (cont’d.) TABLE 1-1 Various values of n, 2n, n2, and n2 + n (n) and (2n) are close, so we magnify (n) (n2) and (n2 + n) are close, so we magnify (n2) Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation (cont’d.) TABLE 1-1 Various values of n, 2n, n2, and n2 + n When n becomes too large, n and n2 becomes very different Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation (cont’d.) Example 1-1 Illustrates fixed number of executed operations 1 operation Only one of them will be executed 2 operations 1 operation 1 operation 1 operation 3 operations Total of 8 operations Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation Example 1-2 Illustrates dominant operations 2 operations 1 operation 1 operation N times the condition is TRUE + 1 time the condition is FALSE 1 operation N+1 operations 2N operations Executed while the cond. is TRUE N operations N operations 3 operations Only one of them will be executed, take the max: 2 1 operation 2 operations 1 operation 3 operation If the while loop executes N times then: 2+1+1+1+5*N + 1 + 3 + 1 + (2 ) + 3 = 5N+(15 ) Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation How to count for loops for (initialization; condition; increase){ statement1; statement2; . . . } Times the cond. Is TRUE + 1 (when the condition is FALSE 1 op Times the cond. Is TRUE Times the cond. Is TRUE Data Structures Using C++ 2E

for(i=1; i<=5; i++) Example for(j=1;j<=5; j++) { } Finally: 147 1 op 5 op 6 op for(i=1; i<=5; i++) for(j=1;j<=5; j++) { cout <<“*”; sum =sum+j; } for(i=1; i<=n; i++) for(j=1; j<=n; j++){ cout <<“*”; Sum=sum + j; } 30 op 25 op 5 op 25 op 2n+2+ 2n2+2n+ 3n2 = 5n2+ 4n+2 25 op 25 op Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation (cont’d.) Sequential search algorithm n: represents list size f(n): number of basic operations (3n + 2) c: units of computer time to execute one operation Depends on computer speed (varies) cf(n): computer time to execute f(n) operations for(i=0; i<n; i++) // at most 1 + (n+1) + n if(a[i] = = searchKey) // at most n return true; // 0 or 1 time Total ops = 3n + 2 Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation (cont’d.) TABLE 1-2 Growth rates of various functions Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation (cont’d.) TABLE 1-3 Time for f(n) instructions on a computer that executes 1 billion instructions per second (1 GHz) Figure 1-4 Growth rate of functions in Table 1-3 Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation (cont’d.) Notation useful in describing algorithm behavior Shows how a function f(n) grows as n increases without bound Asymptotic Study of the function f as n becomes larger and larger without bound Examples of functions g(n)=n2 (no linear term) f(n)=n2 + 4n + 20 Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation (cont’d.) As n becomes larger and larger Term 4n + 20 in f(n) becomes insignificant Term n2 becomes dominant term TABLE 1-4 Growth rate of n2 and n2 + 4n + 20n Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation (cont’d.) If function complexity can be described by complexity of a quadratic function without the linear term We say the function is of O(n2) or Big-O of n2 Let f and g be real-valued functions Assume f and g nonnegative For all real numbers n, f(n) >= 0 and g(n) >= 0 f(n) is Big-O of g(n): written f(n) = O(g(n)) If there exists positive constants c and n0 such that f(n) <= cg(n) for all n >= n0 Data Structures Using C++ 2E

Algorithm Analysis: The Big-O Notation (cont’d.) TABLE 1-5 Some Big-O functions that appear in algorithm analysis Data Structures Using C++ 2E