20
Computational Geometry An Introduction Through Randomized Algorithms Ketan Mulmuley

Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

ComputationalGeometry

An Introduction ThroughRandomized Algorithms

Ketan Mulmuley

Page 2: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

Computational GeometryAn Introduction Through Randomized

Algorithms

Ketan MulmuleyThe University of Chicago

PRENTICE HALL, Englewood Cliffs, NJ 07632

Page 3: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

Library of Congress Cataloging-in-Publication Data

Mulmuley, Ketan.Computational geometry: an introduction through randomized

algorithms / Ketan Mulmuley.p. cm.

Includes bibliographical references and index.ISBN 0-13-336363-51. Geometry--Data processing. 2. Algorithms. I. Title.

QA448.M85 1994516'.13--dc2O 93-3138

CIP

Acquisitions editor: BILL ZOBRISTProduction editor: JOE SCORDATOCopy editor: PETER J. ZURITA

Prepress buyer: LINDA BEHRENSManufacturing buyer: DAVID DICKEYEditorial assistant: DANIELLE ROBINSON

C) 1994 by Prentice-Hall, Inc.A Simon & Schuster CompanyEnglewood Cliffs, New Jersey 07632

All rights reserved. No part of this book may bereproduced, in any form or by any means,without permission in writing from the publisher.

The author and publisher of this book have used their best efforts in preparing this book. Theseefforts include the development, research, and testing of the theories and programs to determinetheir effectiveness. The author and publisher make no warranty of any kind, expressed or implied,with regard to these programs or the documentation contained in this book. The author andpublisher shall not be liable in any event for incidental or consequential damagesin connection with, or arising out of, the furnishing, performance, or use of these programs.

Printed in the United States of America

10 9 8 7 6 5 4 3 2 1

ISBN 0-13-336363-5

Prentice-Hall Intemational (UK) Limited, LondonPrentice-Hall of Australia Pty. Limited, SydneyPrentice-Hall Canada Inc., TorontoPrentice-Hall Hispanoamericana, S.A., MexicoPrentice-Hall of India Private Limited, New DelhiPrentice-Hall of Japan, Inc., TokyoSimon & Schuster Asia Pte. Ltd., SingaporeEditora Prentice-Hall do Brasil, Ltda., Rio de Janeiro

Page 4: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

For Sanchit

Page 5: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

Contents

Preface ix

Notation xvi

I Basics 1

1 Quick-sort and search 31.1 Quick-sort ......... ............................. 41.2 Another view of quick-sort . . . . . . . . . . . . . . . . . . . . 51.3 Randomized binary trees .... ................................. 7

1.3.1 Dynamization ................................... 111.3.2 Another interpretation of rotations ..................... 13

1.4 Skip lists ............................................. 18

2 What is computational geometry? 262.1 Range queries ..... ......................................... 282.2 Arrangements ........................................ 292.3 Trapezoidal decompositions .... ............................. 322.4 Convex polytopes ...... ..................................... 36

2.4.1 Duality ........................................ 402.5 Voronoi diagrams ...................................... 462.6 Hidden surface removal . . . . . . . . . . . . . . . . . . . . ............. 512.7 Numerical precision and degeneracies ...................... 522.8 Early deterministic algorithms ... ........................... 55

2.8.1 Planar convex hulls ......................... 562.8.2 Arrangements of lines . . . . . . . . . . . . . . . . . . 582.8.3 Trapezoidal decompositions . . . . . . . . . . . . . . . 612.8.4 Planar Voronoi diagrams ..................... 672.8.5 Planar point location ........................ 74

2.9 Deterministic vs. randomized algorithms ................... 78

v

Page 6: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

2.10 The model of randomness ..... ............................... 78

3 Incremental algorithms 813.1 Trapezoidal decompositions .............................. 84

3.1.1 History . . . . . . . . . . . . . . . . . . . . . . . . . ............... 903.1.2 Planar graphs .... ................................... 943.1.3 Simple polygons* ................................ 94

