Plane Sweep Algorithm - Design and Analysis - Study Notes, Study notes of Digital Systems Design

Plane sweep Algorithm, Sweep line, Final maximal set, Analysis of Plane sweep Algorithm, Comparison of Brute force and Plane sweep algorithms, Discrete steps are the key points in this study notes file.

Typology: Study notes

2011/2012

Uploaded on 11/03/2012

ankitay
ankitay 🇮🇳

4.4

(50)

106 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture No.5
1.11.2 Plane-sweep Algorithm
The question is whether we can make an significant improvement in the running time?
Here is an idea for how we might do it. We will sweep a vertical line across the plane
from left to right. As we sweep this line, we will build a structure holding the maximal
points lying to the left of the sweep line. When the sweep line reaches the rightmost point
of P, then we will have constructed the complete set of maxima. This approach of solving
geometric problems by sweeping a line across the plane is called plane sweep.
Although we would like to think of this as a continuous process, we need some way to
perform the plane sweep in discrete steps. To do this, we will begin by sorting the points
in increasing order of their x-coordinates. For simplicity, let us assume that no two points
have the same y-coordinate. (This limiting assumption is actually easy to overcome, but it
is good to work with the simpler version, and save the messy details for the actual
implementation.) Then we will advance the sweep-line from point to point in n discrete
steps. As we encounter each new point, we will update the current list of maximal points.
We will sweep a vertical line across the 2-d plane from left to right. As we sweep, we
will build a structure holding the maximal points lying to the left of the sweep line. When
the sweep line reaches the rightmost point of P, we will have the complete set of
maximal points. We will store the existing maximal points in a list The points that pi
dominates will appear at the end of the list because points are sorted by x-coordinate. We
will scan the list left to right. Every maximal point with y-coordinate less than pi will be
eliminated from computation. We will add maximal points onto the end of a list and
delete from the end of the list. We can thus use a stack to store the maximal points. The
point at the top of the stack will have the highest x-coordinate.
Here are a series of figures that illustrate the plane sweep. The figure also show the
content of the stack.
2 4 6 8 10 14 16 18 12
2
4
6
8
10
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Plane Sweep Algorithm - Design and Analysis - Study Notes and more Study notes Digital Systems Design in PDF only on Docsity!

Lecture No.

1.11.2 Plane-sweep Algorithm

The question is whether we can make an significant improvement in the running time? Here is an idea for how we might do it. We will sweep a vertical line across the plane from left to right. As we sweep this line, we will build a structure holding the maximal points lying to the left of the sweep line. When the sweep line reaches the rightmost point of P, then we will have constructed the complete set of maxima. This approach of solving geometric problems by sweeping a line across the plane is called plane sweep.

Although we would like to think of this as a continuous process, we need some way to perform the plane sweep in discrete steps. To do this, we will begin by sorting the points in increasing order of their x-coordinates. For simplicity, let us assume that no two points have the same y-coordinate. (This limiting assumption is actually easy to overcome, but it is good to work with the simpler version, and save the messy details for the actual implementation.) Then we will advance the sweep-line from point to point in n discrete steps. As we encounter each new point, we will update the current list of maximal points. We will sweep a vertical line across the 2-d plane from left to right. As we sweep, we will build a structure holding the maximal points lying to the left of the sweep line. When the sweep line reaches the rightmost point of P, we will have the complete set of maximal points. We will store the existing maximal points in a list The points that pi dominates will appear at the end of the list because points are sorted by x-coordinate. We will scan the list left to right. Every maximal point with y-coordinate less than pi will be eliminated from computation. We will add maximal points onto the end of a list and delete from the end of the list. We can thus use a stack to store the maximal points. The point at the top of the stack will have the highest x-coordinate.

Here are a series of figures that illustrate the plane sweep. The figure also show the content of the stack. 2 4 6 8 10 14 16 18 12 2 4 6 8 10

Figure 1.6: Sweep line at (2, 5) Figure 1.7: Sweep line at^ (3, 13)

Figure 1.8: Sweep line at (4, 11) Figure 1.9: Sweep line at (5, 1)

Figure 1.10: Sweep line at (7, 7) Figure 1.11: Sweep line at^ (9, 10)

Here is the algorithm.

1.11.3 Analysis of Plane-sweep Algorithm

Sorting takes Θ(n log n); we will show this later when we discuss sorting. The for loop executes n times. The inner loop (seemingly) could be iterated (n - 1) times. It seems we

still have an n(n - 1) or Θ (n 2 ) algorithm. Got fooled by simple minded loop-counting. The while loop will not execute more n times over the entire course of the algorithm. Why is this? Observe that the total number of elements that can be pushed on the stack is n since we execute exactly one push each time during the outer for-loop.

We pop an element off the stack each time we go through the inner while-loop. It is impossible to pop more elements than are ever pushed on the stack. Therefore, the inner while-loop cannot execute more than n times over the entire course of the algorithm. ( Make sure that you understand this ).

The for-loop iterates n times and the inner while-loop also iterates n time for a total of Θ(n). Combined with the sorting, the runtime of entire plane-sweep algorithm is Θ(n log n).

1.11.4 Comparison of Brute-force and Plane sweep algorithms

How much of an improvement is plane-sweep over brute-force? Consider the ratio of running times:

For n = 1, 000, 000, if plane-sweep takes 1 second, the brute-force will take about 14 hours!. From this we get an idea about the importance of asymptotic analysis. It tells us which algorithm is better for large values of n. As we mentioned before, if n is not very large, then almost any algorithm will be fast. But efficient algorithm design is most important for large inputs, and the general rule of computing is that input sizes continue to grow until people can no longer tolerate the running times. Thus, by designing algorithms efficiently, you make it possible for the user to run large inputs in a reasonable amount of time.