C++ Articles

Page 4 of 597

Binary Number System - Overflow in Arithmetic Addition in C/C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 1K+ Views

The 2's complement number system is widely implemented in computer architecture for representing signed integers. In an N-bit 2's complement system, numbers can be represented from -2n-1 to 2n-1 - 1. For example − 4-bit system represents numbers from -8 to 7 5-bit system represents numbers from -16 to 15 Overflow occurs when adding two N-bit 2's complement numbers and the result is too large to fit into the N-bit representation. Syntax // Overflow detection formula overflow = carry_in_msb ^ carry_out_msb Understanding Overflow A computer uses N-bit fixed registers. ...

Read More

Barabasi Albert Graph (for Scale Free Models) in C/C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 359 Views

The Barabási-Albert model is one of the most important models for generating scale-free networks. It combines two fundamental concepts: growth and preferential attachment. Growth means that the number of nodes in the network increases over time, while preferential attachment means that highly connected nodes are more likely to receive new connections. This model simulates real-world networks where popular nodes (like well-known websites or influential people) attract more connections than less popular ones, following the "rich get richer" principle. Syntax // Basic structure for BA model implementation typedef struct { int **adjacencyMatrix; ...

Read More

Arrange a binary string to get maximum value within a range of indices C/C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 305 Views

In this problem, we have a binary string consisting of only 0's and 1's, along with M non-intersecting ranges [A1, B1], [A2, B2], ..., [AM, BM]. We need to rearrange the string to maximize the sum within the given ranges while ensuring the result is lexicographically maximum. Syntax char* arrangeString(char* binaryStr, int ranges[][2], int m); Algorithm The approach involves two main steps − First, fill all the given ranges with 1's to maximize the sum Then, place remaining 1's from left to right to achieve lexicographical maximum Example 1: Basic ...

Read More

An application on Bertrandís ballot theorem in C/C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 270 Views

Bertrand's ballot theorem states that in an election where candidate A receives p votes and candidate B receives q votes (where p > q), the probability that A is always strictly ahead throughout the counting process is (p-q)/(p+q). This theorem has practical applications in probability theory and combinatorics. Syntax Probability = (p - q) / (p + q) where p > q > 0 Mathematical Example Let there are 5 voters, of whom 3 vote for candidate A and 2 vote for candidate B (so p = 3 and q = 2). Ten possibilities ...

Read More

All combinations of strings that can be used to dial a number in C/C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 195 Views

Given a phone number, this program generates all possible string combinations that can be formed using the traditional phone keypad mapping. Each digit (2-9) maps to multiple letters, while digits 0 and 1 map to themselves. Syntax void printWords(int number[], int n); Keypad Mapping 2 ABC 3 DEF 4 GHI 5 JKL ...

Read More

C vs BASH Fork bomb in C/C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 512 Views

A fork bomb is a type of denial-of-service attack that creates an exponential number of processes, consuming system resources. While BASH fork bombs are more persistent because created processes detach from the parent, C fork bombs have their own characteristics and can be modified to increase their impact. Syntax #include int main() { while(1) { fork(); } return 0; } BASH vs C Fork Bomb Differences The key differences between BASH and ...

Read More

AA Trees in C/C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 2K+ Views

An AA tree in computer science is defined as a form of balanced binary search tree designed for storing and retrieving ordered data efficiently. AA trees are a variation of red-black trees but with simplified balancing rules. Unlike red-black trees, red nodes (horizontal links) in AA trees can only exist as right children, never left children. Key Properties AA trees maintain the following invariants − The level of every leaf node is one The level of every left child is exactly one smaller than its parent The level of every right child is equal to or ...

Read More

A-Buffer Method in C/C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 2K+ Views

The A-Buffer method is an advanced hidden surface removal technique in computer graphics that extends the traditional Z-Buffer algorithm. Also known as anti-aliased, area-averaged, or accumulation buffer, this technique handles both opaque and transparent objects, making it suitable for complex rendering scenarios where multiple surfaces contribute to a single pixel. Syntax struct ABuffer { float depth; union { struct { int r, g, b; ...

Read More

A Number Link Game in C/C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 311 Views

The Number Link Game is a logic puzzle played on an n × n grid. Some squares are empty, some are solid (blocked), and some contain numbered endpoints (1, 2, 3, etc.). Each number appears exactly twice on the board. The goal is to connect matching numbers with non-intersecting paths using only horizontal and vertical movements, filling all non-solid squares. Syntax // Union-Find structure for path generation typedef struct { int parent[MAX_SIZE]; int rank[MAX_SIZE]; } UnionFind; // Game board representation typedef struct { int ...

Read More

System() Function in C/C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 38K+ Views

The system() function is a part of the C standard library that executes system commands. It is used to pass commands that can be executed in the command processor or terminal of the operating system, and returns the command's exit status after completion. Note: To use the system() function, include header file. Syntax int system(const char *command); Parameters command − A pointer to a null-terminated string containing the command to be executed. If NULL, checks if command processor is available. Return Value Returns the exit ...

Read More
Showing 31–40 of 5,962 articles
« Prev 1 2 3 4 5 6 597 Next »
Advertisements