3.2 Convex polytopes ...................................... 963.2.1 Conflict maintenance ..... ............................. 993.2.2 History ...... ....................................... 1033.2.3 On-line linear programming .... ....................... 104

3.3 Voronoi diagrams . . . . . . . . . . . . . . . . . . . . . . . . . 1063.4 Configuration spaces . . . . . . . . . . . . . . . . . . . . . . . 1113.5 Tail estimates* .. ....................................... 120

4 Dynamic algorithms 1264.1 Trapezoidal decompositions ... ............................. 129

4.1.1 Point location .................................. 1324.2 Voronoi diagrams ... ..................................... 135

4.2.1 Conflict search ..... ................................. 1374.3 History and configuration spaces ... ......................... 140

4.3.1 Expected performance* .......................... 1424.4 Rebuilding history .................................... 1494.5 Deletions in history .... ................................... 151

4.5.1 3D convex polytopes ............................ 1584.5.2 Trapezoidal decompositions . . . . . . . . . . . . . . . 162

4.6 Dynamic shuffling .................................... 167

5 Random sampling 1735.1 Configuration spaces with bounded valence ................ 1765.2 Top-down sampling . . . . . . . . . . . . . . . . . . . . . . . 181

5.2.1 Arrangements of lines ............................ 1825.3 Bottom-up sampling .................................. 184

5.3.1 Point location in arrangements .................... 1855.4 Dynamic sampling .................................... 192

5.4.1 Point location in arrangements .................... 1935.5 Average conflict size .... ................................... 1975.6 More dynamic algorithms . . . . . . . . . . . . . . . . . . . . 201

5.6.1 Point location in trapezoidal decompositions ......... 2045.6.2 Point location in Voronoi diagrams .. ................. 210

5.7 Range spaces and E-nets ..... ............................... 2155.7.1 VC dimension of a range space ................. 221

vi CONTENTS

Page 7: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

CONTENTS vii

5.8 Comparisons .......................................... 223

II Applications 227

6 Arrangements of hyperplanes 2296.1 Incremental construction ..... ............................... 2326.2 Zone Theorem ....................................... 2346.3 Canonical triangulations ........................... 238

6.3.1 Cutting Lemma ............................ 2416.4 Point location and ray shooting ...................... 242

6.4.1 Static setting ............................... 2426.4.2 Dynamization... ........................... 248

6.5 Point location and range queries .. ......................... 2506.5.1 Dynamic maintenance .. ........................... 253

7 Convex polytopes 2607.1 Linear programming .................................. 2627.2 The number of faces .................................. 267

7.2.1 Dehn Sommerville relations ... ....................... 2687.2.2 Upper bound theorem: Asymptotic form ............ 2717.2.3 Upper bound theorem: Exact form .. ................. 2717.2.4 Cyclic polytopes ................................ 274

7.3 Incremental construction ..... ............................... 2767.3.1 Conflicts and linear programming .................. 2787.3.2 Conflicts and history ............................ 279

7.4 The expected structural and conflict change ................ 2807.5 Dynamic maintenance .... ................................. 2847.6 Voronoi diagrams .. ..................................... 2857.7 Search problems ...................................... 286

7.7.1 Vertical ray shooting . . . . . . . . . . . . . . . . . . . 2887.7.2 Half-space range queries .......................... 2897.7.3 Nearest k-neighbor queries ........................ 2917.7.4 Dynamization .................................. 292

7.8 Levels and Voronoi diagrams of order k .. ................... 2947.8.1 Incremental construction .. ......................... 3017.8.2 Single level .................................... 306

8 Range search 3118.1 Orthogonal intersection search . . . . . . . . . . . . . . . . . 311

8.1.1 Randomized segment tree ........................ 3128.1.2 Arbitrary dimension ......................... 317

Page 8: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

8.2 Nonintersecting segments in the plane .................8.3 Dynamic point location ...... .....................8.4 Simplex range search .............................

8.4.1 Partition theorem. ....................8.4.2 Preprocessing time.....................

8.5 Half-space range queries ...........................8.5.1 Partition theorem. ....................8.5.2 Half-space emptiness ........................

