ArticleslgStudy

computer science

Chan's algorithm

Chan's 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 Chan's algorithm rather than just read about it. In short: In computational geometry, Chan's algorithm, named after Timothy M. Chan, is an optimal output-sensitive algorithm to compute the convex hull of a set P of n points, in 2- or 3-dimensional space.

Chan's algorithm — main illustration
Chan's algorithm — illustration

Key takeaways

  • Chan's 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 Chan's algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Chan's algorithm from memory before moving on to harder problems.

Reference excerpt

In computational geometry, Chan's algorithm, named after Timothy M. Chan, is an optimal output-sensitive algorithm to compute the convex hull of a set P of n points, in 2- or 3-dimensional space. The algorithm takes O(nlog⁡h) time, where h is the number of vertices of the output (the convex hull). In the planar case, the algorithm combines an O(nlog⁡n) algorithm (Graham scan, for example) with Jarvis march (O(nh)), in order to obtain an optimal O(nlog⁡h) time. Chan's algorithm is notable because it is much simpler than the Kirkpatrick–Seidel algorithm, and it naturally extends to 3-dimensional space. This paradigm has been independently developed by Frank Nielsen in his Ph.D. thesis.

Algorithm

Overview A single pass of the algorithm requires a parameter m which is between 0 and n (number of points of our set P). Ideally, m=h but h, the number of vertices in the output convex hull, is not known at the start. Multiple passes with increasing values of m are done which then terminates when m≥h. See below on choosing parameter m. The algorithm starts by arbitrarily partitioning the set of points P into K=⌈n/m⌉ subsets (Qk)k=1,2,...K with at most m points each; notice that K=O(n/m). For each subset Qk, it computes the convex hull, Ck, using an O(plog⁡p) algorithm (for example, Graham scan), where p is the number of points in the subset. As there are K subsets of O(m) points each, this phase takes K⋅O(mlog⁡m)=O(nlog⁡m) time. During the second phase, Jarvis's march is executed, making use of the precomputed (mini) convex hulls, (Ck)k=1,2,...K. At each step in this Jarvis's march algorithm, we have a point pi in the convex hull (at the beginning, pi may be the point in P with the lowest y coordinate, which is guaranteed to be in the convex hull of P), and need to find a point pi+1=f(pi,P) such that all other points of P are to the right of the line pipi+1, where the notation pi+1=f(pi,P) simply means that the next point, that is pi+1, is determined as a function of pi and P. The convex hull of the set Qk, Ck, is known and contains at most m points (listed in a clockwise or counter-clockwise order), which allows to compute f(pi,Qk) in O(log⁡m) time by binary search. Hence, the computation of f(pi,Qk) for all the K subsets can be done in O(Klog⁡m) time. Then, we can determine f(pi,P) using the same technique as normally used in Jarvis's march, but only considering the points (f(pi,Qk))1≤k≤K (i.e. the points in the mini convex hulls) instead of the whole set P. For those points, one iteration of Jarvis's march is O(K) which is negligible compared to the computation for all subsets. Jarvis's march completes when the process has been repeated O(h) times (because, in the way Jarvis march works, after at most h iterations of its outermost loop, where h is the number of points in the convex hull of P, we must have found the convex hull), hence the second phase takes O(Khlog⁡m) time, equivalent to O(nlog⁡h) time if m is close to h (see below the description of a strategy to choose m such that this is the case). By running the two phases described above, the convex hull of n points is computed in O(nlog⁡h) time.

Choosing the parameter m If an arbitrary value is chosen for m, it may happen that m<h. In that case, after m steps in the second phase, we interrupt the Jarvis's march as running it to the end would take too much time. At that moment, O(nlog⁡m) time will have been spent, and the convex hull will not have been calculated. The idea is to make multiple passes of the algorithm with increasing values of m; each pass terminates (successfully or unsuccessfully) in O(nlog⁡m) time. If m increases too slowly between passes, the number of iterations may be large; on the other hand, if it rises too quickly, the first m for which the algorithm terminates successfully may be much larger than h, and produce a complexity O(nlog⁡m)>O(nlog⁡h).

Squaring Strategy One possible strategy is to square the value of m at each iteration, up to a maximum value of n (corresponding to a partition in singleton sets). Starting from a value of 2, at iteration t, m=min⁡(n,22t) is chosen. In that case, O(log⁡log⁡h) iterations are made, given that the algorithm terminates once we have

m=22t≥h⟺log⁡(22t)≥log⁡h⟺2t≥log⁡h⟺log⁡2t≥log⁡log⁡h⟺t≥log⁡log⁡h, with the logarithm taken in base 2, and the total running time of the algorithm is

∑t=0⌈log⁡log⁡h⌉O(nlog⁡(22t))=O(n)∑t=0⌈log⁡log⁡h⌉2t=O(n⋅21+⌈log⁡log⁡h⌉)=O(nlog⁡h).

In three dimensions To generalize this construction for the 3-dimensional case, an O(nlog⁡n) algorithm to compute the 3-dimensional convex hull by Preparata and Hong should be used instead of Graham scan, and a 3-dimensional version of Jarvis's march needs to be used. The time complexity remains O(nlog⁡h).

Pseudocode In the following pseudocode, text between parentheses and in italic are comments. To fully understand the following pseudocode, it is recommended that the reader is already familiar with Graham scan and Jarvis march algorithms to compute the convex hull, C, of a set of points, P.

… excerpt ends here. Continue reading the full article.

Illustrations

Chan's algorithm: A 2D demo for Chan's algorithm. Note however that the algorithm divides the points arbitrarily, not by x-coordinate.
A 2D demo for Chan's algorithm. Note however that the algorithm divides the points arbitrarily, not by x-coordinate.

Worked examples

Example 1 — a first encounter with Chan's algorithm

Start with the simplest possible case. Write down what Chan's 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 Chan's 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 Chan's 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 Chan's algorithm

In research
Chan's 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 Chan's 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
Chan's algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Convex hull algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Chan's 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 “Chan's algorithm” →

How to study Chan's algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Chan's 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 Chan's algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Chan's algorithm in simple terms?

In computational geometry, Chan's algorithm, named after Timothy M. Chan, is an optimal output-sensitive algorithm to compute the convex hull of a set P of n points, in 2- or 3-dimensional space.

Why does Chan's 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 Chan's 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 Chan's algorithm.

Tags

  • Convex hull algorithms

Keep exploring