ArticleslgStudy

computer science

Kernighan–Lin algorithm

Kernighan–Lin 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 Kernighan–Lin algorithm rather than just read about it. In short: The Kernighan–Lin algorithm is a heuristic algorithm for finding partitions of graphs. The algorithm has important practical application in the layout of digital circuits and components in electronic design automation of VLSI.

Key takeaways

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

Reference excerpt

The Kernighan–Lin algorithm is a heuristic algorithm for finding partitions of graphs. The algorithm has important practical application in the layout of digital circuits and components in electronic design automation of VLSI.

Description The input to the algorithm is an undirected graph G = (V, E) with vertex set V, edge set E, and (optionally) numerical weights on the edges in E. The goal of the algorithm is to partition V into two disjoint subsets A and B of equal (or nearly equal) size, in a way that minimizes the sum T of the weights of the subset of edges that cross from A to B. If the graph is unweighted, then instead the goal is to minimize the number of crossing edges; this is equivalent to assigning weight one to each edge. The algorithm maintains and improves a partition, in each pass using a greedy algorithm to pair up vertices of A with vertices of B, so that moving the paired vertices from one side of the partition to the other will improve the partition. After matching the vertices, it then performs a subset of the pairs chosen to have the best overall effect on the solution quality T. Given a graph with n vertices, each pass of the algorithm runs in time O(n2 log n). In more detail, for each a ∈ A {\displaystyle a\in A} , let I a {\displaystyle I_{a}} be the internal cost of a, that is, the sum of the costs of edges between a and other nodes in A, and let E a {\displaystyle E_{a}} be the external cost of a, that is, the sum of the costs of edges between a and nodes in B. Similarly, define I b {\displaystyle I_{b}} , E b {\displaystyle E_{b}} for each b ∈ B {\displaystyle b\in B} . Furthermore, let

D s = E s − I s {\displaystyle D_{s}=E_{s}-I_{s}}

be the difference between the external and internal costs of s. If a and b are interchanged, then the reduction in cost is

T o l d − T n e w = D a + D b − 2 c a , b {\displaystyle T_{old}-T_{new}=D_{a}+D_{b}-2c_{a,b}}

where c a , b {\displaystyle c_{a,b}} is the cost of the possible edge between a and b. The algorithm attempts to find an optimal series of interchange operations between elements of A {\displaystyle A} and B {\displaystyle B} which maximizes T o l d − T n e w {\displaystyle T_{old}-T_{new}} and then executes the operations, producing a partition of the graph to A and B.

Pseudocode Source:

function Kernighan-Lin(G(V, E)) is determine a balanced initial partition of the nodes into sets A and B do compute D values for all a in A and b in B let gv, av, and bv be empty lists for n := 1 to |V| / 2 do find a from A and b from B, such that g = D[a] + D[b] − 2×c(a, b) is maximal remove a and b from further consideration in this pass add g to gv, a to av, and b to bv update D values for the elements of A = A \ a and B = B \ b end for find k which maximizes g_max, the sum of gv[1], ..., gv[k] if g_max > 0 then Exchange av[1], av[2], ..., av[k] with bv[1], bv[2], ..., bv[k] until (g_max ≤ 0)

return G(V, E)

See also Fiduccia–Mattheyses algorithm

References

Worked examples

Example 1 — a first encounter with Kernighan–Lin algorithm

Start with the simplest possible case. Write down what Kernighan–Lin 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 Kernighan–Lin 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 Kernighan–Lin 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 Kernighan–Lin algorithm

In research
Kernighan–Lin 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 Kernighan–Lin 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
Kernighan–Lin algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Combinatorial algorithms, Combinatorial optimization, Heuristic algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Kernighan–Lin 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 “Kernighan–Lin algorithm” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Kernighan–Lin algorithm in 20 minutes

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

Frequently asked questions

What is Kernighan–Lin algorithm in simple terms?

The Kernighan–Lin algorithm is a heuristic algorithm for finding partitions of graphs. The algorithm has important practical application in the layout of digital circuits and components in electronic design automation of VLSI.

Why does Kernighan–Lin 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 Kernighan–Lin 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 Kernighan–Lin algorithm.

Tags

  • Combinatorial algorithms
  • Combinatorial optimization
  • Heuristic algorithms

Keep exploring