syllabus 1. go to 2. ebreimer ebreimer 3. click analysis of algorithms link 4. bookmark course...
Post on 21-Dec-2015
213 views
TRANSCRIPT
Syllabus1. Go to2. www.cs.siena.edu/~ebreimer3. Click Analysis of Algorithms link4. bookmark course website Important stuff
– Schedule all due dates– Quizzes details, solutions– Homework details, solutions
Syllabus
Highlights Quiz every Friday HW due every Monday No exams except a final
– Combination of quizzes and HWs No huge projects Some HW will be collaborative
Syllabus Late HWs get a zero
– Due at the beginning of class– Can drop 2 HWs
No quiz makeups– Miss a quiz, get a zero– Can drop 2 quizzes
Attendance 10%– 2 unexcused absences– -2% for each additional unexcused absence.
SyllabusGrading
40% Quizzes
30% HWs
20% Final
10% Attendance
A 93 or higher
A- 90 or higher
B+ 87
B 83
B- 80
C+ 77
C 73
C- 70
Chapter 1 – Intro What is an algorithm?
– 7 properties Two Examples
– Max of 3– Closest Pair
Pseudo-code Present Future
Algorithms? Definition: step-by-step method for solving a
problem We will concentrate on algorithms that can
be executed on modern computers– like the one you probably have
This field existed before computer existed– 900 AD in Persia
7 Properties
1. Input
2. Output
3. Precision
4. Determinism
5. Finiteness
6. Correctness
7. Generality
Examples
Problem: Given three integer values A, B, and C return the maximum value.
Input: 3 integers
Output: 1 integer
Examples
Problem: Given a list of N points, find the closest pair of points (2D)
Input: N points, where a point is a pair of real values (x,y).
Output: 2 points
3. Precisionmax(a,b,c) {
if (a > b && a > c)return a;
else if (b > c)return b;
elsereturn c;
}
Very precise
3. Precision A precise algorithm is one that can be
described by pseudo code or a high-level programming language like C++ or Java.
Pseudo code is like a high-level programming language where the syntax doesn’t have to be perfect.
4. Determinism Not random
– Given the same conditions, you expect the same outcome.
Computer are inherently deterministic. When computers behave randomly it is
usually a result of– human errors– environmental conditions– pseudo-random number generation
5. Finiteness Given finite input, an algorithm should
not run infinitely (i.e., forever). An algorithm that runs forever is not
really an algorithm because it will never solve the problem.
Recall that an algorithm is a step-by-step method for solving a problem.
What if the input is infinite?
6. Correctnessmax(a,b,c) {
if (a > b)
return a;
else if (b > c)
return b;
else
return c;
}
What if a = 5b = 4c = 6
6. Correctness
Algorithms that return incorrect answers aren’t really algorithms
Recall that an algorithm is a step-by-step method for solving a problem.
7. Generalitymax(a, b, c) {
if (a > 10 && b < 10 && c < 10)return a;
if (b > 10 && a < 10 && c < 10)return b;
if (c > 10 && b < 10 && a < 10)return c;
}Will never return an incorrect answer, but does not
apply to a general set of input (like all integers or all real numbers).
Closest Pair Visually this problem is very simple to
solve, but what if I gave you 1 million points?
Closest Pair What is the input? What is the output? What are the precise step-by-step
instructions? Will the algorithm terminate? Will it produce correct answers all the time? How much time will it take to solve? How much memory is required to solve the
problem?
Closest PairThe input: 2D point, a pair values (x, y)
– Point p;– p.x;– p.y;
An array of n Points– Point P[n]– P[0], P[1], P[2], P[3], …, P[n-1]
Closest PairThe output: Two points P[a] and P[b] where the
distance between P[a] and P[b] is minimum among all possible pairs of points.
Sometimes describing the output with precision gives you clues about how to solve the problem.
Closest Pair
1. How do you compute the distance between to points?
2. How do you find a distance is minimum among all possible pairs of points?
Closest Pair
dist(a,b){
d = sqrt[
pow((a.x – b.x),2) +
pow((a.y – b.y),2) ];
return d;
}
22 )()( baba yyxxd
Closest Paird = dist(P[0], P[1]);
Compare all possible pairs of points, i.e.,compare P[0] with P[1], P[2], P[3], …, P[n-1]compare P[1] with P[2], P[3], P[4], …, P[n-1]compare P[2] with P[3], P[4], P[5], …, P[n-1]compare P[3] with P[4], P[5], P[6], …, P[n-1]…compare P[n-3] with P[n-2], P[n-1]compare P[n-2] with P[n-1]
Closest PairClosestPair(P[ ], n) {
min_dist = dist(P[0],P[1]);for (x = 1 to n-1) {
d = dist(P[0], P[x]);if (d < min_dist) {
min_dist = d;}
}return min_dist;
}This is not correct!
Closest PairClosestPair(P[ ], n) {
min_dist = dist(P[0],P[1]);for (y = 0 to n-1) {
for (x = 1 to n-1) {d = dist(P[y], P[x]);if (d < min_dist) {
min_dist = d;}
}}return min_dist;
}
Closest PairClosestPair(P[ ], n) {
min_dist = dist(P[0],P[1]);for (y = 0 to n-1) {
for (x = y+1 to n-1) {d = dist(P[y], P[x]);if (d < min_dist) {
min_dist = d;}
}}return min_dist;
}
Closest Pair This matrix is n x n n2 entries. How many of these n2
entries must we compute?
a
b
0 1 2 3 ... n-1
0
1
2
3
...
n-1
The Present Remember the 7 properties? Many algorithms used in practice
aren’t – General– Deterministic, or– Finite
The Present There are problems that are just too
difficult to solve. Compromises must be made.
1. Some algorithms only work on certain “types” of input.
2. Some algorithms require pseudo-random processing
3. Some algorithms will run forever on certain “types” or problems.
The Present Today, an algorithm doesn’t have to satisfy
all the properties if the problem is very difficult and there is no other know way to get good answers.
Algorithms can be approximate, fuzzy, and even un-predicable.
Some Algorithm purist disagree with this. But, I think a half-baked algorithm is better
than no algorithm at all.
The Future Quantum computing.
– Uses a quantum bit which can store an manipulate information in a massivle parallel way.
– Theoretical only– Might be impossible to implement
DNA computing– DNA bases (A,C,G,T) will be used to represent
data– Biological processes can manipulate large
amounts of data in one step.