find the minimum sum of matrix n x n that select only one in each row and column
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
When tasked with finding the minimum sum of a matrix by selecting only one number from each row and column, we're delving into a classic problem in combinatorial optimization called the Assignment Problem. This article explains the problem, discusses the mathematical techniques used to solve it, and presents an example for clarity.
Understanding the Assignment Problem
The Assignment Problem in a matrix form can be described as follows: Given an cost matrix, assign each row to a unique column such that the total cost is minimized, and each row and column in the matrix is exactly used once. This can be visualized as assigning jobs to workers such that the total cost or time of assignments is minimized.
Mathematical Formulation
Given a cost matrix , where is the cost of assigning the row to the column, our goal is to find a permutation of that minimizes the objective function:
This is subject to the condition that is a permutation, thus reassures that each column and row is only selected once.
Hungarian Algorithm
One of the most efficient algorithms for solving the assignment problem is the Hungarian Algorithm. The method has a polynomial time complexity of and is popular due to its efficiency and straightforward implementation. The cornerstone of this algorithm is transforming the matrix to uncover the optimal assignment using an iterative process of reducing the matrix:
- Row Reduction: Subtract the smallest element in each row from all elements of that row.
- Column Reduction: Subtract the smallest element in each column from all elements of that column.
- Covering Zeros: Use the minimum number of lines to cover all zeros in the matrix.
- Adjust the Matrix: If fewer than n lines are used, adjust the matrix by subtracting the smallest uncovered number from uncovered elements and adding it to elements at intersections of lines.
- Repeat: Repeat the above steps until exactly lines are used to cover all zeros. The positions of zeros give the required assignments.
Example
Let's work through an example with the following cost matrix :
Step 1: Row Reduction
Subtract the smallest element of each row:
Step 2: Column Reduction
Subtract the smallest element of each column:
Step 3: Covering Zeros
Cover all zeros using a minimum number of lines:
• Two horizontal lines: one covering the first row zero and another covering the third row zero.
Step 4: Adjust the Matrix
Identify the smallest uncovered element (1), subtract it from all uncovered elements, and add it to elements at line intersections:
Repeat until a unique zero in each line is available. This results in the assignment: 1st row to 2nd column, 2nd row to 1st column, and 3rd row to 3rd column.
Conclusion
The minimum sum is obtained by following the derived assignments: . It reflects the optimal way of assigning rows to columns to yield minimum costs.
Summary Table
| Step | Operation | Resulting Matrix |
| Initial Matrix | $C = \begin\{bmatrix\} 4 & 1 & 3 \\ 2 & 0 & 5 \\ 3 & 2 & 2 \end\{bmatrix\}$ | $C = [4,1,3; 2,0,5; 3,2,2]$ () |
| Row Reduction | Subtract lowest in each row | |
| Column Reduction | Subtract lowest in each column | |
| Cover and Adjust | Minimal lines through zeros Adjust matrix |
The Hungarian algorithm provides a comprehensive process to efficiently resolve the assignment problem, thus making it a staple in various optimization tasks.

