
















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
Key points of this lecture are: Analysis, 2 Dimensions, Maxima, Times, Output, Loop, Statement, Summations.
Typology: Slides
1 / 24
This page cannot be seen from the preview
Don't miss anything!

















[1... n
])
1 for^ i
←^1 to
n^ n times 2 do^ maximal
←^ true 3 for
j^ ←^1 to
n^ n times 4 do 5
if^ (i^6 =^ j
)&(P[i]
.x^ ≤^ P[
j].x)&(
P[i].y^ ≤
P[j].y)
4 accesses
6
then^ maximal
←^ false
break
7 if
maximal 8
then^ output
P[i].x, P
[i].y^
2 accesses
n^ times
-^ For each
i^ iteration, the inner loop runs
n
time. • P^ is accessed four times in the
if^ statement.
-^ The output statement accesses
P^ 2 times.
-^ In the worst case, every point is maximal soevery point is output.
T^ (n) =
( n∑^2 i= 1
n∑+ j=^1
∑n (j=^1 4 ) =^ 4n
, and so^ n∑ T (n) =^ i=
(4n^ + 1
= (4n
+^2 )n
=^ 4n
2 +^ 2n
n, any algorithm is fast
enough. • What happens when
n^ gets large?
-^ Running time does become an issue. •^ When
n^ is large,
(^2) nterm will be much larger
than the
n^ term and will dominate the running time.
, a,... , a^2
,n
-^ their sum
a+^1
a+^...^2
+^ an^
is expressed in
summation notation
as^ n∑^ ai^ i=^1
-^ If^ n^
=^0 , then the sum is additive identity,
: n ∑^ i^ =^ i=^1
+^ n n(n =
=^ Θ(n
n∑^2 i= i=^1
(^2) n (^3) 2n = 2 +^ 3n
+^ n= 6
(^3) Θ(n
: For^ n
H=n^
n∑^1 i i=^11 = 1 +^ +^2
(^1) + ≈ n^ ln^ n
=^ Θ(ln
n)
1 for
i^ ←^1
to^ n 2 do 3
for^ j^ ←
1 to^ 2i 4
do^ k^ =
j... 5
while^ (
k^ ≥^0 ) 6
do^ k^ =
k^ −^ 1...
1 for
i^ ←^1
to^ n 2 do 3
for^ j^ ←
1 to^ 2i 4
do^ k^ =
j... 5
while^ (
k^ ≥^0
6
do^ k^ =
k^ −^ 1... The answer is we write out the loops assummations and then solve the summations.
1 for
i^ ←^1
to^ n 2 do 3
for^ j^ ←
1 to^ 2i 4
do^ k^ =
j... 5
while^ (
k^ ≥^0
6
do^ k^ =
k^ −^ 1... To convert loops into summations, we work frominside-out.
n 2 do for
j^ ←^1 to
2i 3 do
k^ =^ j 4
while^ (k
≥^0 )^ J 5
do^ k^ =^
k^ −^1
-^ Time spent inside thewhile loop is constant. •^ Let^ I
()^ be the timespent in the while loop.Thus^ j^ ∑ I(j) =^ k=^0
1 =^ j^ +
n 2 do for
j^ ←^1 to
2i^ J 3 do
k^ =^ j 4
while^ (k
≥^0 ) 5
do^ k^ =^
k^ −^1
-^ Consider the
middle for loop. • It’s running time is de-termined by
i.