90 likes | 166 Views
CS 330: Algorithms. Gene Itkis. Algorithms: What?. Systematic procedure that produces — in a finite number of steps — the solution of a problem Encyclopædia Britannica Euclid (300 BC): gcd algorithm Other examples (that you already know/use) : Division, multiplication Sorting/searching
E N D
CS 330: Algorithms Gene Itkis
Algorithms: What? • Systematic procedure that produces—in a finite number of steps—the solution of a problemEncyclopædia Britannica • Euclid (300 BC): gcd algorithm • Other examples (that you already know/use): • Division, multiplication • Sorting/searching • … Gene Itkis
Algorithms: Why? • Performance • Structure/Modularity • Maintanability + Extensibility + Robustness • Simplicity • Correctness • Reliability • Scalability • Predictability • Job security • … Gene Itkis
Algorithms: Why? (take 2) • Web/Internet: • Searching • sorting, selection, search trees, matrix computation, … • Networking & Routing • Shortest path, MST, connectivity, nearest neighbors, flow, … • Communication • Data compression, error-detecting/correcting codes • Security/Cryptography • Large numbers arithmetic, primes generation, RSA, … • IDS/Firewalls: string matching, finite automata,… • … Gene Itkis
Algorithms: Why? (take 2) • Image, Video, Audio • JPEG, MPEG, fractal coding,… • Graphics • Geometric algorithms, ray tracing, … • Biology • String alignment, DNA sequencing, … • Scientific simulations • Eigenvalues, triangulation, … • Other/everywhere • Optimization, linear programming, … • Scheduling • … Gene Itkis
Algorithms: How? • This course, of course • From bureaucrats to machines • Precision • Structure: • Modularity • Layers of abstraction • Analysis: proofs • Learn from Examples Gene Itkis
Problem statement • Input/output • Sorting • Input: Array[1…n] of n elements in arbitrary order • Output: Array[1…n] of the same n elements but in the non-decreasing order • Access methods • Dictionary • New() : creates a new empty dictionary • Insert(x, key) : inserts record x under the key • Find(key) : returns element x which was previously Inserted under the key (nil, if none) • … Gene Itkis
Sorting (review from cs112+) • Strategies • Greedy • Divide & Concur • Reduction • From a “bigger”/harder problem to a “smaller”/simpler one • Analysis • Recurrences • Do not forget details of implementation • Link-lists or Arrays? Gene Itkis
Selection Sort • Idea • Algorithm: • for i= 1 to n do// find min element in A[i...n]// and put it in the i'th position (i.e. at A[i]) • min_index <-- i • //locate minfor j= i+1 to n do • if A[j] < A[min_index] then min_index <-- j • //put the min where it belongsswap( A[i], A[min_index] ) 2 5 3 1 7 6 4 Gene Itkis