390 likes | 547 Views
Syllabus. Go to www.cs.siena.edu/~ebreimer Click Analysis of Algorithms link 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
E N D
Syllabus • Go to • www.cs.siena.edu/~ebreimer • Click Analysis of Algorithms link • 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.
Grading 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 Syllabus
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 • Input • Output • Precision • Determinism • Finiteness • Correctness • 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. Precision max(a,b,c) { compare a, b, and c and return the largest value; } Not precise!
max(a,b,c) { if (a > b && a > c) return a; else if (b > c) return b; else return c; } Very precise 3. Precision
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?
max(a,b,c) { if (a > b) return a; else if (b > c) return b; else return c; } What if a = 5 b = 4 c = 6 6. Correctness
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. Generality max(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 • Design an algorithm to find the closest pair of points
Closest Pair • Designing algorithms is more of an art than a science.
Closest Pair • Visually this problem is very simple to solve, but what if I gave you 1 million points?
Closest Pair • What if I asked you to solve this problem for 1 million different cases?
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 Pair The 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 Pair The 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 • How do you compute the distance between to points? • 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; }
Closest Pair d = 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 Pair ClosestPair(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 Pair ClosestPair(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 Pair • Compare P[a] and P[b]
Closest Pair • Compare P[a] and P[b]
Closest Pair • Compare P[a] and P[b]
Closest Pair ClosestPair(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 n2entries must we compute?
Summations • n-1 + n-2 +n-3 +...+3 +2 +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. • Some algorithms only work on certain “types” of input. • Some algorithms require pseudo-random processing • 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.