Explaining Runtime of Shamos Algorithm

  • Thread starter AkilMAI
  • Start date
  • Tags
    Runtime
In summary, the Shamos algorithm finds the closest pair of points in an input set by recursively dividing the problem in half and then scanning through the points in a vertical strip. Its runtime is T(n) = {O(1), if n ≤ 3; {Tf(n/2) + Tc(n/2) + O(n), if n > 3.
  • #1
AkilMAI
77
0
Can someone please explain to me why the recursive part of this algorithm has the runtime
T(n) = {O(1), if n ≤ 3;
{Tf(n/2) + Tc(n/2) + O(n), if n > 3.

->where Tf(n/2) represents the floor function of T(n/2) and Tc(n/2) represents the the ceilling function

It is called Shamos algorithm and the main steps are:
1. If n ≤ 3 find the closest points by brute force and stop.
2. Find a vertical line V such that divides the input set into two disjoint subsets PL and PR of size
as equal as possible . Points to the left or on the line
belong PL and points to the right or on the line belong to PR. No point belongs to both since
the sets are disjoint.
3. Recursively find the distance δL of a closest pair of points in PL and the distance δR of a closest
pair in PR.
4. Let δ = min(δL, δR). The distance of a pair of closest points in the input set P is either that of
the points found in the recursive step (i.e., δ) or consists of the distance between a point in PL
and a point in PR.
(a) The only candidate points one from PL and one from PR must be in a vertical strip consisting
of a line at distance δ to the left of the line V and a line at distance δ to the right of V
(b) Let YV be an array of the points within the strip sorted by non-decreasing y coordinate
(i.e., if i ≤ j then YV ≤ YV [j]).
(c) Starting with the first point in YV and stepping trough all except the last, check the distance
of this point with the next 7 points (or any that are left if there are not as many as 7). If a
pair is found with distance strictly less than δ then assign this distance to δ.
5. Return δ.
Thanks.
 
Technology news on Phys.org
  • #2
The recursive part of this algorithm essentially reduces the problem size by half at each step. This is what allows it to have a runtime of T(n) = {O(1), if n ≤ 3; {Tf(n/2) + Tc(n/2) + O(n), if n > 3. At each step, the algorithm divides the problem in half and then recursively calls itself on the two halves (Tf(n/2) + Tc(n/2)). The O(n) part is because of Step 4b, where the algorithm must scan through the points in the vertical strip (YV). Since there are n total points, the runtime for scanning through them is O(n).
 

1. What is the Shamos Algorithm?

The Shamos Algorithm is a computational geometry algorithm that is used to find the intersection points between a set of line segments in a plane. It was invented by Dan Shamos in 1978 and has been widely used in various applications, such as computer graphics and geographic information systems.

2. How does the Shamos Algorithm work?

The Shamos Algorithm works by first sorting the line segments in a plane by their x-coordinate. Then, it uses a sweep line to scan through the segments in order and checks for any potential intersection points between them. The algorithm then updates the status of the sweep line as it encounters new segments, and continues until all segments have been checked.

3. What is the runtime of the Shamos Algorithm?

The runtime of the Shamos Algorithm is O(n log n), where n is the number of line segments in the input. This is because the initial sorting of the line segments takes O(n log n) time, and the sweep line algorithm has a time complexity of O(n).

4. What are the limitations of the Shamos Algorithm?

The Shamos Algorithm is limited to finding intersections between line segments in a plane. It cannot handle more complex geometric shapes, such as curves or polygons. Additionally, the algorithm may fail if there are duplicate or overlapping segments in the input.

5. Are there any alternative algorithms to the Shamos Algorithm?

Yes, there are other algorithms that can also find intersection points between line segments, such as the Bentley-Ottmann Algorithm and the Kirkpatrick-Seidel Algorithm. These algorithms may have different time complexities and may be more suitable for certain types of inputs, so it is important to consider the specific requirements of the problem when choosing an algorithm.

Similar threads

  • Programming and Computer Science
Replies
1
Views
953
  • Programming and Computer Science
Replies
6
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
2K
  • Programming and Computer Science
2
Replies
36
Views
3K
  • Programming and Computer Science
Replies
8
Views
2K
  • Special and General Relativity
2
Replies
40
Views
2K
Back
Top