8.6 Decomposable search problems ......................8.6.1 Dynamic range queries .......................

8.7 Parametric search .. . .......................

9 Computer graphics9.1 Hidden surface removal ...... .....................

9.1.1 Analysis. . .........................9.2 Binary Space Partitions ...........................

9.2.1 Dimension two. ......................9.2.2 Dimension three. .....................

9.3 Moving viewpoint .. . .......................9.3.1 Construction of a cylindrical partition..........9.3.2 Randomized incremental construction..........

10 How crucial is randomness?10.1 Pseudo-random sources ...... .....................10.2 Derandomization ...............................

10.2.1 E-approximations......................10.2.2 The method of conditional probabilities.........10.2.3 Divide and conquer .........................

A Tail estimatesA.1 Chernoff's technique ........................

A.1.1 Binomial distribution...................A.1.2 Geometric distribution ...................A.1.3 Harmonic distribution...................

A.2 Chebychev's technique ............................

Bibliography

Index

322327328332336338341343345348349

358361367372372379383391392

398399410412413417

422423424426428429

431

442

viii CONTENTS

Page 9: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

Preface

This book is based on lectures given to graduate students at the Universityof Chicago. It is intended to provide a rapid and concise introduction tocomputational geometry. No prior familiarity with computational geometryis assumed. A modest undergraduate background in computer science or arelated field should suffice.

My goal is to describe some basic problems in computational geometryand the simplest known algorithms for them. It so happens that several ofthese algorithms are randomized. That is why we have chosen randomizedmethods to provide an introduction to computational geometry. There isanother feature of randomized methods that makes them ideal for this task:They are all based on a few basic principles, which can be applied systemat-ically to a large number of apparently dissimilar problems. Thus, it becomespossible to provide through randomized algorithms a unified, broad perspec-tive of computational geometry. I have tried to give an account that bringsout this simplicity and unity of randomized algorithms and also their depth.

Randomization entered computational geometry with full force only inthe 80s. Before that the algorithms in computational geometry were mostlydeterministic. We do cover some of the very basic, early deterministic al-gorithms. Their study will provide the reader an historical perspective andfamiliarity with some deterministic paradigms that every student of computa-tional geometry must know. It will also provide the reader an opportunity tostudy the relationship between these deterministic algorithms and their ran-domized counterparts. This relationship is quite akin to the relationship be-tween quick-sort and deterministic sorting algorithms: Randomization yieldssimplicity and efficiency at the cost of losing determinism.

But randomization does more than just provide simpler alternatives to thedeterministic algorithms. Its role in the later phase of computational geome-try was pivotal. For several problems, there are no deterministic algorithmsthat match the performance of randomized algorithms. For several others,the only known deterministic algorithms are based on a technique called de-randomization. Later in the book, we study the basic principles underlying

ix

Page 10: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

this technique. It consists of an ingenious simulation of a randomized al-gorithm in a deterministic fashion. It has made the study of randomizedalgorithms even more important.

Of course, there are also numerous problems in computational geometryfor which randomization offers no help. We have not touched upon theseproblems in this book. Our goal is to provide a cohesive and unified accountrather than a comprehensive one. Even the field of randomized algorithmshas become so vast that it is impossible to cover it comprehensively within abook of this size. Finally, the choice of topics is subjective. But I hope thatthe book will provide the reader with a glimpse of the exciting developmentsin computational geometry. Once the vistas of this terrain are roughly illu-minated, it is hoped that the reader will be provided with the perspectivenecessary to delve more deeply into the subfields of his or her choice.

Organization of the book

Figure 0.1 shows logical dependence among the various chapters.The book is organized in two parts-basics and applications. In the first

part, we describe the basic principles that underlie the randomized algorithmsin this book. These principles are illustrated with the help of simple two-dimensional geometric problems. The first part uses only elementary planargeometry. It can also be easily read by those who are mainly interested inrandomized algorithms rather than in computational geometry.

In the applications part of the book, we apply the basic principles de-veloped in the first part to several higher-dimensional problems. Here thegeometry becomes more interesting. The chapters in this part are indepen-dent of each other. Thus, one can freely select and read the chapters ofinterest.

