1 / 37

Algorithms: Design and Analysis

Algorithms: Design and Analysis. 240-310 , Semester 2, 2018-2019. Objective to give some background on the course. Please ask questions. 0. Preliminaries. Who I am: Andrew Davison WiG Lab ad@fivedots.coe.psu.ac.th. 1. What is a Algorithm?.

kristyr
Download Presentation

Algorithms: Design and Analysis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algorithms: Design and Analysis 240-310, Semester2, 2018-2019 • Objective • to give some background on the course Please ask questions 0. Preliminaries Who I am: Andrew DavisonWiG Lab ad@fivedots.coe.psu.ac.th

  2. 1. What is a Algorithm? • An algorithm is a finite set of unambiguous instructions for solving a problem. • An algorithm is correct if on all legitimate inputs, it outputs the right answer in a finite amount of time • Can be expressed as • pseudocode • flow charts • text in a natural language (e.g. English) • computer code

  3. The Importance of Algorithms • Their impact is broad and far-reaching. • Internet. Web search, packet routing, distributed file sharing, ... • Biology. Human genome project, protein folding, ... • Computers. Circuit layout, file system, compilers, ... • Computer graphics. Movies, video games, virtual reality, ... • Security. Cell phones, e-commerce, voting machines, ... • Multimedia. MP3, JPG, DivX, HDTV, face recognition, ... • Social networks. Recommendations, news feeds, advertisements, ... • Physics. N-body simulation, particle collision simulation, ...

  4. The Top 10 Algorithms of the 20th Century • Ten algorithms having "the greatest influence on the development and practice of science and engineering in the 20th century". • Dongarra and SullivanTop Ten Algorithms of the CenturyComputing in Science and EngineeringJanuary/February 2000 • Barry CipraThe Best of the 20th Century: Editors Name Top 10 AlgorithmsSIAM NewsVolume 33, Number 4, May 2000 • http://www.siam.org/pdf/news/637.pdf

  5. What are the Top 10? • 1946: The Metropolis (Monte Carlo) Algorithm. Uses random processes to find answers to problems that are too complicated to solve exactly. • 1947: Simplex Method for Linear Programming.A fast technique for maximizing or minimizing a linear function of several variables, applicable to planning and decision-making. • 1950: Krylov Subspace Iteration Method.A technique for rapidly solving the linear equations that are common in scientific computation.

  6. 1951: The Decompositional Approach to Matrix Computations. A collection of techniques for numerical linear algebra. • 1957: The Fortran Optimizing Compiler. • 1959: QR Algorithm for Computing Eigenvalues. A crucial matrix operation made swift and practical. Application areas include computer vision, vibration analysis, data analysis. • 1962: Quicksort Algorithm. We will look at this.

  7. 1965: Fast Fourier Transform (FFT). It breaks down waveforms (like sound) into periodic components. Used in many different areas (e.g. digital signal processing , solving partial differential equations, fast multiplication of large integers.) • 1977: Integer Relation Detection. A fast method for finding simple equations that explain collections of data. • 1987: Fast Multipole Method. Deals with the complexity of n-body calculations. It is applied in problems ranging from celestial mechanics to protein folding.

  8. 2. Some Algorithm Types • Simple recursive algorithms • Backtracking • Brute force • Divide and conquer • Dynamic programming • Greedy algorithms • Randomized algorithms

  9. Simple Recursive • A simple recursivealgorithm: • Non-recursive base case • Recurs with a simpler subproblem • Examples: • Count the number of occurrence of an element in a tree • Test if a value occurs in a list • Fibonnaci number calculation • Several of the other algorithm types use recursion in more complex ways

  10. Fibonnaci numbers • The Fibonacci sequence: • 1, 1, 2, 3, 5, 8, 13, 21, 33, ... • Find the nth Fibonacci number: fib(int n) if (n <= 1) return 1; else return fib(n-1) + fib(n-2);

  11. lots of repeated work, that only gets worse for bigger n • Execution of fib(5):

  12. Backtracking • Backtracking algorithms use a depth-first recursive search • involves choice (non-determinism) • backtracking means "go back to where you came from" • Examples: • search a maze • color a map with no more than four colors

  13. Brute Force • A brute force algorithm tries all possibilities until a solution is found. • often this is implemented using backtracking • Brute force algorithms usually have exponential running time (very large time, so very slow) • Various heuristics and optimizations can be used • heuristic means “a rule of thumb” • e.g. look for sub-optimal solutions (not the best), which can be calculated more quickly than the best one

  14. Divide and Conquer • A divide and conquer algorithm: • Divide the problem into smaller subproblems • Combine the solutions to the subproblems into a solution to the original problem • Examples: • quicksort • merge sort • binary search

  15. Dynamic Programming • A dynamic programming algorithm remembers past results and uses them to find new results. • often use a table (2D array) to store results • memorization = remember results in a table • the problen contains repeating subproblems • since past results are stored, they can be reused instead of being calculated again

  16. Fibonacci numbers Again • Finding the nth Fibonacci number involves lots of repeated work that can be avoided using memorization:

  17. Greedy algorithms • At each step use the best solution you can get right now, and don't allow for backtracking to change the choice later • no backtracking makes the coding easier and faster • You hope that by choosing the best at each step, you will end up with the best combined final solution

  18. Example: Counting Money • Count out some money using the fewest possible notes and coins • A greedy algorithm will take the largest possible note or coin at each step • Example: count out $6.39 using: • a $5 bill • a $1 bill // to make $6 • a 25¢ coin // to make $6.25 • a 10¢ coin // to make $6.35 • four 1¢ coins // to make $6.39

  19. Greedy Algorithms Can 'Fail' • “Krons” money come in 1, 7, and 10 coins • Count out 15 krons: • A 10 kron piece • Five 1 kron pieces, for a total of 15 krons • This requires 6 coins, but a better solution is two 7 kron pieces and one 1 kron piece (3 coins) • The greedy algorithm 'fails' because its final solution is not the best

  20. Randomized Algorithms • A randomized algorithm uses a random number to make a choice during the computation • faster than calculating a choice • the choice may be just as good • Examples: • Quicksort randomly chooses a pivot • Factor a large number by choosing random numbers as possible divisors

  21. 3. Analysis of Algorithms The theoretical study of algorithm performanceand resource usage. Performance isn't the only important things for code: • modularity • user-friendliness • correctness • programmer time • maintainability • simplicity • functionality • extensibility • robustness • reliability This subject isn't about these things.

  22. Why study Algorithm Analysis? • It help us to understand algorithm scalability. • Performance often draws the line between what is feasible and what is impossible. • Algorithmic mathematics provides a precise way totalk about program behavior. • The lessons of program performance generalize to other computing resources.

  23. 4. Course Structure • Running time of programs • Backtracking • Divide-and-conquer; quicksort • Linear sorting • Hashing • Dynamic programming • Graph algorithms • search, shortest path • not minimum spanning trees, which was done in Discrete Maths • Heaps • P and NP problems

  24. Meeting Times / Locations • Monday 9:00 – 10:30 IDLWednesday 9:00 – 10:30 IDL • I want to change these times to be 3 classes/week, each of 1 hour. • Tell me your preferences.

  25. Workload • Mid-term exam: 35% (2 hours) • week 9 • Final exam: 45% (3 hours) • weeks 17-18 • Two exercises: 20%(2*10) • weeks 7-8 and weeks 15-16

  26. Non-Attendence Penalty • I may take registration at the start of a class. • If someone is not there, they lose 1%(unless they have a good excuse). • A maximum of 10% can be lost • deducted from your final mark

  27. Course Materials • All the handouts (and other materials)will be placed on-line at http://fivedots.coe.psu.ac.th/Software.coe/Algorithms/ • Print 6 slides-per-page, grayscale, and bring to class.

  28. 5. Books • Intro to Java Programming, Comprehensive, 10th ed.Y. Daniel Liang • http://www.cs.armstrong.edu/liang/intro10e/ • Topics • Generics, Collections (lists, stack, queues,sets, maps) • Sorting, searching • graph algorithms (2 chapters)

  29. Algorithms, 4th ed.Robert Sedgewick, Kevin Wayne • http://algs4.cs.princeton.edu/ • Introduction to Algorithms, 3rd ed.Thomas Cormen, Charles Leiserson, Ronald Rivest, Clifford Stein • lots of resources online; see video section

  30. การออกแบบและวิเคราะห์อัลกอริทึมการออกแบบและวิเคราะห์อัลกอริทึม ผู้แต่ง : สมชาย ประสิทธิ์จูตระกูล http://www.chulabook.com/ http://www.cp.eng.chula.ac.th/~somchai/books/ โครงสร้างข้อมูลและอัลกอริทึมData Structures and Algorithms) ผู้แต่ง : สุธี พงศาสกุลชัย&ณัฐพงษ์ วารีประเสริฐ http://ktpbook.com

  31. Fun Overviews • Algorithms UnlockedThomas H. CormenMIT Press, March 2013 • Nine Algorithms that Changed the FutureJohn MacCormickPrinceton University Press, 2011 • http://users.dickinson.edu/~jmac/9algorithms/ • search engine indexing, pagerank, public key cryptography, error-correcting codes, pattern recognition, data compression, databases, digital signatures, computablity

  32. Algorithmic PuzzlesAnany Levitin, Maria LevitinOxford University Press, , 2011 • Algorithmics: The Spirit of ComputingDavid Harel, Yishai FeldmanAddison-Wesley; 3 ed., 2004(and Springer, 2012) • http://www.wisdom.weizmann.ac.il/~harel/algorithmics.html

  33. The New Turing Omnibus: Sixty-Six Excursions in Computer ScienceA. K. DewdneyHolt, 1993 • 66 short article; e.g. detecting primes, noncomputable functions, self-replicating computers, fractals, genetic algorithms, Newton-Raphson Method, viruses

  34. 6. Videos • MIT 6.046J / 18.410J Intro. to Algorithms, Fall 2005 • http://ocw.mit.edu/6-046JF05 • original course website for Cormen book • http://videolectures.net/mit6046jf05_introduction_algorithms/ • video and slides side-by-side • http://www.catonmat.net/category/introduction-to-algorithms • notes taken while watching the videos

  35. Skiena's Algorithms Lectures • http://www3.cs.stonybrook.edu/~algorith/video-lectures/ • 1997, 2007, 2012

  36. Hi-tech TrekRoyal Institution Christmas Lectures 2008 • A hi-tech trek through the world of computer science by Professor Chris Bishop; aimed at school kids. • Lecture 1: Breaking the speed limit • Lecture 2: Chips with everything • Lecture 3: Ghost in the machine • Lecture 4: Untangling the web • Lecture 5: Digital intelligence • http://richannel.org/christmas-lectures/2008/ • I have copies on a DVD

  37. 7. Web Sites • Algorithm Tutorials • http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=alg_index • Algorithmy • http://en.algoritmy.net/ • brief explanations and code • Algorithmist • http://algorithmist.com/index.php/Main_Page • explanations and code • Wikipedia page for an algorithm • e.g. http://en.wikipedia.org/wiki/Quicksort

More Related