Channel Assignment Problem
Last Updated :
23 Jul, 2025
There are M transmitter and N receiver stations. Given a matrix that keeps track of the number of packets to be transmitted from a given transmitter to a receiver. If the (i; j)-th entry of the matrix is k, it means at that time the station i has k packets for transmission to station j.
During a time slot, a transmitter can send only one packet and a receiver can receive only one packet. Find the channel assignments so that maximum number of packets are transferred from transmitters to receivers during the next time slot.
Example:
0 2 0
3 0 1
2 4 0
The above is the input format. We call the above matrix M. Each value M[i; j] represents the number of packets Transmitter 'i' has to send to Receiver 'j'. The output should be:
The number of maximum packets sent in the time slot is 3
T1 -> R2
T2 -> R3
T3 -> R1
Note that the maximum number of packets that can be transferred in any slot is min(M, N).
Algorithm:
The channel assignment problem between sender and receiver can be easily transformed into Maximum Bipartite Matching(MBP) problem that can be solved by converting it into a flow network.
Step 1: Build a Flow Network
There must be a source and sink in a flow network. So we add a dummy source and add edges from source to all senders. Similarly, add edges from all receivers to dummy sink. The capacity of all added edges is marked as 1 unit.
Step 2: Find the maximum flow.
We use Ford-Fulkerson algorithm to find the maximum flow in the flow network built in step 1. The maximum flow is actually the maximum number of packets that can be transmitted without bandwidth interference in a time slot.
Implementation:
Let us first define input and output forms. Input is in the form of Edmonds matrix which is a 2D array ‘table[M][N]‘ with M rows (for M senders) and N columns (for N receivers). The value table[i][j] is the number of packets that has to be sent from transmitter ‘i’ to receiver ‘j’. Output is the maximum number of packets that can be transmitted without bandwidth interference in a time slot.
A simple way to implement this is to create a matrix that represents adjacency matrix representation of a directed graph with M+N+2 vertices. Call the fordFulkerson() for the matrix. This implementation requires O((M+N)*(M+N)) extra space.
Extra space can be reduced and code can be simplified using the fact that the graph is bipartite. The idea is to use DFS traversal to find a receiver for a transmitter (similar to augmenting path in Ford-Fulkerson). We call bpm() for every applicant, bpm() is the DFS based function that tries all possibilities to assign a receiver to the sender. In bpm(), we one by one try all receivers that a sender ‘u’ is interested in until we find a receiver or all receivers are tried without luck.
For every receiver we try, we do following:
If a receiver is not assigned to anybody, we simply assign it to the sender and return true. If a receiver is assigned to somebody else say x, then we recursively check whether x can be assigned some other receiver. To make sure that x doesn’t get the same receiver again, we mark the receiver ‘v’ as seen before we make recursive call for x. If x can get other receiver, we change the sender for receiver ‘v’ and return true. We use an array maxR[0..N-1] that stores the senders assigned to different receivers.
If bmp() returns true, then it means that there is an augmenting path in flow network and 1 unit of flow is added to the result in maxBPM().
C++
// C++ program to implement Channel Assignment Problem
#include <bits/stdc++.h>
using namespace std;
// A Depth First Search based recursive function that returns true
// if a matching for vertex u is possible
bool bpm(int u, vector<vector<int>> &table, vector<bool> &seen,
vector<int> &match) {
int n = table[0].size();
// Try every receiver one by one
for (int v = 0; v < n; v++) {
// If sender u has packets to send to receiver v and
// receiver v is not already mapped to any other sender
// just check if the number of packets is greater than '0'
// because only one packet can be sent in a time frame anyways
if (table[u][v]>0 && !seen[v]) {
// Mark v as visited
seen[v] = true;
// If receiver 'v' is not assigned to any sender OR
// previously assigned sender for receiver v (which is
// match[v]) has an alternate receiver available. Since
// v is marked as visited in the above line, match[v] in
// the following recursive call will not get receiver 'v' again
if (match[v] < 0 || bpm(match[v], table, seen, match)) {
match[v] = u;
return true;
}
}
}
return false;
}
// Returns maximum number of packets that can be sent parallelly in 1
// time slot from sender to receiver
int maxBPM(vector<vector<int>> &table) {
int m = table.size(), n = table[0].size();
// An array to keep track of the receivers assigned to the senders.
// The value of match[i] is the sender ID assigned to receiver i.
// the value -1 indicates nobody is assigned.
vector<int> match(n, -1);
// Count of receivers assigned to senders
int result = 0;
for (int u = 0; u < m; u++) {
// Mark all receivers as not seen for next sender
vector<bool> seen(n, false);
// Find if the sender 'u' can be assigned to the receiver
if (bpm(u, table, seen, match))
result++;
}
return result;
}
int main() {
vector<vector<int>> table = {{0, 2, 0}, {3, 0, 1}, {2, 4, 0}};
cout << maxBPM(table);
return 0;
}
Java
// Java program to implement Channel Assignment Problem
class GfG {
// A Depth First Search based recursive function that returns true
// if a matching for vertex u is possible
static boolean bpm(int u, int[][] table, boolean[] seen, int[] match) {
int n = table[0].length;
// Try every receiver one by one
for (int v = 0; v < n; v++) {
// If sender u has packets to send to receiver v and
// receiver v is not already mapped to any other sender
// just check if the number of packets is greater than '0'
// because only one packet can be sent in a time frame anyways
if (table[u][v] > 0 && !seen[v]) {
// Mark v as visited
seen[v] = true;
// If receiver 'v' is not assigned to any sender OR
// previously assigned sender for receiver v (which is
// match[v]) has an alternate receiver available. Since
// v is marked as visited in the above line, match[v] in
// the following recursive call will not get receiver 'v' again
if (match[v] < 0 || bpm(match[v], table, seen, match)) {
match[v] = u;
return true;
}
}
}
return false;
}
// Returns maximum number of packets that can be sent parallelly in 1
// time slot from sender to receiver
static int maxBPM(int[][] table) {
int m = table.length, n = table[0].length;
// An array to keep track of the receivers assigned to the senders.
// The value of match[i] is the sender ID assigned to receiver i.
// the value -1 indicates nobody is assigned.
int[] match = new int[n];
for (int i = 0; i < n; i++) match[i] = -1;
// Count of receivers assigned to senders
int result = 0;
for (int u = 0; u < m; u++) {
// Mark all receivers as not seen for next sender
boolean[] seen = new boolean[n];
// Find if the sender 'u' can be assigned to the receiver
if (bpm(u, table, seen, match))
result++;
}
return result;
}
public static void main(String[] args) {
int[][] table = {{0, 2, 0}, {3, 0, 1}, {2, 4, 0}};
System.out.println(maxBPM(table));
}
}
Python
# Python program to implement Channel Assignment Problem
# A Depth First Search based recursive function that returns true
# if a matching for vertex u is possible
def bpm(u, table, seen, match):
n = len(table[0])
# Try every receiver one by one
for v in range(n):
# If sender u has packets to send to receiver v and
# receiver v is not already mapped to any other sender
# just check if the number of packets is greater than '0'
# because only one packet can be sent in a time frame anyways
if table[u][v] > 0 and not seen[v]:
# Mark v as visited
seen[v] = True
# If receiver 'v' is not assigned to any sender OR
# previously assigned sender for receiver v (which is
# match[v]) has an alternate receiver available. Since
# v is marked as visited in the above line, match[v] in
# the following recursive call will not get receiver 'v' again
if match[v] < 0 or bpm(match[v], table, seen, match):
match[v] = u
return True
return False
# Returns maximum number of packets that can be sent parallelly in 1
# time slot from sender to receiver
def maxBPM(table):
m = len(table)
n = len(table[0])
# An array to keep track of the receivers assigned to the senders.
# The value of match[i] is the sender ID assigned to receiver i.
# the value -1 indicates nobody is assigned.
match = [-1] * n
# Count of receivers assigned to senders
result = 0
for u in range(m):
# Mark all receivers as not seen for next sender
seen = [False] * n
# Find if the sender 'u' can be assigned to the receiver
if bpm(u, table, seen, match):
result += 1
return result
if __name__ == "__main__":
table = [[0, 2, 0], [3, 0, 1], [2, 4, 0]]
print(maxBPM(table))
C#
// C# program to implement Channel Assignment Problem
using System;
class GfG {
// A Depth First Search based recursive function that returns true
// if a matching for vertex u is possible
static bool Bpm(int u, int[,] table, bool[] seen, int[] match) {
int n = table.GetLength(1);
// Try every receiver one by one
for (int v = 0; v < n; v++) {
// If sender u has packets to send to receiver v and
// receiver v is not already mapped to any other sender
// just check if the number of packets is greater than '0'
// because only one packet can be sent in a time frame anyways
if (table[u,v] > 0 && !seen[v]) {
// Mark v as visited
seen[v] = true;
// If receiver 'v' is not assigned to any sender OR
// previously assigned sender for receiver v (which is
// match[v]) has an alternate receiver available. Since
// v is marked as visited in the above line, match[v] in
// the following recursive call will not get receiver 'v' again
if (match[v] < 0 || Bpm(match[v], table, seen, match)) {
match[v] = u;
return true;
}
}
}
return false;
}
// Returns maximum number of packets that can be sent parallelly in 1
// time slot from sender to receiver
static int MaxBPM(int[,] table) {
int m = table.GetLength(0), n = table.GetLength(1);
// An array to keep track of the receivers assigned to the senders.
// The value of match[i] is the sender ID assigned to receiver i.
// the value -1 indicates nobody is assigned.
int[] match = new int[n];
for (int i = 0; i < n; i++) match[i] = -1;
// Count of receivers assigned to senders
int result = 0;
for (int u = 0; u < m; u++) {
// Mark all receivers as not seen for next sender
bool[] seen = new bool[n];
// Find if the sender 'u' can be assigned to the receiver
if (Bpm(u, table, seen, match))
result++;
}
return result;
}
static void Main() {
int[,] table = {{0, 2, 0}, {3, 0, 1}, {2, 4, 0}};
Console.WriteLine(MaxBPM(table));
}
}
JavaScript
// JavaScript program to implement Channel Assignment Problem
// A Depth First Search based recursive function that returns true
// if a matching for vertex u is possible
function bpm(u, table, seen, match) {
let n = table[0].length;
// Try every receiver one by one
for (let v = 0; v < n; v++) {
// If sender u has packets to send to receiver v and
// receiver v is not already mapped to any other sender
// just check if the number of packets is greater than '0'
// because only one packet can be sent in a time frame anyways
if (table[u][v] > 0 && !seen[v]) {
// Mark v as visited
seen[v] = true;
// If receiver 'v' is not assigned to any sender OR
// previously assigned sender for receiver v (which is
// match[v]) has an alternate receiver available. Since
// v is marked as visited in the above line, match[v] in
// the following recursive call will not get receiver 'v' again
if (match[v] < 0 || bpm(match[v], table, seen, match)) {
match[v] = u;
return true;
}
}
}
return false;
}
// Returns maximum number of packets that can be sent parallelly in 1
// time slot from sender to receiver
function maxBPM(table) {
let m = table.length, n = table[0].length;
// An array to keep track of the receivers assigned to the senders.
// The value of match[i] is the sender ID assigned to receiver i.
// the value -1 indicates nobody is assigned.
let match = new Array(n).fill(-1);
// Count of receivers assigned to senders
let result = 0;
for (let u = 0; u < m; u++) {
// Mark all receivers as not seen for next sender
let seen = new Array(n).fill(false);
// Find if the sender 'u' can be assigned to the receiver
if (bpm(u, table, seen, match))
result++;
}
return result;
}
let table = [[0, 2, 0], [3, 0, 1], [2, 4, 0]];
console.log(maxBPM(table));
Time Complexity: O((M + N) * N), Where M and N is the number of senders and number of receivers respectively.
Space Complexity: O(M) , here M is the number of senders.
Similar Reads
Basics & Prerequisites
Data Structures
Array Data StructureIn this article, we introduce array, implementation in different popular languages, its basic operations and commonly seen problems / interview questions. An array stores items (in case of C/C++ and Java Primitive Arrays) or their references (in case of Python, JS, Java Non-Primitive) at contiguous
3 min read
String in Data StructureA string is a sequence of characters. The following facts make string an interesting data structure.Small set of elements. Unlike normal array, strings typically have smaller set of items. For example, lowercase English alphabet has only 26 characters. ASCII has only 256 characters.Strings are immut
2 min read
Hashing in Data StructureHashing is a technique used in data structures that efficiently stores and retrieves data in a way that allows for quick access. Hashing involves mapping data to a specific index in a hash table (an array of items) using a hash function. It enables fast retrieval of information based on its key. The
2 min read
Linked List Data StructureA linked list is a fundamental data structure in computer science. It mainly allows efficient insertion and deletion operations compared to arrays. Like arrays, it is also used to implement other data structures like stack, queue and deque. Hereâs the comparison of Linked List vs Arrays Linked List:
2 min read
Stack Data StructureA Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). LIFO implies that the element that is inserted last, comes out first and FILO implies that the element that is inserted first
2 min read
Queue Data StructureA Queue Data Structure is a fundamental concept in computer science used for storing and managing data in a specific order. It follows the principle of "First in, First out" (FIFO), where the first element added to the queue is the first one to be removed. It is used as a buffer in computer systems
2 min read
Tree Data StructureTree Data Structure is a non-linear data structure in which a collection of elements known as nodes are connected to each other via edges such that there exists exactly one path between any two nodes. Types of TreeBinary Tree : Every node has at most two childrenTernary Tree : Every node has at most
4 min read
Graph Data StructureGraph Data Structure is a collection of nodes connected by edges. It's used to represent relationships between different entities. If you are looking for topic-wise list of problems on different topics like DFS, BFS, Topological Sort, Shortest Path, etc., please refer to Graph Algorithms. Basics of
3 min read
Trie Data StructureThe Trie data structure is a tree-like structure used for storing a dynamic set of strings. It allows for efficient retrieval and storage of keys, making it highly effective in handling large datasets. Trie supports operations such as insertion, search, deletion of keys, and prefix searches. In this
15+ min read
Algorithms
Searching AlgorithmsSearching algorithms are essential tools in computer science used to locate specific items within a collection of data. In this tutorial, we are mainly going to focus upon searching in an array. When we search an item in an array, there are two most common algorithms used based on the type of input
2 min read
Sorting AlgorithmsA Sorting Algorithm is used to rearrange a given array or list of elements in an order. For example, a given array [10, 20, 5, 2] becomes [2, 5, 10, 20] after sorting in increasing order and becomes [20, 10, 5, 2] after sorting in decreasing order. There exist different sorting algorithms for differ
3 min read
Introduction to RecursionThe process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. A recursive algorithm takes one step toward solution and then recursively call itself to further move. The algorithm stops once we reach the solution
14 min read
Greedy AlgorithmsGreedy algorithms are a class of algorithms that make locally optimal choices at each step with the hope of finding a global optimum solution. At every step of the algorithm, we make a choice that looks the best at the moment. To make the choice, we sometimes sort the array so that we can always get
3 min read
Graph AlgorithmsGraph is a non-linear data structure like tree data structure. The limitation of tree is, it can only represent hierarchical data. For situations where nodes or vertices are randomly connected with each other other, we use Graph. Example situations where we use graph data structure are, a social net
3 min read
Dynamic Programming or DPDynamic Programming is an algorithmic technique with the following properties.It is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for the same inputs, we can optimize it using Dynamic Programming. The idea is to simply store the results of
3 min read
Bitwise AlgorithmsBitwise algorithms in Data Structures and Algorithms (DSA) involve manipulating individual bits of binary representations of numbers to perform operations efficiently. These algorithms utilize bitwise operators like AND, OR, XOR, NOT, Left Shift, and Right Shift.BasicsIntroduction to Bitwise Algorit
4 min read
Advanced
Segment TreeSegment Tree is a data structure that allows efficient querying and updating of intervals or segments of an array. It is particularly useful for problems involving range queries, such as finding the sum, minimum, maximum, or any other operation over a specific range of elements in an array. The tree
3 min read
Pattern SearchingPattern searching algorithms are essential tools in computer science and data processing. These algorithms are designed to efficiently find a particular pattern within a larger set of data. Patten SearchingImportant Pattern Searching Algorithms:Naive String Matching : A Simple Algorithm that works i
2 min read
GeometryGeometry is a branch of mathematics that studies the properties, measurements, and relationships of points, lines, angles, surfaces, and solids. From basic lines and angles to complex structures, it helps us understand the world around us.Geometry for Students and BeginnersThis section covers key br
2 min read
Interview Preparation
Practice Problem