If the reader wishes, Chapter 2 can be read after reading just the in-troduction of Chapter 1. But the rest of Chapter 1 should be read beforeproceeding further. Chapters 1, 2, 3, and 5 should be read before proceedingto the applications part. Chapter 4 is optional, and can be skipped in thefirst reading after reading its introduction. This requires skipping Section 7.5and some exercises that depend on it. The other dynamic algorithms in thebook are based on the principles described in Chapter 5.

It should be noted that all randomized algorithms in this book are simple,without any exception. But sometimes their analysis is not so simple. If youare not theoretically inclined, you may skip the probabilistic analysis-whichis always separate-on the first reading. But, eventually, we hope, you willwish to know why these algorithms work so well and hence turn to theiranalysis.

PREFACEx

Page 11: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

Prerequisites

This book is meant to be understandable to those with only a modest un-dergraduate background in computer science or a related field. It is assumedthat the reader is familiar with elementary data structures such as lists, trees,graphs, and arrays. Familiarity with at least one nontrivial data structure,such as a balanced search tree, will help. But strictly speaking even that isnot required, because Chapter 1 gives a complete description of randomizedsearch trees. The algorithms in this book are described in plain English. Itis assumed that the reader can convert them into a suitable programminglanguage, if necessary.

Figure 0.1: Logical dependence among the chapters.

PREFACE xi

Page 12: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

It is also assumed that the reader is familiar with elementary notions ofprobability theory-random variables, their expectation, conditional expec-tation, and so on. We do not need anything deep from probability theory.The deeper aspects of randomized, geometric algorithms are generally geo-metric rather than probabilistic.

The first part of the book requires only planar geometry. The secondpart assumes nodding acquaintance with elementary notions in Euclideangeometry: closed set, open set, boundary of a set, linear function, and so on.Otherwise, it is meant to be self-contained.

To the teacher

The book can be used for a course on computational geometry to begin-ning graduate students. Such a course may begin with some basic problemsand their deterministic solutions (Chapter 2) and then shift to randomizedalgorithms as the problems get more complex.

On the deterministic side, the book contains only some very basic algo-rithms, which can be used for the first course in computational geometry. Intwo dimensions, we cover roughly as much ground as in, say, the book byPreparata and Shamos [185], but in higher dimensions, we go little further toaddress some additional deterministic techniques: incremental construction(Section 6.1), parametric search (Section 8.7), dynamization of decomposablesearch problems (Section 8.6), and derandomization (Section 10.2). Also, thealgorithms for orthogonal intersection search and dynamic planar point lo-cation in Chapter 8 are almost deterministic. The only difference is that Ihave substituted the weight-balanced trees in their solutions with skip lists.So, if you wish, you can cover the deterministic versions, too, after coveringthe simpler randomized versions.

On the side of randomized algorithms, the book contains more than whatcan be reasonably covered in one semester course. The choice of materialwould depend on the inclination of the students. In a leisurely course tostudents who are not theoretically inclined, you may wish to cover only thebasic algorithms in the beginnings of Chapters 3 and 5. This assumes verylittle mathematical sophistication. In an intensive course to theoreticallyinclined graduate students, you can cover most of Part I, but perhaps skipChapter 4, and cover selected topics in Part II. Since the chapters in Part IIare independent, the choice is flexible.

The book can also be used as a supplement for a course on randomizedalgorithms.

Xll PREFACE

Page 13: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

PREFACE xiii

Outline

Here is a brief outline of the book, chapter by chapter.

In Chapter 1, we begin with the simplest and the most well-known ran-domized algorithm: quick-sort. It is of special interest to us, because therandomized methods in computational geometry can be viewed as higher-dimensional generalizations of quick-sort. Quick-sort is known to be oneof the simplest and the most efficient general-purpose algorithms for sort-ing. This indicates why its higher-dimensional analogs can be expected tobe simple and efficient in practice. It is our hope that this book can help apractitioner get acquainted with some theoretical principles that may turnout to be useful in practice. With that in mind, we have chosen quick-sort asa starting point. Here, we analyze and interpret quick-sort in several ways,some of which are standard and some are not. These various interpretationsare systematically extended later in the book to attack a large number ofproblems.

