Slow Start Backoff Algorithm for Ad-Hoc
Last Updated :
28 Apr, 2025
If the receiver proclaims a large window-size, larger than what the network en-route can manage, then there will always be packet losses. So there will be re-transmissions as well. However, the sender can’t send all the packets for which ACK (Acknowledgement) has not been received. Because of this way, even more congestion in the network will be caused. Moreover, the sender cannot be sure about the packets that have been lost due to transmission. It might be that this is the only packet that has been lost. It will also be not know how many packets have been actually received and buffered by the receiver. In that case, the sender will have superfluously sent various packets.
So the re-transmission of the packets also follows slow - start backoff mechanism. However, we do precisely need to keep an upper bound on the size of the packets as it gets increases in slow start, to prevent it from the increasing in unbounded and causing congestion. In slow – start backoff mechanism
the threshold window size is half the value of the size of the congestion window.
Prerequisite: Back-off Algorithm for CSMA/CD
Algorithm of Slow-Start Mechanism:-
repeat
if ACK frame received then successful transmission
if current backoff window size <= Wm then
if current backoff window size = W0 then
current backoff window size = W0
else
current backoff window size = current backoff window size ÷ 2
else
current backoff window size = current backoff window size-W0
else
if current backoff window size < Wm then
current backoff window size = current backoff window size × 2
else frame lost due to collision or interference
if current backoff window size = Wn then
current backoff window size = Wn
else
current backoff window size = current backoff window size +W0
until no more frame to transmit
end
Examples:
This represents the successful transmission because Threshold window is lesser the current window.
Input :
Enter the Threshold value:-->512
Enter the Current backoff window size:-->64
Output :
Backoff Window Size is:-->128
Backoff Window Size is:-->96
Successful transmission
Backoff Window Size is:-->32
Successful transmission
Backoff Window Size is:-->32
Backoff Window Size is:-->128
Backoff Window Size is:-->96
Successful transmission
Backoff Window Size is:-->32
This represents the unsuccessful transmission because the threshold window is greater the current window.
Input :
Enter the Threshold value:-->512
Enter the Current backoff window size:-->1024
Output :
Frame lost due to collision or interferenceBackoff Window Size is:-->1056
Successful transmission
Backoff Window Size is:-->512
Successful transmission
Backoff Window Size is:-->512
Frame lost due to collision or interferenceBackoff Window Size is:-->1056
Successful transmission
Backoff Window Size is:-->512
Notations:-
W0 --> Initial backoff window size
Wm --> Threshold
Wn --> Maximum backoff window size
ACK --> Acknowledgement
Curr_BT --> Current backoff window size
Implementation of the Slow-Start Mechanism:-
CPP
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <random>
#include <string>
#include <time.h>
using namespace std;
void signal(int array_ACK[])
{
srand(time_t(0));
for (int i = 0; i < 5; i++) {
array_ACK[i] = rand() % 2;
}
}
void Slow_Start_Backoff(int Wm, int Wo, int Wn,
int Curr_BT, int array_ACK[])
{
// Taking ACK Binary values in
// array by user one by one
// backoff_win_size defines
// backoff window size
int backoff_win_size = 0;
// Printing of backoff window size takes place
for (int j = 0; j < 5; j++) {
if (array_ACK[j] == 1) {
cout << "Successful transmission" << endl;
if (Curr_BT <= Wm) {
if (Curr_BT == Wo) {
Curr_BT = Wo;
cout << "Backoff Window Size is:-->"
<< Curr_BT << endl;
}
else {
Curr_B= Curr_BT / 2;
cout << "Backoff Window Size is:-->"
<< Curr_BT << endl;
}
}
else {
Curr_BT = Curr_BT - Wo;
cout << "Backoff Window Size is:-->"
<< Curr_BT << endl;
}
}
else {
if (Curr_BT < Wm) {
Curr_BT = Curr_BT * 2;
cout << "Backoff Window Size is:-->"
<< Curr_BT << endl;
}
else {
cout << "Frame lost due to collision"
<<" or interference";
}
if (Curr_BT == Wn) {
Curr_BT = Wn;
cout << "Backoff Window Size is:-->"
<< Curr_BT << endl
<< endl;
}
else {
Curr_BT = Curr_BT + Wo;
cout << "Backoff Window Size is:-->"
<< Curr_BT << endl;
}
}
}
}
// Driver Code
int main()
{
int Wm, Wo, Wn, Curr_BT;
int array_ACK[5];
Wo = 32; // Initial backoff window size
Wn = 1024; // Maximum backoff window size
// Curr_BT defines the current backoff window size
cout << "Enter the Threshold value:-->";
cin >> Wm; // Threshold backoff window size
cout << "Enter the Current backoff window size:-->";
cin >> Curr_BT;
signal(array_ACK);
Slow_Start_Backoff(Wm, Wo, Wn, Curr_BT, array_ACK);
return 0;
}
Java
// Java program to implement the approach
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
class GFG {
static void signal(int[] array_ACK)
{
for (var i = 0; i < 5; i++) {
array_ACK[i] = ThreadLocalRandom.current().nextInt(1, 101) % 2;
}
}
static void Slow_Start_Backoff(int Wm, int Wo, int Wn,
int Curr_BT,
int[] array_ACK)
{
// Taking ACK Binary values in
// array by user one by one
// backoff_win_size defines
// backoff window size
// Printing of backoff window size takes place
for (var j = 0; j < 5; j++) {
if (array_ACK[j] == 1) {
System.out.println(
"Successful transmission");
if (Curr_BT <= Wm) {
if (Curr_BT == Wo) {
Curr_BT = Wo;
System.out.println(
"Backoff Window Size is:-->"
+ Curr_BT);
}
else {
Curr_BT = (int)(Curr_BT / 2);
System.out.println(
"Backoff Window Size is:-->"
+ Curr_BT);
}
}
else {
Curr_BT = Curr_BT - Wo;
System.out.println(
"Backoff Window Size is:-->"
+ Curr_BT);
}
}
else {
if (Curr_BT < Wm) {
Curr_BT = Curr_BT * 2;
System.out.println(
"Backoff Window Size is:-->"
+ Curr_BT);
}
else {
System.out.println(
"Frame lost due to collision"
+ " or interference");
}
if (Curr_BT == Wn) {
Curr_BT = Wn;
System.out.println(
"Backoff Window Size is:-->"
+ Curr_BT + "\n");
}
else {
Curr_BT = Curr_BT + Wo;
System.out.println(
"Backoff Window Size is:-->"
+ Curr_BT);
}
}
}
}
// Driver Code
public static void main(String[] args)
{
int Wm, Wo, Wn, Curr_BT;
int[] array_ACK = new int[5];
Wo = 32; // Initial backoff window size
Wn = 1024; // Maximum backoff window size
// Curr_BT defines the current backoff window size
Wm = 512; // Threshold backoff window size
Curr_BT = 1024;
signal(array_ACK);
Slow_Start_Backoff(Wm, Wo, Wn, Curr_BT, array_ACK);
}
}
// This code is contributed by phasing17.
Python3
# Python3 program to implement the approach
import random
def signal(array_ACK):
for i in range(5):
array_ACK[i] = (random.randint(1, 101) % 2);
def Slow_Start_Backoff( Wm, Wo, Wn, Curr_BT, array_ACK):
# Taking ACK Binary values in
# array by user one by one
# backoff_win_size defines
# backoff window size
backoff_win_size = 0;
# Printing of backoff window size takes place
for j in range(5):
if (array_ACK[j] == 1):
print("Successful transmission");
if (Curr_BT <= Wm) :
if (Curr_BT == Wo):
Curr_BT = Wo;
print("Backoff Window Size is:-->", Curr_BT);
else :
Curr_B= Math.floor(Curr_BT / 2);
print( "Backoff Window Size is:-->", Curr_BT);
else :
Curr_BT = Curr_BT - Wo;
print("Backoff Window Size is:-->", Curr_BT);
else :
if (Curr_BT < Wm):
Curr_BT = Curr_BT * 2;
print("Backoff Window Size is:-->", Curr_BT);
else :
print("Frame lost due to collision" + " or interference");
if (Curr_BT == Wn) :
Curr_BT = Wn;
print("Backoff Window Size is:-->", Curr_BT, "\n")
else:
Curr_BT = Curr_BT + Wo;
print("Backoff Window Size is:-->", Curr_BT);
# Driver Code
array_ACK = [0 for _ in range(5)]
Wo = 32; # Initial backoff window size
Wn = 1024; # Maximum backoff window size
# Curr_BT defines the current backoff window size
Wm = 512; # Threshold backoff window size
Curr_BT = 1024;
signal(array_ACK);
Slow_Start_Backoff(Wm, Wo, Wn, Curr_BT, array_ACK);
# This code is contributed by phasing17.
C#
// C# program to implement the approach
using System;
using System.Collections.Generic;
class GFG {
static void signal(int[] array_ACK)
{
Random rand = new Random();
for (var i = 0; i < 5; i++) {
array_ACK[i] = (rand.Next(1, 100)) % 2;
}
}
static void Slow_Start_Backoff(int Wm, int Wo, int Wn,
int Curr_BT,
int[] array_ACK)
{
// Taking ACK Binary values in
// array by user one by one
// backoff_win_size defines
// backoff window size
// Printing of backoff window size takes place
for (var j = 0; j < 5; j++) {
if (array_ACK[j] == 1) {
Console.WriteLine(
"Successful transmission");
if (Curr_BT <= Wm) {
if (Curr_BT == Wo) {
Curr_BT = Wo;
Console.WriteLine(
"Backoff Window Size is:-->"
+ Curr_BT);
}
else {
Curr_BT = (int)(Curr_BT / 2);
Console.WriteLine(
"Backoff Window Size is:-->"
+ Curr_BT);
}
}
else {
Curr_BT = Curr_BT - Wo;
Console.WriteLine(
"Backoff Window Size is:-->"
+ Curr_BT);
}
}
else {
if (Curr_BT < Wm) {
Curr_BT = Curr_BT * 2;
Console.WriteLine(
"Backoff Window Size is:-->"
+ Curr_BT);
}
else {
Console.WriteLine(
"Frame lost due to collision"
+ " or interference");
}
if (Curr_BT == Wn) {
Curr_BT = Wn;
Console.WriteLine(
"Backoff Window Size is:-->"
+ Curr_BT + "\n");
}
else {
Curr_BT = Curr_BT + Wo;
Console.WriteLine(
"Backoff Window Size is:-->"
+ Curr_BT);
}
}
}
}
// Driver Code
public static void Main(string[] args)
{
int Wm, Wo, Wn, Curr_BT;
int[] array_ACK = new int[5];
Wo = 32; // Initial backoff window size
Wn = 1024; // Maximum backoff window size
// Curr_BT defines the current backoff window size
Wm = 512; // Threshold backoff window size
Curr_BT = 1024;
signal(array_ACK);
Slow_Start_Backoff(Wm, Wo, Wn, Curr_BT, array_ACK);
}
}
// This code is contributed by phasing17.
JavaScript
// JS program to implement the approach
function signal(array_ACK)
{
for (var i = 0; i < 5; i++) {
array_ACK[i] = ( Math.floor(Math.random() * 100)) % 2;
}
}
function Slow_Start_Backoff( Wm, Wo, Wn, Curr_BT, array_ACK)
{
// Taking ACK Binary values in
// array by user one by one
// backoff_win_size defines
// backoff window size
let backoff_win_size = 0;
// Printing of backoff window size takes place
for (var j = 0; j < 5; j++) {
if (array_ACK[j] == 1) {
console.log("Successful transmission");
if (Curr_BT <= Wm) {
if (Curr_BT == Wo) {
Curr_BT = Wo;
console.log("Backoff Window Size is:-->" + Curr_BT);
}
else {
Curr_B= Math.floor(Curr_BT / 2);
console.log( "Backoff Window Size is:-->"
+ Curr_BT);
}
}
else {
Curr_BT = Curr_BT - Wo;
console.log("Backoff Window Size is:-->"
+ Curr_BT);
}
}
else {
if (Curr_BT < Wm) {
Curr_BT = Curr_BT * 2;
console.log("Backoff Window Size is:-->"
+ Curr_BT);
}
else {
console.log("Frame lost due to collision"
+ " or interference");
}
if (Curr_BT == Wn) {
Curr_BT = Wn;
console.log("Backoff Window Size is:-->"
+ Curr_BT + "\n")
}
else {
Curr_BT = Curr_BT + Wo;
console.log("Backoff Window Size is:-->"
+ Curr_BT);
}
}
}
}
// Driver Code
let Wm, Wo, Wn, Curr_BT;
let array_ACK = new Array(5);
Wo = 32; // Initial backoff window size
Wn = 1024; // Maximum backoff window size
// Curr_BT defines the current backoff window size
Wm = 512; // Threshold backoff window size
Curr_BT = 1024;
signal(array_ACK);
Slow_Start_Backoff(Wm, Wo, Wn, Curr_BT, array_ACK);
// This code is contributed by phasing17.
How the data sent in the form of packets through the network:-
Any type of data gets converted into the binary format and this binary format contains 0's and 1's bytes
which gets divided into the small binary bit sequences called packets.
Now, we are implementing code in which the random matrix of 0's and 1's generates and suppose the binary file bit sequence arranged in the matrix row-wise in fixed-length (Taking a Length 10). Then each row of the matrix represents a single data packet that is going to be transmitted.
Implementation of the Random Matrix Generator:-
CPP
// C++ program to construct the
// Random Matrix Generator.
#include <iostream>
#include <iterator>
#include <list>
#include <random>
#include <string>
using namespace std;
void showlist(list<string> l1)
{
list<string>::iterator it;
cout << "list of frame packets are "
<<"show as below :-> " << endl;
cout << endl;
for (it = l1.begin(); it != l1.end(); ++it)
cout << *it << endl;
cout << '\n';
}
// Driver Code
int main()
{
int x, y, k = 1;
string s, s1, s2;
list<string> l1;
srand(time_t(0));
cout << "Rows: " << endl;
cin >> x;
cout << "Columns: " << endl;
cin >> y;
int randomNums[x][y];
std::string temp[x];
int random;
for (int i = 0; i < x; i++) {
// This loop is for the row
for (int p = 0; p < y; p++) {
// Here you would randomize each
// element for the array.
random = rand() % 2;
randomNums[i][p] = random;
}
}
for (int i = 0; i < x; i++) {
// This loop is for the row
for (int p = 0; p < y; p++) {
// Here you would randomize each
// element for the array.
cout << randomNums[i][p] << "\t";
}
cout << endl;
}
cout << endl;
// concatenation of the bits in the matrix row
// to form a single data packet
for (int i = 0; i < x; i++) {
temp[i] = to_string(randomNums[i][0]);
for (int j = 0; j < y; ++j) {
s1 = temp[i];
s2 = to_string(randomNums[i][j]);
s = s1 + s2;
temp[i] = s;
k++;
}
temp[i].erase(temp[i].begin() + 1);
l1.push_back(temp[i]);
}
showlist(l1);
return 0;
}
Java
// Java program to construct the
// Random Matrix Generator.
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
class GFG {
static void showlist(ArrayList<String> l1)
{
System.out.println("list of frame packets are "
+ "show as below :-> ");
for (var it : l1)
System.out.println(it);
}
// Driver Code
public static void main(String[] args)
{
int x = 10, y = 10, k = 1;
String s, s1, s2;
ArrayList<String> l1 = new ArrayList<String>();
System.out.println("Rows:" + x);
System.out.println("Columns:" + y);
int[][] randomNums = new int[x][y];
String[] temp = new String[x];
int random;
for (int i = 0; i < x; i++) {
// This loop is for the row
for (int p = 0; p < y; p++) {
// Here you would randomize each
// element for the array.
random = Math.abs(
ThreadLocalRandom.current().nextInt()
% 2);
randomNums[i][p] = random;
}
}
for (int i = 0; i < x; i++) {
// This loop is for the row
for (int p = 0; p < y; p++) {
// Here you would randomize each
// element for the array.
System.out.print(randomNums[i][p] + "\t");
}
System.out.print("\n");
}
System.out.print("\n");
// concatenation of the bits in the matrix row
// to form a single data packet
for (int i = 0; i < x; i++) {
temp[i] = String.valueOf(randomNums[i][0]);
for (int j = 0; j < y; ++j) {
s1 = temp[i];
s2 = String.valueOf(randomNums[i][j]);
s = s1 + s2;
temp[i] = s;
k++;
}
temp[i] = temp[i].substring(1);
l1.add(temp[i]);
}
showlist(l1);
}
}
// This code is contributed by phasing17.
Python3
# Python3 program to construct the
# Random Matrix Generator.
import random as rn
def showlist(l1):
print("list of frame packets are show as below :-> \n");
print(*l1, sep = '\n')
# Driver Code
x = 10
y = 10
k = 1;
s = ""
s1 = ""
s2 = "";
l1 = [];
print("Rows: 10");
print("Columns: 10");
randomNums = [[None for _ in range(y)] for _ in range(x) ]
temp = ["" for _ in range(x)]
for i in range(x):
# This loop is for the row
for p in range(y):
# Here you would randomize each
# element for the array.
random = (rn.randint(1, 100000)) % 2
randomNums[i][p] = random;
for i in range(x):
# This loop is for the row
for p in range(y):
# Here you would randomize each
# element for the array.
print(randomNums[i][p], end = "\t")
print()
print()
# concatenation of the bits in the matrix row
# to form a single data packet
for i in range(x):
temp[i] = str(randomNums[i][0]);
for j in range(y):
s1 = temp[i];
s2 = str(randomNums[i][j]);
s = s1 + s2;
temp[i] = s;
k += 1;
temp[i] = temp[i][1::];
l1.append(temp[i]);
showlist(l1);
# This code is contributed by phasing17
C#
// C# program to construct the
// Random Matrix Generator.
using System;
using System.Collections.Generic;
class GFG
{
static void showlist(List<string> l1)
{
Console.WriteLine("list of frame packets are "
+ "show as below :-> ");
foreach (var it in l1)
Console.WriteLine(it);
}
// Driver Code
public static void Main(string[] args)
{
int x = 10, y = 10, k = 1;
string s, s1, s2;
List<string> l1 = new List<string>();
Random rand = new Random();
Console.WriteLine("Rows:" + x);
Console.WriteLine("Columns:" + y);
int[,] randomNums = new int[x, y];
string[] temp = new string[x];
int random;
for (int i = 0; i < x; i++) {
// This loop is for the row
for (int p = 0; p < y; p++) {
// Here you would randomize each
// element for the array.
random = rand.Next(1, 101) % 2;
randomNums[i, p] = random;
}
}
for (int i = 0; i < x; i++) {
// This loop is for the row
for (int p = 0; p < y; p++) {
// Here you would randomize each
// element for the array.
Console.Write(randomNums[i, p] + "\t");
}
Console.Write("\n");
}
Console.Write("\n");
// concatenation of the bits in the matrix row
// to form a single data packet
for (int i = 0; i < x; i++) {
temp[i] = Convert.ToString(randomNums[i, 0]);
for (int j = 0; j < y; ++j) {
s1 = temp[i];
s2 = Convert.ToString(randomNums[i, j]);
s = s1 + s2;
temp[i] = s;
k++;
}
temp[i] = temp[i].Substring(1);
l1.Add(temp[i]);
}
showlist(l1);
}
}
// This code is contributed by phasing17.
JavaScript
// C++ program to construct the
// Random Matrix Generator.
function showlist(l1)
{
console.log("list of frame packets are "
+ "show as below :-> \n");
for (var l of l1)
console.log(l);
}
// Driver Code
let x = 10, y = 10, k = 1;
let s = "", s1 = "", s2 = "";
let l1 = [];
console.log("Rows: 10");
console.log("Columns: 10");
let randomNums = new Array(x);
for (var i = 0; i < 10; i++)
randomNums[i] = new Array(y);
let temp = new Array(x).fill("");
let random;
for (var i = 0; i < x; i++) {
// This loop is for the row
for (var p = 0; p < y; p++) {
// Here you would randomize each
// element for the array.
random = Math.floor(Math.random() * 10000) % 2;
randomNums[i][p] = random;
}
}
for (var i = 0; i < x; i++) {
// This loop is for the row
for (var p = 0; p < y; p++) {
// Here you would randomize each
// element for the array.
process.stdout.write(randomNums[i][p] + "\t");
}
process.stdout.write("\n");
}
process.stdout.write("\n");
// concatenation of the bits in the matrix row
// to form a single data packet
for (var i = 0; i < x; i++) {
temp[i] = "" + (randomNums[i][0]);
for (var j = 0; j < y; ++j) {
s1 = temp[i];
s2 = "" + (randomNums[i][j]);
s = s1 + s2;
temp[i] = s;
k++;
}
temp[i] = temp[i].substring(1);
l1.push(temp[i]);
}
showlist(l1);
// This code is contributed by phasing17
Example:
Input:
Rows:
10
Columns:
10
Output:
0 1 1 0 1 1 0 1 0 1
0 0 0 0 0 0 1 1 0 0
0 1 1 0 1 1 0 1 1 1
0 1 0 0 0 0 1 0 0 0
0 0 1 1 0 0 1 0 0 0
0 0 0 0 1 0 1 1 1 0
0 0 1 1 0 0 1 1 0 1
1 1 0 0 1 1 0 0 0 1
1 1 0 0 1 0 1 1 1 1
0 1 0 1 1 0 0 1 1 1
list of frame packets are show as below :->
0110110101
0000001100
0110110111
0100001000
0011001000
0000101110
0011001101
1100110001
1100101111
0101100111
Reference: Slow Start Backoff Algorithm for Ad-Hoc Wireless Networks
Similar Reads
DSA Tutorial - Learn Data Structures and Algorithms DSA (Data Structures and Algorithms) is the study of organizing data efficiently using data structures like arrays, stacks, and trees, paired with step-by-step procedures (or algorithms) to solve problems effectively. Data structures manage how data is stored and accessed, while algorithms focus on
7 min read
What is OSI Model? - Layers of OSI Model The OSI (Open Systems Interconnection) Model is a set of rules that explains how different computer systems communicate over a network. OSI Model was developed by the International Organization for Standardization (ISO). The OSI Model consists of 7 layers and each layer has specific functions and re
13 min read
Quick Sort QuickSort is a sorting algorithm based on the Divide and Conquer that picks an element as a pivot and partitions the given array around the picked pivot by placing the pivot in its correct position in the sorted array. It works on the principle of divide and conquer, breaking down the problem into s
12 min read
Merge Sort - Data Structure and Algorithms Tutorials Merge sort is a popular sorting algorithm known for its efficiency and stability. It follows the divide-and-conquer approach. It works by recursively dividing the input array into two halves, recursively sorting the two halves and finally merging them back together to obtain the sorted array. Merge
14 min read
Data Structures Tutorial Data structures are the fundamental building blocks of computer programming. They define how data is organized, stored, and manipulated within a program. Understanding data structures is very important for developing efficient and effective algorithms. What is Data Structure?A data structure is a st
2 min read
Bubble Sort Algorithm Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order. This algorithm is not suitable for large data sets as its average and worst-case time complexity are quite high.We sort the array using multiple passes. After the fir
8 min read
Breadth First Search or BFS for a Graph Given a undirected graph represented by an adjacency list adj, where each adj[i] represents the list of vertices connected to vertex i. Perform a Breadth First Search (BFS) traversal starting from vertex 0, visiting vertices from left to right according to the adjacency list, and return a list conta
15+ min read
Binary Search Algorithm - Iterative and Recursive Implementation Binary Search Algorithm is a searching algorithm used in a sorted array by repeatedly dividing the search interval in half. The idea of binary search is to use the information that the array is sorted and reduce the time complexity to O(log N). Binary Search AlgorithmConditions to apply Binary Searc
15 min read
Insertion Sort Algorithm Insertion sort is a simple sorting algorithm that works by iteratively inserting each element of an unsorted list into its correct position in a sorted portion of the list. It is like sorting playing cards in your hands. You split the cards into two groups: the sorted cards and the unsorted cards. T
9 min read
Array Data Structure Guide In 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
4 min read