CIS 3020 Part 7

From In The Wings
Revision as of 10:22, 26 April 2007 by Jka (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Complexity

  • When computing O(), we are concerned with big values of n
  • With big values, constants become ignorable
  • Consider the two exponential functions we developed
  • Let's count all operations (arithmetic, assignment, references, comparisons, etc.) the same with calls counting 20.
public int expt(int b, int n) {
  int result;
  if (n<=0) {
    result = 1;
  } else {
    result = b * expt(b, n-1);
  }
  return result;
}

2
1
3
3

28

2
=======
39