Chapter 2 gives a snapshot of computational geometry. It describes sev-eral of the basic motivating problems in the field. These problems are tackledin a unified fashion later in the book. We also cover here some early deter-ministic algorithms for very basic two-dimensional problems. This shouldprovide the reader familiarity with some simple deterministic design princi-ples and an opportunity to compare these deterministic algorithms with theirrandomized counterparts studied later.

Chapter 3 deals with randomized incremental algorithms in computa-tional geometry. They solve a problem by adding the objects in the input,one at a time, in random order. This is exactly how quick-sort proceeds, ifit is viewed appropriately. We describe this paradigm in general form andthen illustrate it with several simple problems dealing with planar graphs,Voronoi diagrams, and so on.

Chapter 4 deals with dynamic problems. In a dynamic setting, the useris allowed to add or delete an object in the input in an on-line fashion. Wedevelop some general principles and demonstrate these on the same two-dimensional problems considered in Chapter 3.

Chapter 5 is central to the book. It describes the principle of randomsampling. This can be thought of as an extension of the randomized divide-and-conquer view of quick-sort. We describe the general principles and thenillustrate them on the two-dimensional problems considered in the earlierchapters.

Chapter 6 deals with arrangements of hyperplanes. Arrangements areimportant in computational geometry because, among all geometric configu-rations, they have perhaps the simplest combinatorial structure. Thus, they

Page 14: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

serve as a nice test-bed for the algorithmic principles developed earlier in thebook.

Chapter 7 deals with convex polytopes, convex hulls, Voronoi diagrams,and related problems. Convex polytopes and Voronoi diagrams come upin many fields-signal processing, operations research, physics, and so on.There is no need to dwell on their importance here.

Chapter 8 deals with range searching problems. Range searching is animportant theme that encompasses a large number of problems in compu-tational geometry. These problems have the following form: We are givena set of geometric objects. The goal is to build a data structure so that,given a query region, one can quickly report or count the input objects thatit intersects. Chapter 8 deals with several important problems of this form.

Chapter 9 deals with the applications of randomized methods to somebasic problems in computer graphics.

Finally, Chapter 10 studies how crucial the randomness is for the perfor-mance of the algorithms studied earlier in the book. We shall see that thenumber of random bits used by most randomized incremental algorithms canbe made logarithmic in the input size without changing their expected per-formance by more than a constant factor. Several of the algorithms based onrandom sampling can be made completely deterministic by "derandomizing"them. A comprehensive account of such deterministic algorithms is outsidethe scope of this book. However, we describe the basic principles underlyingthis technique.

There are several exercises throughout the book. The reader is encouragedto solve as many as possible. Some simple exercises are used in the book.These are mostly routine. Quite often, we defer the best known solution to agiven problem to the exercises, if this solution is too technical. The exercisesmarked with * are difficult-the difficulty increases with the number of stars.The exercises marked with t are unsolved at the time of this writing. Somesections in the book are starred. They can be skipped on the first reading.

The bibliography at the end is far from being comprehensive. We havemainly confined ourselves to the references that bear directly on the methodscovered in this book. For the related topics not covered in this book, we haveonly tried to provide a few references that can be used as a starting point;in addition, we also suggest for this purpose [63, 174, 180, 199, 231].

As for the exercises in the book, some of them are new and some are justroutine or standard. For the remaining exercises, I have provided explicitreferences unless they directly continue or extend the material covered inthe sections containing them (this should be apparent), in which case, thereference for the containing section is meant to be applicable for the exercise,too, unless mentioned otherwise.

XIV PREFACE

Page 15: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

Acknowledgments

