CS 3610/5610N data structures Lecture: complexity analysis Data Structures Using C++ 2E1.

Slides:



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

Lecture 11: Algorithms and Time Complexity I Discrete Mathematical Structures: Theory and Applications.
Growth-rate Functions
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.
Lecture: Algorithmic complexity
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
1 ICS 353 Design and Analysis of Algorithms Spring Semester (062) King Fahd University of Petroleum & Minerals Information & Computer Science.
Complexity Analysis (Part I)
Cmpt-225 Algorithm Efficiency.
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
The Efficiency of Algorithms
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 COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis (Big O)
Algorithm Cost Algorithm Complexity. Algorithm Cost.
Algorithm analysis and design Introduction to Algorithms week1
CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a lgorithms.
Week 2 CS 361: Advanced Data Structures and Algorithms
SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Fall 2009.
1 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
Lecture 2 Computational Complexity
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
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.
CS 221 Analysis of Algorithms Instructor: Don McLaughlin.
Coursenotes CS3114: Data Structures and Algorithms Clifford A. Shaffer Department of Computer Science Virginia Tech Copyright ©
Department of Computer Science 1 COSC 2320 Section Room 104 AH 5:30 – 7:00 PM TTh Professor Olin Johnson Office 596 PGH
ASYMPTOTIC COMPLEXITY CS2111 CS2110 – Fall
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =
Fundamentals of Algorithms MCS - 2 Lecture # 8. Growth of Functions.
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 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
RUNNING TIME 10.4 – 10.5 (P. 551 – 555). RUNNING TIME analysis of algorithms involves analyzing their effectiveness analysis of algorithms involves analyzing.
CSC – 332 Data Structures Generics Analysis of Algorithms Dr. Curry Guinn.
Introduction to Analysis of Algorithms CS342 S2004.
Algorithmic Analysis Charl du Plessis and Robert Ketteringham.
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
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
Asymptotic Performance. Review: Asymptotic Performance Asymptotic performance: How does algorithm behave as the problem size gets very large? Running.
Data Structures Using C++ 2E
Searching Topics Sequential Search Binary Search.
Asymptotic Notation Faculty Name: Ruhi Fatima
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.
Ch03-Algorithms 1. Algorithms What is an algorithm? An algorithm is a finite set of precise instructions for performing a computation or for solving a.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
Chapter 3 Chapter Summary  Algorithms o Example Algorithms searching for an element in a list sorting a list so its elements are in some prescribed.
Big-O. Speed as function Function relating input size to execution time – f(n) = steps where n = length of array f(n) = 4(n-1) + 3 = 4n – 1.
Analysis of 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
Introduction to Algorithms
Data Structures Using The Big-O Notation 1.
CS 3343: Analysis of Algorithms
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
CS 201 Fundamental Structures of Computer Science
Analysis of Algorithms
Advanced Analysis of Algorithms
Searching, Sorting, and Asymptotic Complexity
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Estimating Algorithm Performance
Big-O & Asymptotic Analysis
Analysis of Algorithms
Presentation transcript:

CS 3610/5610N data structures Lecture: complexity analysis Data Structures Using C++ 2E1

Time matters Data Structures Using C++ 2E2

To understand a data structure Data Structures Using C++ 2E3

4 Algorithm Analysis 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

