ArticleslgStudy

computer science

Gift wrapping algorithm

Gift wrapping algorithm is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Gift wrapping algorithm rather than just read about it. In short: In computational geometry, the gift wrapping algorithm is an algorithm for computing the convex hull of a given set of points. Planar case In the two-dimensional case the algorithm is also known as Jarvis march, after R.

Gift wrapping algorithm — main illustration
Gift wrapping algorithm — illustration

Key takeaways

  • Gift wrapping algorithm belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Gift wrapping algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Gift wrapping algorithm from memory before moving on to harder problems.

Reference excerpt

In computational geometry, the gift wrapping algorithm is an algorithm for computing the convex hull of a given set of points.

Planar case In the two-dimensional case the algorithm is also known as Jarvis march, after R. A. Jarvis, who published it in 1973; it has O(nh) time complexity, where n is the number of points and h is the number of points on the convex hull. Its real-life performance compared with other convex hull algorithms is favorable when n is small or h is expected to be very small with respect to n. In general cases, the algorithm is outperformed by many others (see Convex hull algorithms).

Algorithm For the sake of simplicity, the description below assumes that the points are in general position, i.e., no three points are collinear. The algorithm may be easily modified to deal with collinearity, including the choice whether it should report only extreme points (vertices of the convex hull) or all points that lie on the convex hull. Also, the complete implementation must choose how to deal with degenerate cases when the convex hull has only 1 or 2 vertices, as well as with the issues of limited arithmetic precision, both of computer computations and input data. The gift wrapping algorithm begins with i=0 and a point p0 known to be on the convex hull, e.g., the leftmost point, and selects the point pi+1 such that all points are to the right of the line pi pi+1. This point may be found in O(n) time by comparing polar angles of all points with respect to point pi taken for the center of polar coordinates. Letting i=i+1, and repeating with until one reaches ph=p0 again yields the convex hull in h steps. In two dimensions, the gift wrapping algorithm is similar to the process of winding a string (or wrapping paper) around the set of points. The approach can be extended to higher dimensions.

Pseudocode

algorithm jarvis(S) is // S is the set of points // P will be the set of points which form the convex hull. Final set size is i. pointOnHull := leftmost point in S // which is guaranteed to be part of the CH(S) i := 0 repeat P[i] := pointOnHull endpoint := S[0] // initial endpoint for a candidate edge on the hull for j from 0 to |S| do // endpoint == pointOnHull is a rare case and can happen only when j == 1 and a better endpoint has not yet been set for the loop if (endpoint == pointOnHull) or (S[j] is on left of line from P[i] to endpoint) then endpoint := S[j] // found greater left turn, update endpoint i := i + 1 pointOnHull := endpoint until endpoint == P[0] // wrapped around to first hull point

Complexity The inner loop checks every point in the set S, and the outer loop repeats for each point on the hull. Hence the total run time is O(nh). The run time depends on the size of the output, so Jarvis's march is an output-sensitive algorithm. However, because the running time depends linearly on the number of hull vertices, it is only faster than O(nlog⁡n) algorithms such as Graham scan when the number h of hull vertices is smaller than log n. Chan's algorithm, another convex hull algorithm, combines the logarithmic dependence of Graham scan with the output sensitivity of the gift wrapping algorithm, achieving an asymptotic running time O(nlog⁡h) that improves on both Graham scan and gift wrapping.

See also Convex hull algorithms

References

Illustrations

Gift wrapping algorithm: Animation of the gift wrapping algorithm. With different colored lines where it shows different angles, the color changes each time when it finishes finding the optimal point.
Animation of the gift wrapping algorithm. With different colored lines where it shows different angles, the color changes each time when it finishes finding the optimal point.
Gift wrapping algorithm: Jarvis's march computing the convex hull.
Jarvis's march computing the convex hull.

Worked examples

Example 1 — a first encounter with Gift wrapping algorithm

Start with the simplest possible case. Write down what Gift wrapping algorithm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Gift wrapping algorithm before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Gift wrapping algorithm ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Gift wrapping algorithm

In research
Gift wrapping algorithm appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Gift wrapping algorithm in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Gift wrapping algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Convex hull algorithms, Polytopes, so understanding it makes those chapters shorter.
In everyday life
Look for Gift wrapping algorithm outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Gift wrapping algorithm” →

How to study Gift wrapping algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Gift wrapping algorithm means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Gift wrapping algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Gift wrapping algorithm in simple terms?

In computational geometry, the gift wrapping algorithm is an algorithm for computing the convex hull of a given set of points. Planar case In the two-dimensional case the algorithm is also known as Jarvis march, after R.

Why does Gift wrapping algorithm matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Gift wrapping algorithm?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Gift wrapping algorithm.

Tags

  • Convex hull algorithms
  • Polytopes

Keep exploring