The.Algorithm.Design.Manual.Springer-Verlag.1998
The.Algorithm.Design.Manual.Springer-Verlag.1998 The.Algorithm.Design.Manual.Springer-Verlag.1998
Randomization for i = low+1 to high swap(A[low],A[leftwall]) if (A[i] < pivot) then leftwall = leftwall+1 swap(A[i],A[leftwall]) Mergesort ran in time because we split the keys into two equal halves, sorted them recursively, and then merged the halves in linear time. Thus whenever our pivot element is near the center of the sorted array (i.e. the pivot is close to the median element), we get a good split and realize the same performance as mergesort. Such good pivot elements will often be the case. After all, half the elements lie closer to the middle than one of the ends. On average, Quicksort runs in time. If we are extremely unlucky and our randomly selected elements always are among the largest or smallest element in the array, Quicksort turn into selection sort and runs in . However, the odds against this are vanishingly small. Randomization is a powerful, general tool to improve algorithms with bad worst-case but good averagecase complexity. The worst case examples still exist, but they depend only upon how unlucky we are, not on the order that the input data is presented to us. For randomly chosen pivots, we can say that ``Randomized quicksort runs in time on any input, with high probability.'' If instead, we used some deterministic rule for selecting pivots (like always selecting A[(low+high)/2] as pivot), we can make no claim stronger than ``Quicksort runs in time if you give me random input data, with high probability.'' Randomization can also be used to drive search techniques such as simulated annealing, which are discussed in Section . file:///E|/BOOK/BOOK/NODE35.HTM (2 of 3) [19/1/2003 1:28:31]
Randomization Next: Bucketing Techniques Up: Approaches to Sorting Previous: Divide and Conquer Algorithms Mon Jun 2 23:33:50 EDT 1997 file:///E|/BOOK/BOOK/NODE35.HTM (3 of 3) [19/1/2003 1:28:31]
- Page 105 and 106: Correctness NearestNeighborTSP(P) P
- Page 107 and 108: Correctness Figure: A bad example f
- Page 109 and 110: Efficiency Next: Expressing Algorit
- Page 111 and 112: Keeping Score Next: The RAM Model o
- Page 113 and 114: The RAM Model of Computation substa
- Page 115 and 116: Best, Worst, and Average-Case Compl
- Page 117 and 118: The Big Oh Notation Figure: Illustr
- Page 119 and 120: Logarithms Next: Modeling the Probl
- Page 121 and 122: Logarithms justified in ignoring th
- Page 123 and 124: Modeling the Problem Figure: Modeli
- Page 125 and 126: About the War Stories Next: War Sto
- Page 127 and 128: War Story: Psychic Modeling Next: E
- Page 129 and 130: War Story: Psychic Modeling have pu
- Page 131 and 132: War Story: Psychic Modeling Next: E
- Page 133 and 134: Exercises (b) If I prove that an al
- Page 135 and 136: Fundamental Data Types Next: Contai
- Page 137 and 138: Containers Next: Dictionaries Up: F
- Page 139 and 140: Dictionaries Next: Binary Search Tr
- Page 141 and 142: Binary Search Trees BinaryTreeQuery
- Page 143 and 144: Priority Queues Next: Specialized D
- Page 145 and 146: Specialized Data Structures Next: S
- Page 147 and 148: Sorting Next: Applications of Sorti
- Page 149 and 150: Applications of Sorting Figure: Con
- Page 151 and 152: Data Structures Next: Incremental I
- Page 153 and 154: Incremental Insertion Next: Divide
- Page 155: Randomization Next: Bucketing Techn
- Page 159 and 160: Bucketing Techniques Algorithms Mon
- Page 161 and 162: War Story: Stripping Triangulations
- Page 163 and 164: War Story: Stripping Triangulations
- Page 165 and 166: War Story: Mystery of the Pyramids
- Page 167 and 168: War Story: Mystery of the Pyramids
- Page 169 and 170: War Story: String 'em Up We were co
- Page 171 and 172: War Story: String 'em Up Figure: Su
- Page 173 and 174: Exercises Next: Implementation Chal
- Page 175 and 176: Exercises used to select the pivot.
- Page 177 and 178: Dynamic Programming Next: Fibonacci
- Page 179 and 180: Fibonacci numbers Next: The Partiti
- Page 181 and 182: Fibonacci numbers Next: The Partiti
- Page 183 and 184: The Partition Problem . What is the
- Page 185 and 186: The Partition Problem Figure: Dynam
- Page 187 and 188: Approximate String Matching Next: L
- Page 189 and 190: Approximate String Matching The val
- Page 191 and 192: Longest Increasing Sequence Will th
- Page 193 and 194: Minimum Weight Triangulation Next:
- Page 195 and 196: Limitations of Dynamic Programming
- Page 197 and 198: War Story: Evolution of the Lobster
- Page 199 and 200: War Story: Evolution of the Lobster
- Page 201 and 202: War Story: What's Past is Prolog Ne
- Page 203 and 204: War Story: What's Past is Prolog th
- Page 205 and 206: War Story: Text Compression for Bar
Randomization<br />
for i = low+1 to high<br />
swap(A[low],A[leftwall])<br />
if (A[i] < pivot) then<br />
leftwall = leftwall+1<br />
swap(A[i],A[leftwall])<br />
Mergesort ran in time because we split the keys into two equal halves, sorted them recursively, and<br />
then merged the halves in linear time. Thus whenever our pivot element is near the center of the sorted<br />
array (i.e. the pivot is close to the median element), we get a good split and realize the same performance as<br />
mergesort. Such good pivot elements will often be the case. After all, half the elements lie closer to the<br />
middle than one of the ends. On average, Quicksort runs in time. If we are extremely unlucky and<br />
our randomly selected elements always are among the largest or smallest element in the array, Quicksort<br />
turn into selection sort and runs in . However, the odds against this are vanishingly small.<br />
Randomization is a powerful, general tool to improve algorithms with bad worst-case but good averagecase<br />
complexity. <strong>The</strong> worst case examples still exist, but they depend only upon how unlucky we are, not<br />
on the order that the input data is presented to us. For randomly chosen pivots, we can say that<br />
``Randomized quicksort runs in time on any input, with high probability.''<br />
If instead, we used some deterministic rule for selecting pivots (like always selecting A[(low+high)/2] as<br />
pivot), we can make no claim stronger than<br />
``Quicksort runs in time if you give me random input data, with high probability.''<br />
Randomization can also be used to drive search techniques such as simulated annealing, which are<br />
discussed in Section .<br />
file:///E|/BOOK/BOOK/NODE35.HTM (2 of 3) [19/1/2003 1:28:31]