Graham Scan Algorithm

Graham's scan is a method of finding the convex hull of a finite set of points in the airplane with time complexity O(n log n).It is named after Ronald Graham, who published the original algorithm in 1972.

Graham Scan source code, pseudocode and analysis

If the consequence is 0, the points are collinear; if it is positive, the three points constitute a" left turn" or counter-clockwise orientation, otherwise a" right turn" or clockwise orientation (for counter-clockwise numbered points).The same determination is then made for the set of the latest point and the two points that immediately precede the point found to have been inside the hull, and is repeated until a" left turn" set is encountered, at which point the algorithm moves on to the next point in the set of points in the sorted array subtraction any points that were found to be inside the hull; there is no need to consider these points again.