Beruflich Dokumente
Kultur Dokumente
Homework
Read Section 1.4 (recap of data
structures)
pages 26-37
Answer the following questions:
Agenda
WTF?
Euclids algorithm
What is an algorithm
What is algorithm analysis all about
Problem types
WTF?
Euclids Algorithm
while n != 0 do
r m mod n
mn
nr
return m
Isnt it a cool algorithm?
Its very efficient, no?
How many divisions must it do, as a
function of m or n?
Euclids Algorithm
Best case: m mod n equal zero
Worst case?
Try This
Two prime numbers 29 and 7
Then try 13 and 8.
How can you cause the worst case?
Euclids Algorithm
Answer: Two consecutive Fibonacci
numbers.
In the worst case it will require about
L divisions
Euclids Algorithm
If I have two 10 digit numbers,
Euclids algorithm will take (at most)
about 20 divisions.
Whereas, consecutive integer
checking could take 9,999,999,999 X
2 divisions.
How does Euclids algorithm gain
such an advantage?
Euclids Algorithm
r m mod n
If r is not equal to zero then all the
numbers between m and r are NOT
gcds of m and n.
Its all about understanding the
properties of the problem.
An Algorithm
A sequence of unambiguous
instructions for solving a problem,
i.e., for obtaining a required output
for any legitimate input
in a finite amount of time.
History Lesson
Notion of algorithm
problem
algorithm
input
computer
output
Statement of problem:
Algorithms:
Selection sort
Insertion sort
Merge sort
(many others)
Example
Algorithm:
for i=1 to n
swap a[i] with smallest of a[i],a[n]
Brute force
Decrease and
conquer
Transform and
conquer
Greedy approach
Dynamic
programming
Backtracking and
Branch and bound
Space and time
tradeoffs
Analysis of Algorithms
Sorting
Searching
Shortest paths in a graph
Minimum spanning tree
Primality testing
Traveling salesman problem
Knapsack problem
Chess
Towers of Hanoi
Program termination
Why do we care?
Theoretical analysis
Empirical analysis (experiments)
Optimality
What is an algorithm?
1.
2.
Definiteness
3.
Output
5.
Input
4.
Effectiveness
Theoretical importance
the core of computer science
Practical importance
A practitioners toolkit of known algorithms
Intrinsically related
Sorting can make searching easier
Amazingly well-studied
Surprisingly difficult problem for certain
variations
Tons of applications:
Approximate matching used in spell checkers
Pattern matching used to find genes in DNA
Or, used to find patterns in the stock market
Graph Problems
Combinatorial Problems
Geometric Problems
These problems can be as simple as
finding the intersection point of two
lines to
Finding the Delaunay Triangulation of
the smallest convex polygon
containing a given set of points.
These types of problems arise from
modeling all sorts of real-world
entities.
Numerical Problems
Problems involving mathematical
objects
solving equations
computing integrals
efficiently evaluating functions
i.e., really boring stuff
Data Structures
Homework
Read Section 1.4 (recap of data
structures)
pages 26-37
Answer the following questions: