CSC 2300 Data Structures - PowerPoint PPT Presentation

About This Presentation
Title:

CSC 2300 Data Structures

Description:

... Oh is an upper bound, we must not underestimate the running time of the program. ... is a guarantee that the program will terminate within a certain time period. ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 24
Provided by: stude6
Learn more at: http://www.cs.rpi.edu
Category:
Tags: csc | data | structures

less

Transcript and Presenter's Notes

Title: CSC 2300 Data Structures


1
CSC 2300Data Structures Algorithms
  • January 23, 2007
  • Chapter 2. Algorithm Analysis

2
Today
  • Counting operations
  • Algorithm analysis
  • Order notation
  • Running time calculations

3
Example 1 Search
  • Sequential search

4
Example 2 Sort
  • Insertion Sort

5
Preliminary Analysis
6
Algorithm Analysis Rules
7
Computation Time
8
Typical Growth Rates
9
Order Notation
10
Graph of O(f(n))
11
Graph of T(f(n))
12
Graph of O(f(n))
13
Use of Limits
14
Two Examples
15
Order Notation Manipulation Rules
16
Big-Oh Estimate for Summation
  • Evaluate the summation using techniques we have
    learned. Then determine an O (or T) estimate from
    the resultant function.
  • Place upper bounds on terms inside the summation
    to simplify the terms and eliminate the summation.

17
Running Time Calculations
  • We assume no particular units of time. Thus, we
    throw away leading constants.
  • We also throw away low-order terms.
  • Since Big-Oh is an upper bound, we must not
    underestimate the running time of the program.
  • Our answer is a guarantee that the program will
    terminate within a certain time period. The
    program may stop earlier, but never later.

18
Four Rules
  • FOR loops
  • Nested loops
  • Consecutive statements
  • If/Else

19
FOR Loops
  • The running time of a FOR loop is at most the
    running time of the statements inside the FOR
    loop (including tests) times the number of
    iterations.

20
Nested Loops
  • Analyze these inside out. The total running time
    of a statement inside a group of nested loops is
    the running time of the statement multiplied by
    the product of the sizes of all the loops.

21
Consecutive Statements
  • These just add, which means that the maximum is
    the one that counts.

22
If/Else
  • if condition
  • S1
  • else
  • S2
  • The running time of an if/else statement is never
    more than the running time of the test plus the
    larger of the running times of S1 and S2.

23
Two More Examples
Write a Comment
User Comments (0)
About PowerShow.com