of 95
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
  CPS 230 DESIGN AND ANALYSISOF ALGORITHMS Fall 2008 Instructor:  Herbert Edelsbrunner Teaching Assistant:  Zhiqiang Gu  CPS 230 Fall Semester of 2008 Table of Contents 1 Introduction 3I D ESIGN  T ECHNIQUES  42 Divide-and-Conquer 53 Prune-and-Search 84 Dynamic Programming 115 Greedy Algorithms 14First Homework Assignment 17II S EARCHING  186 Binary Search Trees 197 Red-Black Trees 228 Amortized Analysis 269 Splay Trees 29Second Homework Assignment 33III P RIORITIZING  3410 Heaps and Heapsort 3511 Fibonacci Heaps 3812 Solving Recurrence Relations 41Third Homework Assignment 44IV G RAPH  A LGORITHMS  4513 Graph Search 4614 Shortest Paths 5015 Minimum Spanning Trees 5316 Union-Find 56Fourth Homework Assignment 60V T OPOLOGICAL  A LGORITHMS  6117 Geometric Graphs 6218 Surfaces 6519 Homology 68Fifth Homework Assignment 72VI G EOMETRIC  A LGORITHMS  7320 Plane-Sweep 7421 Delaunay Triangulations 7722 Alpha Shapes 81Sixth Homework Assignment 84VII NP-C OMPLETENESS  8523 Easy and Hard Problems 8624 NP-Complete Problems 8925 Approximation Algorithms 92Seventh Homework Assignment 952  1 Introduction Meetings.  We meet twice a week, on Tuesdays andThursdays, from 1:15 to 2:30pm, in room D106 LSRC. Communication.  The course material will be deliveredin the two weekly lectures. A written record of the lec-tures will be available on the web, usually a day after thelecture. The web also contains other information, such ashomework assignments, solutions, useful links, etc. Themain supporting text is T ARJAN .  Data Structures and Network Algorithms.  SIAM,1983. The book focuses on fundamental data structures andgraph algorithms, and additional topics covered in thecourse can be found in the lecture notes or other texts inalgorithms such as K LEINBERG AND  T ARDOS .  Algorithm Design.  Pearson Ed-ucation, 2006. Examinations.  There will be a final exam (covering thematerial of the entire semester) and a midterm (at the be-ginning of October), You may want to freshen up yourmath skills before going into this course. The weightingof exams and homework used to determine your grades ishomework 35%,midterm 25%,final 40%. Homework.  We have seven homeworks scheduledthroughout this semester, one per main topic covered inthe course. The solutions to each homework are due oneand a half weeks after the assignment. More precisely,they are due at the beginning of the third lecture after theassignment. The seventhhomeworkmay help you preparefor the final exam and solutions will not be collected.Rule 1. Thesolutionto anyone homeworkquestionmustfit on a singlepage(togetherwith the statementoftheproblem).Rule 2. The discussion of questions and solutions beforethe due date is not discouraged, but you must formu-late your own solution.Rule 3. The deadline for turning in solutions is 10 min-utes afterthe beginningof the lecture onthe due date. Overview.  The main topics to be covered in this courseareI Design Techniques;II Searching;III Prioritizing;IV Graph Algorithms;V Topological Algorithms;VI Geometric Algorithms;VII NP-completeness.The emphasis will be on algorithm  design  and on algo-rithm  analysis . For the analysis, we frequently need ba-sic mathematical tools. Think of analysis as the measure-ment of the quality of your design. Just like you use yoursense of taste to check your cooking, you should get intothe habit of using algorithm analysis to justify design de-cisions when you write an algorithm or a computer pro-gram. This is a necessary step to reach the next level inmastering the art of programming. I encourage you to im-plement new algorithms and to compare the experimentalperformance of your program with the theoretical predic-tion gained through analysis.3  I D ESIGN  T ECHNIQUES 2 Divide-and-Conquer3 Prune-and-Search4 Dynamic Programming5 Greedy AlgorithmsFirst Homework Assignment4  2 Divide-and-Conquer We use quicksort as an example for an algorithm that fol-lows the divide-and-conquer paradigm. It has the repu-tation of being the fasted comparison-based sorting algo-rithm. Indeed it is very fast on the average but can be slowfor some input, unless precautions are taken. The algorithm.  Quicksort follows the general paradigmof divide-and-conquer, which means it  divides  the un-sorted array into two, it  recurses  on the two pieces, and itfinally  combines  the two sorted pieces to obtainthe sortedarray. An interesting feature of quicksort is that the dividestep separates small from large items. As a consequence,combining the sorted pieces happens automatically with-out doing anything extra. void  Q UICK S ORT ( int  ℓ,r ) if  ℓ < r  then  m  =  S PLIT ( ℓ,r ) ;Q UICK S ORT ( ℓ,m − 1) ;Q UICK S ORT ( m  + 1 ,r ) endif .We assume the items are stored in  A [0 ..n − 1] . The arrayis sorted by calling Q UICK S ORT (0 ,n − 1) . Splitting.  The performance of quicksort depends heav-ily on the performanceof the split operation. The effect of splitting from  ℓ  to  r  is: •  x  =  A [ ℓ ]  is moved to its correct location at  A [ m ] ; •  no item in  A [ ℓ..m − 1]  is larger than  x ; •  no item in  A [ m + 1 ..r ]  is smaller than  x .Figure 1 illustrates the process with an example. The nineitems are split by moving a pointer  i  from left to rightand another pointer  j  from right to left. The process stopswhen  i  and  j  cross. To get splitting right is a bit delicate,in particular in special cases. Make sure the algorithm iscorrect for (i)  x  is smallest item, (ii)  x  is largest item, (iii)all items are the same. int  S PLIT ( int  ℓ,r ) x  =  A [ ℓ ] ;  i  =  ℓ ;  j  =  r  + 1 ; repeat repeat i ++ until  x  ≤  A [ i ] ; repeat  j -- until  x  ≥  A [  j ] ; if  i < j  then  S WAP ( i,j )  endifuntil  i  ≥  j ;S WAP ( ℓ,j ) ;  return  j . i jm ji 1 93 5 4 2 41 92 7574 2 9 4 2 17 33 5 4 2 4 2 Figure 1: First,  i  and  j  stop at items 9 and 1, which are thenswapped. Second,  i  and  j  cross and the pivot, 7, is swapped withitem 2. Special cases (i) and (iii) are ok but case (ii) requires astopper at  A [ r  + 1] . This stopper must be an item at leastas large as  x . If   r < n  −  1  this stopper is automaticallygiven. For  r  =  n − 1 , we create such a stopper by setting A [ n ] = + ∞ . Running time.  The actions taken by quicksort can beexpressed using a binary tree: each (internal) node repre-sents a call and displays the length of the subarray; seeFigure 2. The worst case occurs when  A  is already sorted. 121 125791 Figure 2: The total amount of time is proportional to the sumof lengths, which are the numbers of nodes in the correspondingsubtrees. In the displayed case this sum is 29. In this case the tree degenerates to a list without branch-ing. The sum of lengths can be described by the followingrecurrence relation: T  ( n ) =  n  + T  ( n − 1) = n  i =1 i  =  n + 12  . The running time in the worst case is therefore in O ( n 2 ) .In the best case the tree is completely balanced and thesum of lengths is described by the recurrence relation T  ( n ) =  n + 2 · T   n − 12  . 5
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!