View the step-by-step solution to:


C++ program to implement Kernighan-Lin's partitioning algorithm. The objective is to minimize the number of edges

in the cut and the partitioning should be two-way-even. The number of nodes in the test case would be even.

Input: A text file describing a set of even number of nodes and a set of edges. If there are n nodes, the node indices are continuous integers from 1 to n.

Input file format:

• The first line has two numbers - the number of nodes followed by the number of edges.

• Each of the following lines has two numbers that are indices of two nodes of an edge.

For example:

3 2

1 2

2 3

The input indicates there are three nodes and two edges. Node1 and node 2 are the indices of an edge; node 2 and node 3 are the indices of an edge.


• The initial solution must be partition {1, 2, ...,n/2} and {n/2+1, n/2+2, ..., n}.

• The input filename should be taken as the argument at command line in Linux/UNIX.

• Please submit source code and the executable code for Linux/UNIX.

• The output should be displayed to screen in a self-clear format.


• Two partitions, each of which is described by the indices of its member nodes.

• Cut set, represented by the edges in the cut, an edge is denoted by a pair of node indices.

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Let our 24/7 Electrical Engineering tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors