























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
An introduction to Algorithm Analysis, focusing on the goal of the course, the concept of algorithms, algorithm design and analysis, problem solving, and specific algorithms such as Euclid's algorithm and sequential search. It covers the importance of correctness, amount of work done, simplicity, clarity, and optimality in algorithm analysis.
Typology: Assignments
1 / 31
This page cannot be seen from the preview
Don't miss anything!
























As soon as an Analytical Engine exists, it will necessarily guide the futurecourse of the science. Whenever any result is sought by its aid, thequestion will then arise – By what course of calculation can these resultsbe arrived at by the machine in the shortest time?
- Charles Babbage, 1864
As soon as an Analytical Engine exists, it will necessarily guide the futurecourse of the science. Whenever any result is sought by its aid, thequestion will then arise – By what course of calculation can these resultsbe arrived at by the machine in the shortest time?
- Charles Babbage, 1864
Input/Output/Step: Analysis: Correct or wrong “good” or “bad” Implementation: Verification:
m , n ) if^ n =0^ then return
m else return
Euclid(
n ,^ m^ mod
n )
Specification Recursion AlgorithmPseudocode
seqSearch(
int [] E,^
int^ n,^ int
int^ ans, index; ans=-1; for^ (index=0; index<n; index++)^ if^ (K==E[index])
ans=index; break ; Return^
ans;
The Problem
: The Problem Searching a list for aspecific key.^ Input : an unordered array Ewith n entries, a key Kto be matched^ Output : the location of K in E(or^ fail )
: Searching a list for aspecific key. Input : an unordered array Ewith n entries, a key Kto be matched Output : the location of K in E(or^ fail )
m , n ) if^ n =0^ then return
m else return
Euclid(
n ,^ m^ mod ( m^ mod^ n ) is always less than^ n )
n , so,
if^ d^ is a common divisor of 1 the algorithm must terminate
m
and^ n , it must be a commondivisor of
n^ and ( m
mod^ n ) GCD recursion theorem:For any nonnegative integer^2
a^ and positive
integer^ b : gcd(
a , b ) = gcd(
b , ( a^ mod
b ))
Proof: gcd(
a , b ) | gcd(
b , ( a^ mod
b )), and gcd( b , ( a^
mod^ b )) | gcd(
a , b )
GCD recursion theorem:For any nonnegative integer
a^ and positive
integer^ b : gcd(
a , b ) = gcd(
b , ( a^ mod
b ))
Proof: gcd(
a , b ) | gcd(
b , ( a^ mod
b )), and gcd( b , ( a^
mod^ b )) | gcd(
a , b )