















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
Material Type: Notes; Class: ANALYSIS OF ALGORITHMS; Subject: Computer Science; University: Oregon State University; Term: Unknown 2002;
Typology: Study notes
1 / 23
This page cannot be seen from the preview
Don't miss anything!
















Computers and Computer Science
325- 265 BC, Euclid of Alexandria –Sometimes called the “grandfatherof Algorithms” invented Geometryand number theory.
~600 AD – Decimal system wasinvented in India
~780-850 AD – Al Khwarizmi
~1170-1250 AD – LeonardoFibonacci – popularized algorithmsin Europe
1448 – Guttenberg invented theprinting press
Fibonacci
Euclid
Turing Machine and Effective
Procedures
Alan Turing (1912-1954) isconsidered the Father ofComputer Science.
In 1936, he formalized thenotion of an
effective procedure
as a set of rules that can bemechanically followed by amachine.
The rules must be precise andunambiguous
For a procedure to be an algorithm
, the machine must
eventually stop with the correctanswer.
Some High-level Programming Languages (Turing equivalent)
Precise mechanical procedure to computecorrect answers to all instances of a problem.(Must terminate on all possible inputs.)
Are described in
pseudocode
that can be
translated to any programming language.
Three questions we ask about every algorithm
Is it correct?
How fast does it run?
Can we do better?
Computational problems are mathematical functionsfrom inputs to outputs:
Shortest Path Problem Input:
Map, starting address, destination
Output
: Directions for
shortest route
Sorting numbers Input
: A sequence of numbers, e.g., [5,8,1,2]
Output:
Sorted sequence of numbers, e.g., [1,2,5,8]
Problem instance is one particular possible input, e.g.,[5, 8, 1, 2]
The size of the instance is the length of its encoding,e.g., the number of numbers to be sorted. We use
n
to
denote problem size.
Do all problems have algorithms?
In general, the bigger the problem, the longer it takes tosolve it. So we make the time complexity
t(n),
a function
of the problem size
n
.
Even for the same size, some problems are more difficultthan others. Analyze the hardest problem of that size(
worst-case
complexity).
The exact time taken depends on
The programming language used to implement the algorithm
The compiler
The computer hardware
What other jobs are running in the machine
How much memory does one have
Network speed, etc.
We say a function
f = O(g)
if there is a
constant
c
such that
f(n)
c g(n)
for all
n
A function
f =
(g)
if
g = O(f)
A function
f =
(g)
if f
(g)
and
f=O(g)
0
900080007000600050004000300020001000
0
2
4
6
8
10
12
14
y=x^2y=x^3y=2^x
0
800000600000400000200000
12000001000000
0
5
10
15
20
25
y=x^2y=x^3y=2^x
Efficient usually means polynomial-time, although for someapplications, O(n^5) or even O(n^3) is not considered efficient;and for some applications, exponential worst-case is stillacceptable.
pseudocode.
following
recurrence relation
t(0) = 1; t(1)=2; t(n)= t(n-1)+t(n-2)+3.
So t(n) > F(n). This is bad because F(n)=1.
n
Fib1(4) = Fib1(3) + Fib1(2)
= Fib1(2)+Fib1(1)+Fib1(1)+Fib1(0)
= Fib1(1)+Fib1(0) + 1 + 1 + 0 = 1 + 0 + 1 + 1 + 0 = 3
Fib1(2) is calculated twice! To calculate Fib1(5), Fib1(3) will be called twice,
and Fib1(2) will be called 3 times, Fib1(1) will be called 4 times!
The number of redundant calculations increase
exponentially with n!