18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Applications of Sorting<br />

Figure: Constructing the convex hull of points in the plane<br />

● Convex hulls - Given n points in two dimensions, what is the polygon of smallest area that<br />

contains them all? <strong>The</strong> convex hull is like a rubber band stretched over the points in the plane and<br />

then released. It compresses to just cover the points, as shown in Figure . <strong>The</strong> convex hull<br />

gives a nice representation of the shape of the points and is the most important building block for<br />

more sophisticated geometric algorithms, as discussed in catalog Section .<br />

But how can we use sorting to construct the convex hull? Once you have the points sorted by xcoordinate,<br />

the points can be inserted from left to right into the hull. Since the rightmost point is<br />

always on the boundary, we know that it will be inserted into the hull. Adding this new rightmost<br />

point might cause others to be deleted, but we can quickly identify these points because they lie<br />

inside the polygon formed by adding the new point. <strong>The</strong>se points to delete will be neighbors of<br />

the previous point we inserted, so they will be easy to find. <strong>The</strong> total time is linear after the<br />

sorting has been done.<br />

While some of these problems (particularly median and selection) can be solved in linear time using<br />

more sophisticated algorithms, sorting provides quick and easy solutions to all of these problems. It is a<br />

rare application whose time complexity is such that sorting proves to be the bottleneck, especially a<br />

bottleneck that could have otherwise been removed using more clever algorithmics. Don't ever be afraid<br />

to spend time sorting whenever you use an efficient sorting routine.<br />

Next: Approaches to Sorting Up: Data Structures and Sorting Previous: Sorting<br />

<strong>Algorithm</strong>s<br />

Mon Jun 2 23:33:50 EDT 1997<br />

file:///E|/BOOK/BOOK/NODE30.HTM (2 of 2) [19/1/2003 1:28:28]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!