1 of 51 Interaction public int countCookiesEaten(Bowl bowl) { if (bowl.isEmpty()) { return 0; } else { this.eatCookie(bowl); return this.countCookiesEaten(bowl) + 1; }
Transcript
Slide 1
1 of 51 Interaction public int countCookiesEaten(Bowl bowl) {
if (bowl.isEmpty()) { return 0; } else { this.eatCookie(bowl);
return this.countCookiesEaten(bowl) + 1; }
Slide 2
2 of 51 Big-O and Sorting Lecture 15
Slide 3
3 of 51 Importance of Algorithm Analysis 1/2 Performance of an
algorithm often refers to how quickly it executes and/or how much
memory it needs o performance matters when the data grows in size!
o can observe and/or analyze, then tune or revise algorithm
Algorithm analysis is so important that every Brown CS student is
required to take at least one course covering it
Slide 4
4 of 51 Importance of Algorithm Analysis 2/2 Many important
factors that make performance important o computing resources o
implementation (like machine, language) o size of data, denoted N
number of elements to be sorted number of elements in ArrayList to
iterate through ex: much faster to search through CS15 course-list
than the Social Security Database This lecture: a brief
introduction to Algorithm Analysis! Goal: learning how to maximize
efficiency of an algorithm and conserve resources
Slide 5
5 of 51 Runtime The runtime of an algorithm varies with the
input and typically grows with the input size In most of computer
science we focus on the worst case running time. o easier to
analyze and important for unforeseen inputs Average case is what
will happen most often. Best case requires the least amount of work
and is the best situation you could have. o average case is also
important, best case is interesting but not insightful How to
determine runtime? o by inspecting pseudocode, can determine the
number of statements executed by an algorithm as a function of
input size o allows us to evaluate approximate speed of an
algorithm independent of the hardware or software environment o
memory use may be even more important for small and embedded
devices
Slide 6
6 of 51 Elementary Operations Algorithmic time is measured in
elementary operations o math (+, -, *, /, max, min, log, sin, cos,
abs,...) o comparisons ( ==, >,