The buddy algorithm is a memory allocation and management algorithm that manages memory in the power of two increments. The programming language used is C++
The packet has 8 files out of which "main.cpp" is the only file necessary for running the program, the rest of the files are just terminal runtime screenshots that can be used for a better understanding of the code.
The buddy algorithm divides the memory into partitions in the powers of 2 according to the memory request.
The memory available for allocation is treated as a single block whose size is in the power of 2 and when the first request is made, if its size is greater than half of the memory available for allocation then the entire block is allocated else the block is split into two equal blocks (buddies) and this recursively goes on until the smallest block greater than or equal to the size of the request is found and allocated to it.
During the deallocation process, the buddy block that was allocated is freed and if possible, an unallocated buddy block is merged with a companion buddy block and forms a double-sized buddy block. Two buddy blocks are said to be companions if they are split from the same block initially.
Submitted by Koppula Bhanu Prakash Reddy (Bhanuprakash11)
Download packets of source code on Coders Packet