Algorithms · Visualized

Geometry: Convex Hull (Jarvis March)

Computational Geometry

Points, polygons, and hulls — geometry made computational.

Jarvis March (gift wrapping) finds the convex hull by starting at the leftmost point and repeatedly choosing the next hull point as the one that keeps all other points to one side — like wrapping a string around the outside of the point set. Time: O(n·h) average, O(n²) — all points on the hull worst; space: O(h) — the hull and scan lines.

Big-O: Cross products and sweeping tell left/right and inside/outside.

Convex Hull (Jarvis March)

Computational Geometry

Jarvis March (gift wrapping) finds the convex hull by starting at the leftmost point and repeatedly choosing the next hull point as the one that keeps all other points to one side — like wrapping a string around the outside of the point set. Simple to visualize, though slower than Graham scan on large hulls.

How Convex Hull (Jarvis March) Works

  1. Find the leftmost point — guaranteed to be on the hull — and make it the start.
  2. From the current hull point, consider every other point as a candidate for the next hull vertex.
  3. A candidate q replaces the current best if it is more counter-clockwise (cross product sign), or collinear and farther.
  4. Add the winning candidate to the hull and make it the new current point.
  5. Repeat until the wrapping returns to the starting point.

Convex Hull (Jarvis March) Worked Example

Input: Points (0,0), (1,1), (2,2), (3,0), (0,3), (3,3)

Start at the leftmost point (0,0). From there the most counter-clockwise point is (3,0) — wrap to it. From (3,0), wrap to (3,3), then to (0,3), then back to (0,0), which closes the hull. Interior points (1,1) and (2,2) never get selected.

Python · Geometry Algorithms in Code
def jarvis(points):
    start = min(range(len(points)), key=lambda i: (points[i][0], points[i][1]))
    hull = []
    cur = start
    while True:
        hull.append(cur)
        best = None
        for i, p in enumerate(points):
            if i == cur:
                continue
            if best is None:
                best = i
                continue
            cross = ((points[cur][1] - points[cur][1]) * 0 +
                     (points[best][0] - points[cur][0]) * (p[1] - points[cur][1]) -
                     (points[best][1] - points[cur][1]) * (p[0] - points[cur][0]))
            if cross < 0:
                best = i
        cur = best
        if cur == start:
            break
    hull.append(start)
    return hull

Behind the Scenes Execution

Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.

Convex Hull (Jarvis March) Time & Space Complexity

BestO(n·h) — h hull points
AverageO(n·h)
WorstO(n²) — all points on the hull
SpaceO(h) — the hull and scan lines

When to Use Convex Hull (Jarvis March)

  • Collision-detection bounding shapes in games and physics engines.
  • GIS territory boundary computation.
  • Pattern recognition and shape-outline analysis.

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits

Keep the momentum going

Step through a related structure, pattern or course — the ideas reinforce each other and stick faster.