You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: chapters/computational_geometry/gift_wrapping/graham_scan/graham_scan.md
+13-5Lines changed: 13 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# Graham Scan
2
2
3
3
At around the same time of the [Jarvis March](jarvis_march.md), R. L. Graham was also developing an algorithm to find the convex hull of a random set of points {{ "gs1972" | cite }}.
4
-
Unlike the Jarvis March, which is an $$\mathcal{O}(nh)$$ operation, the Graham Scan is $$\mathcal{O}(n\log(n))$$, where $$n$$ is the number of points and $$h$$ is the size fo the hull.
4
+
Unlike the Jarvis March, which is an $$\mathcal{O}(nh)$$ operation, the Graham Scan is $$\mathcal{O}(n\log(n))$$, where $$n$$ is the number of points and $$h$$ is the size fo the hull.
5
5
This means that the complexity of the Graham Scan is not output-sensitive; moreover, there are some cases where the Jarvis March is more optimal, depending on the size of the hull and the number of points to wrap.
6
6
7
-
Rather than starting at the leftmost point like the Jarvis March, the Graham scan starts at the bottom.
7
+
Rather than starting at the leftmost point like the Jarvis March, the Graham scan starts at the bottom.
8
8
We then sort the distribution of points based on the angle between the bottom-most point, the origin, and each other point.
9
9
After sorting, we go through point-by-point, searching for points that are on the convex hull and throwing out any other points.
10
10
We do this by looking for counter-clockwise rotations.
@@ -14,6 +14,8 @@ We can find whether a rotation is counter-clockwise with trigonometric functions
@@ -26,12 +28,14 @@ We basically do not want clockwise rotations, because this means we are at an in
26
28
<!---ADD FIGURE--->
27
29
28
30
To save memory and expensive `append()` operations, we ultimately look for points that should be on the hull and swap them with the first elements in the array.
29
-
If there are $$M$$ elements on the hull, then the first $$M$$ elements in our output random distribution of points will be the hull.
31
+
If there are $$M$$ elements on the hull, then the first $$M$$ elements in our output random distribution of points will be the hull.
30
32
In the end, the code should look something like this:
0 commit comments