Runtime Analysis - PowerPoint PPT Presentation

About This Presentation
Title:

Runtime Analysis

Description:

Project is Due Friday visit the writing center. Slides are on ... Seabiscuit. Runtime of programs. Measure some 'size' of the input. the value of some integer ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 12
Provided by: thaddeusf
Category:

less

Transcript and Presenter's Notes

Title: Runtime Analysis


1
Runtime Analysis
  • CSC 172
  • SPRING 2004
  • LECTURE 4

2
General
  • Project is Due Friday visit the writing center
  • Slides are on
  • http//www.cs.rochester.edu/pawlicki/CSC172SP04
  • Start reading Weiss Chapter 6 (this week next)

3
BEST PICTURE?
  • The Lord of the Rings The Return of the King
  • Lost in Translation
  • Master and Commander The Far Side of the World
  • Mystic River
  • Seabiscuit

4
Runtime of programs
  • Measure some size of the input
  • the value of some integer
  • The length of a string or array

5
Program Analysis
  • Basis cases (simple statements) constant time
  • Assignments
  • Break, continue, return
  • System.in.println()
  • Induction
  • Loops
  • Branching (if, if-else)
  • Blocks .

6
Blocks
  • Blocks Running time bound is the sum of the
    bounds of the consitutents
  • Use summation law to drop from the sum any term
    that is Big-Oh of another term

7
Conditionals
  • Bound is O(1)larger of the bounds for the then
    and else clauses
  • O(1) for the cost of the test

8
Loops
  • Bound is usually the maximum number of times
    around the loop times the bound on the body of
    the loop.
  • We must include O(1) for the increment and test
    each time around a loop
  • The possibility exists that the loop executes 0
    times, this costs O(1) for the initialization and
    the first test

9
Structure Tree
  • Nodes are complex statements
  • Children are constituent statements

10
  • public String int2bin(int n)
  • String rval
  • while (ngt0)
  • if((n2) 1)
  • rval 0
  • else
  • rval 1
  • n/2
  • return rval

1 2 3 4 5 6 7 8 9
O(log2n)
1-9
O(1)
O(1)
O(log2n)
2-8
9
1
log2n times
3-7
O(1)
O(1)
O(1)
3-6
7
O(1) max
6
4
O(1)
O(1)
11
Reductions
  • Use summation law to drop from the sum any term
    that is Big-Oh of another
  • O(1) O(1) O(1)
  • O(1) O(log2i) O(1) O(log2i)
  • Looping
  • O(1) log2i O(log2i)
Write a Comment
User Comments (0)
About PowerShow.com