Algorithm Analysis (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 = 50 miles –Total distance traveled: = 100 miles Data Structures Using C++ 2E5 FIGURE 1-2 Package delivering scheme

Algorithm Analysis (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 Data Structures Using C++ 2E6 FIGURE 1-3 Another package delivery scheme

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

Data Structures Using C++ 2E8 Algorithm Analysis (cont’d.) Analyzing an algorithm –Count number of operations performed Not affected by computer speed TABLE 1-1 Various values of n, 2n, n 2, and n 2 + n

Data Structures Using C++ 2E9 Algorithm Analysis (cont’d.) Example 1-1 –Illustrates fixed number of executed operations

Analysis of Example 1-1 –Line 1 has one operation, <<; –Line 2 has two operations; –Line 3 has one operation, >=; –Line 4 has one operation, =; –Line 6 has one operation; and –Line 7 has three operations. –Either Line 4 or Line 6 executes. Therefore, the total number of operations executed in the preceding code is = 8. In this algorithm, the number of operations executed is fixed. Data Structures Using C++ 2E10

Data Structures Using C++ 2E11 Algorithm Analysis (cont’d.) Example 1-2 –Illustrates dominant operations

Analysis of Example 1-2 –Before the while loop: 5 operations (lines 1 – 4) –After the while loop: 9 or 8 operations (depends on whether line 11 or line 13 executes) –The while loop: 1 operation (line 5) 4 operations (lines 6-8) Note: the loop head (line 5) will be executed one more time than the body to terminate the loop. Therefore, if the loop runs k times, the total number of operations is 5 + (k*5 + 1) + 9 or 5 + (k*5 + 1)

Data Structures Using C++ 2E13 Algorithm Analysis (cont’d.) Another example: Search algorithm –n: represents list size –f(n): count function Number of comparisons in search algorithm –c: units of computer time to execute one operation –cf(n): computer time to execute f(n) operations –Constant c depends computer speed (varies) –f(n): number of basic operations (constant) –Determine algorithm efficiency Knowing how function f(n) grows as problem size grows

Data Structures Using C++ 2E14 Algorithm Analysis (cont’d.) TABLE 1-2 Growth rates of various functions

Data Structures Using C++ 2E15 Algorithm Analysis (cont’d.) Figure 1-4 Growth rate of functions in Table 1-3 TABLE 1-3 Time for f(n) instructions on a computer that executes 1 billion instructions per second Picture from the textbook; the curve 2^n is wrong

Data Structures Using C++ 2E16 The Big-O Notation 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)=n 2 (no linear term) f(n)=n 2 + 4n + 20

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

Data Structures Using C++ 2E18 Algorithm Analysis: The Big-O Notation (cont’d.) Algorithm analysis –If function complexity can be described by complexity of a quadratic function without the linear term We say the function is of O(n 2 ) or Big-O of n 2 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 n 0 such that f(n) = n 0

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

Three time complexities Data Structures Using C++ 2E20

Running time, cont’d Data Structures Using C++ 2E21

Running time of iterative functions The routine “Example 1-2” is an iterative example The number of operations can usually be calculated through the summation of the operations within individual steps/stages. Data Structures Using C++ 2E22

Recursive example: merge sort 23

Merge() Data Structures Using C++ 2E24

Time complexity of Merge Sort Data Structures Using C++ 2E25 A constant-time step A linear-time step

Time complexity 26

Big-O notation: revisit Data Structures Using C++ 2E27

Asymptotic notation Data Structures Using C++ 2E28

Big-O, Big-Omega, Big-Theta Data Structures Using C++ 2E29

Example Data Structures Using C++ 2E30

Example, cont’d Data Structures Using C++ 2E31

Logarithms Data Structures Using C++ 2E32

Some rules about Big-O notations Data Structures Using C++ 2E33

Some rules about Big-O notations, cont’d Data Structures Using C++ 2E34

Some rules about Big-O notations, cont’d Data Structures Using C++ 2E35

Important notation Data Structures Using C++ 2E36

Big Omega notation Data Structures Using C++ 2E37

Big Theta notation 38

Big-O, Big-Omega, Big-Theta Data Structures Using C++ 2E39

Amortized complexity (won’t show up in homework/exam) Sometimes, worst case performance is a poor indicator of the running time of a given algorithm because infrequent executions of the algorithm may take a long time (worst case), but, in aggregate, the algorithm actually performs very well. Since algorithm designers usually use basic algorithms over and over again in larger tasks, these infrequent worst case executions can be “smoothed out.” Data Structures Using C++ 2E40

Amortized complexity, Cont’d The technique used to describe this behavior is referred to as “amortized complexity” because it consider the running time of an algorithm over a collection of invocations. Amortized complexity is still worst case complexity —- however, it provides a way of describing the worst case complexity of a collection of operations. Data Structures Using C++ 2E41

Amortized complexity An example: your daily expenditure in college –Regular days: meals, transportations, laundry, etc $25 –Once a while: rental $600 –Once a semester: tuition due $5,000 Single-day worst case: $5,625 Amortized complexity: much better than the worst case. In algorithm/data structure designs, we also often consider the amortized complexity --- looking at certain solution from a longitudinal perspective. Data Structures Using C++ 2E42