I am very grateful to the Computer Science Department in the University ofChicago for providing a stimulating atmosphere for the work on this book. Iwish to thank the numerous researchers and graduate students who sharedtheir insights with me. I am especially grateful to the graduate studentswho took the courses based on this book and provided numerous criticisms,in particular, Stephen Crocker, L. Satyanarayana, Sundar Vishwanathan,and Victoria Zanko. Sundar provided a great help in the preparation ofthe appendix. I also wish to thank Bernard Chazelle, Alan Frieze, JirkaMatousek, Joe Mitchell and Rajeev Motwani for their helpful criticisms. Thework on this book was supported by a Packard Fellowship. I wish to thank thePackard Foundation for its generous support. It is a pleasure to thank AdamHarris who did the artwork, including the art on the cover, and provided everykind of support during the typesetting of this book. I wish to thank SamRebelsky for customizing LaTeX, Bill Zobrist and Joe Scordato of PrenticeHall for their enthusiasm and cooperation. Finally, I wish to thank my wifeManju for her endurance while the book was being written. I should alsoacknowledge the contribution of my son Sanchit; he insisted on having hisfavorite animals on the cover.

Ketan Mulmuley

PREFACE XV

Page 16: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

Notation

f(n) = O(g(n)) f(n) < cg(n), for some constant c > 0.f(n) = Q(g(n)) f(n) > cg(n), for some constant c > 0.

f(n) t g(n) Asymptotic equality, i.e., f(n) = O(g(n)) and g(n) =O(f(n)).

f(n) = O(g(n)) f(n) = O(g(n)) with high probability. This means, forsome constant c > 0, f(n) < cg(n) with probability1 - 1/p(n), where p(n) is a polynomial whose degree de-pends on c, and this degree can be made arbitrarily highby choosing c large enough. Thus, f(n) > cg(n) withprobability 1/p(n), which is minuscule.

X C Y X is a subset of Y.

X \ Y The relative complement of Y in X.

R The real line. (On a few occasions, R has a differentmeaning, but this will be clear from the context.)

Rd The d-fold product of R, i.e., the d-dimensional Euclideanspace.

XI The size of X. If X is an ordinary set, then this is justits cardinality. If X is a geometric partition (complex),this is the total number of its faces of all dimensions (cf.Chapter 2). Finally, if X is a real number, IX] is itsabsolute value.

[X] The smallest integer greater than x (the ceiling function).

Lxj The largest integer smaller than xr (the floor function).

E[X] Expected value of the random variable X.

E[X I ] Expected value of X subject to the specified conditions.

prob{..} Probability of the specified event.

az Boundary of the set Z.

min.... } The minimum element in the set.

max{ .. }. The maximum element in the set.

