1 / 118

Introduction

Algorithm Design. Introduction. Pizzanu Kanongchaiyos, Ph.D. pizzanu@cp.eng.chula.ac.th. What is Algorithm? A detailed sequence of actions to perform to accomplish some task. Named after an Iranian mathematician, Al-Khawarizmi. algorithm[N] ชุดของคำสั่งที่สร้างไว้ตามขั้นตอน

penn
Download Presentation

Introduction

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. Algorithm Design Introduction Pizzanu Kanongchaiyos, Ph.D. pizzanu@cp.eng.chula.ac.th

  2. What is Algorithm? • A detailed sequence of actions to perform to accomplish some task. Named after an Iranian mathematician, Al-Khawarizmi. • algorithm[N] ชุดของคำสั่งที่สร้างไว้ตามขั้นตอน • algorithm[N] ลำดับขั้นตอนที่แน่นอนซึ่งใช้ในการแก้ปัญหา • algorithm(แอล' กะริธธึม) n. ระบบกฏเกณฑ์ในการแก้ปัญหาของจำนวนที่แน่นอนทางคณิตศาสตร์ เช่นในการหาค่าของตัวหารร่วมที่สุด., • S. algorism, -algorithmic adj. ขั้นตอนวิธีอัลกอริทึมหมายถึง การวิเคราะห์แยกแยะวิธีการทำงานให้เป็นขั้นเป็นตอนโดยกำหนดให้ เรียงกันไปตามลำดับ การเขียนโปรแกรมในยุคแรก ๆ นั้น ผู้เขียนโปรแกรมจะต้องมองเห็นขั้นตอนในการแก้ปัญหาอย่างแจ่มชัด เสียก่อน จึงจะเขียนโปรแกรมได้

  3. So you want to be a computer scientist?

  4. Is your goal to be a mundane programmer?

  5. Or a great leader and thinker?

  6. Original Thinking

  7. Boss assigns task: • Given today’s prices of pork, grain, sawdust, … • Given constraints on what constitutes a hotdog. • Make the cheapest hotdog. Everyday industry asks these questions.

  8. Your answer: • Um? Tell me what to code. With more suffocated software engineering systems,the demand for mundane programmers will diminish.

  9. Your answer: • I learned this great algorithm that will work. Soon all known algorithms will be available in libraries.

  10. Your answer: • I can develop a new algorithm for you. Great thinkers will always be needed.

  11. The future belongs to the computer scientist who has • Content: An up to date grasp of fundamental problems and solutions • Method: Principles and techniques to solve the vast array of unfamiliar problems that arise in a rapidly changing field • Rudich www.discretemath.com

  12. Course Content • A list of algoirthms. • Learn their code. • Trace them until you are convenced that they work. • Impliment them. class InsertionSortAlgorithm extends SortAlgorithm { void sort(int a[]) throws Exception { for (int i = 1; i < a.length; i++) { int j = i; int B = a[i]; while ((j > 0) && (a[j-1] > B)) { a[j] = a[j-1]; j--;} a[j] = B; }}

  13. Course Content • A survey of algorithmic design techniques. • Abstract thinking. • How to develop new algorithms for any problem that may arise.

  14. Study: • Many experienced programmers were asked to code up binary search.

  15. Study: • Many experienced programmers were asked to code up binary search. 80% got it wrong Good thing is was not for a nuclear power plant.

  16. What did they lack?

  17. What did they lack? • Formal proof methods?

  18. What did they lack? • Formal proof methods? Yes, likely Industry is starting to realize that formal methods are important. But even without formal methods …. ?

  19. What did they lack? • Fundamental understanding of the algorithmic design techniques. • Abstract thinking.

  20. Course Content Notations, analogies, and abstractions for developing, thinking about, and describing algorithms so correctness is transparent

  21. A survey of fundamental ideas and algorithmic design techniques For example . . .

  22. Classifying Functions Time Complexity t(n) = Q(n2) f(i) = nQ(n) Time Input Size Recurrence Relations Adding Made Easy T(n) = a T(n/b) + f(n) ∑i=1 f(i). Start With Some Math

  23. 0 i-1 i T+1 i i 9 km 5 km Iterative Algorithms Loop Invariants <preCond> codeA loop <loop-invariant> exit when <exit Cond> codeB codeC <postCond> One step at a time Code Relay Race

  24. ? ? Recursive Algorithms

  25. Graph Search Algorithms

  26. Network Flows

  27. Greedy Algorithms

  28. Recursive Back Tracking

  29. Dynamic Programing

  30. Reduction = • Rudich www.discretemath.com

  31. Useful Learning Techniques

  32. Read Ahead You are expected to read the lecture notesbefore the lecture. This will facilitate more productive discussionduringclass.

  33. We are going to test you on yourability to explain the material. Hence, the best way of studying is to explain the material over and over again out loud toyourself, to each other, and to your stuffed bear. Explaining

  34. While going along with your day Day Dream Mathematics is not all linear thinking. Allow the essence of the materialto seepinto your subconscious Pursue ideas that percolate up and flashes of inspiration that appear.

  35. Be Creative Ask questions. Why is it done this way and not thatway?

  36. Guesses and Counter Examples • Guess at potential algorithms for solving a problem. • Look forinput instances for which your algorithm gives the wrong answer.

  37. Refinement:The best solution comes from a process of repeatedly refining and inventing alternative solutions

  38. 2 X 2 = 5 A Few Example Algorithms Grade School Revisited:How To Multiply Two Numbers

  39. Complex Numbers • Remember how to multiply 2 complex numbers? • (a+bi)(c+di) = [ac –bd] + [ad + bc] i • Input: a,b,c,d Output: ac-bd, ad+bc • If a real multiplication costs $1 and an addition cost a penny. What is the cheapest way to obtain the output from the input? • Can you do better than $4.02?

  40. Gauss’ $3.05 Method:Input: a,b,c,d Output: ac-bd, ad+bc • m1 = ac • m2 = bd • A1 = m1 – m2 = ac-bd • m3 = (a+b)(c+d) = ac + ad + bc + bd • A2 = m3 – m1 – m2 = ad+bc

  41. Question: • The Gauss “hack” saves one multiplication out of four. It requires 25% less work. • Could there be a context where performing 3 multiplications for every 4 provides a more dramatic savings?

  42. Odette Bonzo

  43. How to add 2 n-bit numbers. ** ** ** ** ** ** ** ** ** ** ** +

  44. How to add 2 n-bit numbers. ** ** ** ** ** ** ** ** ** * ** ** * +

  45. How to add 2 n-bit numbers. ** ** ** ** ** ** ** ** * ** * ** * ** * +

  46. How to add 2 n-bit numbers. ** ** ** ** ** ** ** * ** * ** * * ** * ** * +

  47. How to add 2 n-bit numbers. ** ** ** ** ** ** * ** * ** * * ** * * ** * ** * +

  48. How to add 2 n-bit numbers. * * * ** * * ** * * ** * * ** * * ** * *** * * ** * * ** * * ** * * ** * ** * +

  49. * * * ** * * ** * * ** * * ** * * ** * * ** * * ** * * ** * * ** * * ** * ** * + Time complexity of grade school addition On any reasonable computer adding 3 bits can be done in constant time. T(n) = The amount of time grade school addition uses to add two n-bit numbers = θ(n) = linear time.

  50. f = θ(n) means that f can be sandwiched between two lines time # of bits in numbers

More Related