








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
A portion of lecture notes from a discrete mathematics course, specifically covering the topics of algorithmic complexity, time complexity, space complexity, and orders of growth. It includes definitions, examples, and analyses of the max algorithm and linear search, as well as a review of key concepts.
Typology: Study notes
1 / 14
This page cannot be seen from the preview
Don't miss anything!









Discrete Mathematics
Kemal Akkaya
Department of Computer Science
Discrete Mathematics
Kemal Akkaya
The
algorithmic complexity
of a computation is,
most generally, a measure of how
difficult
it is to
perform the computation. z That is, it measures some aspect of the
cost
of
computation (in a general sense of “cost”).^ z^ Amount of resources required to do a computation. z Some of the most common complexitymeasures:^ z^ “Time” complexity: # of operations or steps required^ z^ “Space” complexity: # of memory bits required
Discrete Mathematics
Kemal Akkaya
Suppose algorithm A has worst-case timecomplexity (w.c.t.c., or just
time
)^ f (
n ) for
inputs of length
n , while algorithm B (for
the same task) takes time
g (
n ).
z^ Suppose that
f ∈
g ).
z^ Which algorithm will be
fastest
on all
sufficiently-large, worst-case inputs?^ z^ f(n)
is at most order of
g(n),
and hence faster
Discrete Mathematics
Kemal Akkaya
Problem:
Find the
simplest form
of the
exact
order of growth (
Θ) of the
worst-
case
time complexity (w.c.t.c.) of the max
algorithm, assuming that each line of code takes some constant time everytime it is executed (with possibly differenttimes for different lines of code).
Discrete Mathematics
7
Kemal Akkaya
Now, what is the simplest form of the exact(
Θ) order of growth of
t ( n
)( )( ) (^1) ( ) (^1) ( )( ) (^1) (
) (^1) ( ) 1 ( ) (^1) ( ) (^1) ( ) (^1) (
) (^1) (
) (
)(
2
4
2
3 2
1
n n
n
n
t t t t nt
n i n i
Θ= Θ+ Θ= Θ Θ+ Θ=
Θ −
Θ= Θ+ ⎞ ⎟ ⎠ ⎛^ ⎜ ⎝
Θ
Θ=
⎞ +⎟ ⎠
⎛^ ⎜ ⎝
=
Discrete Mathematics
Kemal Akkaya
linear search
( x
: integer,
a ,^1
a^2
an
: distinct integers)
i^ :=
t^1
while
( i^
≤^ n
x^ ≠
a ) i
t^2
i^ :=
i^ + 1
t^3
if^ i
n^ then
location
i^
t^4
else
location
t^5
return
location
t^6
Discrete Mathematics
Kemal Akkaya
Algorithmic complexity =
cost
of computation.
z^ Focus on
time
complexity for our course.
z^ Although space & energy are also important. z^ Characterize complexity as a function of inputsize: Worst-case, best-case, or average-case. z^ Use orders-of-growth notation to conciselysummarize the growth properties of complexityfunctions.
Discrete Mathematics
11
Kemal Akkaya
binary search
( x :integer
, a^1
,^ a^2
, …,
a^ : distinct integers, sorted smallest to n largest) i^ :=
1 j^ :=
n while
i < j
begin m^ :=
⎣( i +
j )/
⎦
if^ x
a^ m
then
i^ :=
m +
else
j^ :=
m
end if^ x
=^ a
then i
location
:=
i^ else
location
:=
0
return
location
Θ(1)
Θ(1)
Θ(1)
Key question: How many loop iterations?
Discrete Mathematics
Kemal Akkaya
Θ(1)
Constant
z^ Θ
(log
nc )Logarithmic (same order
∀ c
)
z^ Θ
(log
c^ n
)Polylogarithmic
z^ Θ
( n )
Linear
z^ Θ
c ( n )^
Polynomial (for any
c )
z^ Θ
n ( c )^
Exponential (for
c >1)
z^ Θ
( n !)
Factorial
(With
c^ a constant.)^ NP Problems
Discrete Mathematics
Kemal Akkaya
Definitions of algorithmic complexity,time complexity, worst-case timecomplexity. z Names of specific orders of growth ofcomplexity. z How to analyze the worst case, bestcase, or average case order of growth oftime complexity for simple algorithms.