[XWd The falling factorial xr(x -1)... (x - d + 1).

polylog(n) log' n, for a fixed constant a > 0.

We often refer to a number which is bounded by a constant as simply abounded number. By a random sample of a set, we mean its random subsetof the specified size.

Page 17: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

Part I

Basics

Page 18: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

Chapter 1

Quick-sort and search

In this book, we view computational geometry as a study of sorting andsearching problems in higher dimensions. In a sense, these problems arejust generalizations of the ubiquitous problem in computer science-how tosearch and sort lists of elements drawn from an ordered universe. This latterproblem can be seen as the simplest one-dimensional form of sorting andsearching. This becomes clear if we reformulate it in a geometric languageas follows. We are given a set N of n points on the real line R. The goal isto sort them by their coordinates. This is equivalent to (Figure 1.1):

The sorting problem: Find the partition H(N) of R formed by the givenset of points N.

The partition H(N) is formally specified by the points in N, the resulting(open) intervals within the line R-such as J in Figure 1.1-and adjacenciesamong the points and the intervals. A geometric formulation of the associatedsearch problem is the following:

The search problem: Associate a search structure ft(N) with H(N) sothat, given any point q C R, one can locate the interval in H(N) containingq quickly, i.e., in logarithmic time.

In a dynamic variant of the search problem, the set N can be changedin an on-line fashion by addition or deletion of a point. We are required toupdate H(N) quickly, i.e., in logarithmic time, during each such update.

JA gp

Figure 1.1: H(N).

3

Page 19: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

CHAPTER 1. QUICK-SORT AND SEARCH

In higher dimensions, the elements of the set N are not points any more,but, rather, hyperplanes or sites or polygons and so on, depending on theproblem under consideration.

The simplest methods for sorting and searching linear lists are random-ized. It is no surprise that the simplest known methods for several higher-dimensional sorting and searching problems are also randomized. Thesemethods can be thought of as generalizations of the randomized methodsfor sorting and searching linear lists. Hence, we begin with a review of theselatter methods. Actually, our goal is more than just a review-we wantto reformulate these methods in a geometric language and analyze them inways that can be generalized to higher dimensions. A great insight in higher-dimensional problems is obtained by just redoing the one-dimensional case.

Remark. In the above geometric formulation of sorting and searching in lists,we assumed that the points in N were points on the line. Strictly speaking,this is not necessary. The elements in N can be arbitrary, as long as theycan be linearly ordered and the comparison between any two elements in Ncan be carried out in constant time. All methods described in this chaptercan be translated to this more general setting trivially.

1.1 Quick-sort

A simple randomized method for sorting a list of points on the real line R isquick-sort. It is based on the randomized divide-and-conquer paradigm. LetN be the given set of n points in R. Pick a random point S C N. It dividesR into two halves. Let N1 , N2 C N be the subsets of points contained inthese two halves. Sort N1 and N2 recursively.

Intuitively, we should expect the sizes of N1 and N2 to be roughly equalto n/2. Hence, the expected depth of recursion is O(logn). This means theexpected running time of the algorithm should be O(n log n). We shall givea rigorous justification for this in a moment.

One issue remains to be addressed here. In the division step, how do wechoose a random point in N? In practice, this has to be done with the help ofa random number generator. But the numbers generated by these so-calledrandom number generators are not truly random. They only "appear" ran-dom. Fortunately, we shall see in Chapter 10 that all randomized algorithmsin this book work very well even when the source of randomness in not per-fectly random, but only "pseudo-random". Until then, we shall assume, forthe sake of simplicity, that all our algorithms have ability to make perfectlyrandom choices whenever necessary.

4

Page 20: Computational Geometry · 2018-09-18 · geometry. It can also be easily read by those who are mainly interested in randomized algorithms rather than in computational geometry. In

1.2. ANOTHER VIEW OF QUICK-SORT

1.2 Another view of quick-sort

If we unwind the recursion in the definition of quick-sort, we get its so-calledrandomized incremental version. Though this version is equivalent to theversion in the previous section, in higher dimensions, these two paradigmslead to markedly different algorithms.

.: points in N2 points in N\N2

Figure 1.2: H(N2 ).

S3

II(S3) 2(S3)

Figure 1.3: Addition of the third point.

The randomized incremental version of quick-sort works as follows. Itconstructs the required partition of the line incrementally by adding thepoints in N, one at a time, in random order. In other words, at any giventime we choose a random point from the set of unadded points and add thechosen point to the existing partition. Let us elaborate this idea fully. LetN2 be the set of the first i added points. Let H(N2 ) be the partition of Rformed by N2. Starting with H(N0 ), the empty partition of R, we constructa sequence of partitions

H (NO), H(N ), H(N 2),...H(N n)= H(N).

At the ith stage of the algorithm, we also maintain, for each interval I E

H(N?), its conflict list L(I). This is defined to be an unordered list of thepoints in N \ N' contained in I (Figure 1.2). Conversely, with each point inN\N', we maintain a pointer to the conflicting interval in H(N') containingit.

Addition of a randomly chosen point S = Si+1 in N \ N t consists insplitting the interval I in H(N2 ) containing S, together with its conflict list.

Let Ii(S) and I2(S) denote the intervals in H(NZ+l) adjacent to S (Fig-ure 1.3). Let l(Il(S)) and l(I2(S)) denote their conflict sizes, i.e., the sizesof their conflict lists L(11 (S)) and L(1 2 (S)). It is easily seen that:

Fact 1.2.1 The cost of adding S is proportional to l(Ii(S)) + 1(1 2 (S)), ig-noring an additive 0(1) term.

5