
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of runtime analysis in cs 260, focusing on big o and θ notation, as well as simple sums. It includes examples, algorithms, and code adapted from data structures and other objects using c++ by main & savitch. The document aims to help students understand how to analyze the efficiency of algorithms as the input size grows.
Typology: Study notes
1 / 32
This page cannot be seen from the preview
Don't miss anything!

























CS 260
Big O,
, some simple sums. (see section 1.2 for motivation)
Notes, examples and code adapted from Data Structuresand Other Objects Using C++ by Main & Savitch
CS 260
-^
Some quick identities (just like integrals):
∑
∑
∑ ∑
∑
=
= +
) ( ) ( ) ( ) ( constant is c
where, ) (
) (
i g i f i g i f
i f
c
i cf i^
i
-^
Not like the integral:
∑
∑
=
=
b ai
a bi
CS 260
Problem:
to count the # of steps in the
Eiffel Tower
-^
Setup:
Jack and Jill are at the top of the
tower w/paper and a pencil
CS 260
st
attempt:
T
(n) = 2n + n = 3n 1
CS 260
= 2 * n(n+1)/2= n
2
T
(n) = n 2
2
CS 260
rd
try:
ground
10
( n )
T
(n) = log 3
10
( n )
CS 260
(n) is a line (^1) – So, if we double the # of stairs, the runtimedoubles
(n) is a parabola (^2) – So, if we double the # of stairs, the runtimequadruples (roughly)
(n) is a logarithm (^3) – We’d have to multiply the number of stairs bya factor of 10 to increase T by 1 (roughly)– Very nice function
CS 260
-^
Suppose 3 stairs (or 3 marks) can be made per 1second
-^
(There are really 2689 steps)
2 sec
2 sec
2 sec
T
(n) 3
252 days
112 days
28 days
T
(n) 2
135 min
90 min
45 min
T
(n) 1
3n
2n
n
CS 260
design point of view) we don’t want toconcern ourselves with lower-level details:– processor speed– the presence of a floating-point coprocessor– the phase of the moon
function grows as n grows
arbitrarily large
asymptotic
behavior
CS 260
more and more by its highest-order term(so we don’t really need to consider lower-order terms)
really of interest either. A line w/a steepslope will eventually be overtaken by eventhe laziest of parabolas (concave up).That coefficient is just a matter of scale.Irrelevant as n
CS 260
no slower than f(n)
(n)
below with f(n)
CS 260
counting, what might vary over thealgorithm, and what actions are constant
for(
i=0;
i<5;
++i
++cnt;
^6
times
CS 260
CS 260
can be given by:
i
4 0
=
times, and each loop has a constant cost