C++ Articles - Page 612 of 719

C++ Program to Demonstrate the Implementation of 4-Color Problem

Farhan Muhamed
Updated on 11-Jun-2025 18:42:06

753 Views

In this article, we will explain the 4 color problem to color a graph and implement the backtracking algorithm to solve it in C++. The 4 Color Problem The 4-color problem states that the maximum number of colors needed to color any planar graph (or a 2D map) is four, such that no two adjacent nodes have the same color. For example, suppose that you want to color a world map, such that no two countries sharing a border have the same color. According to this theorem, the maximum number of colors needed to do this is four. Now, ... Read More

C++ Program to Solve the Dominating Set Problem

Farhan Muhamed
Updated on 10-Jun-2025 17:59:20

449 Views

In this article, we will explain the dominating set problem and implement it's solution in C++. First of all, let's understand what a dominating set is. Dominating Set of a Graph A dominating set for a graph is a subset of the set of all the vertices. Every vertex that is not in the dominating set should be adjacent of at least one vertex in the dominating set. To understand this clearly, consider the following graph: In the above graph, the set of vertices {B, D} is one of the dominating sets, because: ... Read More

C++ Program to Generate a Random Subset by Coin Flipping

Farhan Muhamed
Updated on 10-Jun-2025 17:58:34

290 Views

The subsets of a set refers to all the possible combinations of choosing elements from the set. For example, if we have a set {1, 2}, the subsets are {}, {1}, {2}, and {1, 2}. In this article, we will learn how to generate a random subset for a set using coin flipping technique in C++. // Set of elements int arr[] = {1, 2, 3}; // Subsets of the above set {}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3} Coin Flipping Technique The coin flipping technique is a simple way ... Read More

C++ Program to Implement the Binary Counting Method to Generate Subsets of a Set

Farhan Muhamed
Updated on 09-Jun-2025 19:09:42

1K+ Views

The subsets of a set refers to all the possible combinations of choosing elements from the set. For example, if we have a set {1, 2}, the subsets are {}, {1}, {2}, and {1, 2}. In this article, we will learn how to generate subsets of a set using the Binary Counting Method in C++. // Set of elements int arr[] = {1, 2, 3}; // Subsets of the above set {}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3} Binary Counting Method The binary counting method is a technique used to generate ... Read More

C++ Program to Implement the Alexander Bogomolny’s UnOrdered Permutation Algorithm for Elements From 1 to N

Samual Sam
Updated on 30-Jul-2019 22:30:26

138 Views

This is a C++ program to implement the Alexander Bogomolny’s UnOrdered Permutation Algorithm for elements from 1 to NAlgorithmsBegin    function AlexanderBogomolny() to implement the Algorithms    Arguments:       Val[] = an array       N = number of elements taken as input.       K = level       Body of the function:       intialize l = -1       l = l+1       Val[k] = l       if (l == N)          Call function display(Val, N)       else       ... Read More

C++ Program to Find the Number of occurrences of a given Number using Binary Search approach

Ravi Ranjan
Updated on 20-Aug-2025 13:43:41

303 Views

In this article, our task is to find the number of occurrences of a given number using binary search. The binary search algorithm works on the divide-and-conquer principle as it keeps dividing the array in half before searching. To search for an element in an array using binary search, it should be sorted. In the sorted array, we find the middle element and compare it with the element that has to be searched, and based on the comparison, we either search in the left or right sub-array or return the middle element. Following are some example scenarios: Scenario ... Read More

Parameter Passing Techniques in C/C++

Samual Sam
Updated on 30-Jul-2019 22:30:26

6K+ Views

In C we can pass parameters in two different ways. These are call by value, and call by address, In C++, we can get another technique. This is called Call by reference. Let us see the effect of these, and how they work.First we will see call by value. In this technique, the parameters are copied to the function arguments. So if some modifications are done, that will update the copied value, not the actual value.Example#include using namespace std; void my_swap(int x, int y) {    int temp;    temp = x;    x = y;    y = ... Read More

Using range in switch case in C/C++

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

8K+ Views

In C or C++, we have used the switch-case statement. In the switch statement we pass some value, and using different cases, we can check the value. Here we will see that we can use ranges in the case statement.The syntax of using range in Case is like below −case low … highAfter writing case, we have to put lower value, then one space, then three dots, then another space, and the higher value.In the following program, we will see what will be the output for the range based case statement.Example#include main() {    int data[10] = { 5, ... Read More

Difference between “int main()” and “int main(void)” in C/C++?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

3K+ Views

Sometimes we see that there are two types of main function definition. The int main() and int main(void). So is there any difference?In C++, there is no difference. In C also both are correct. But the second one is technically better. It specifies that the function is not taking any argument. In C if some function is not specified with the arguments, then it can be called using no argument, or any number of arguments. Please check these two codes. (Remember these are in C not C++)Example#include void my_function() {    //some task } main(void) {    my_function(10, "Hello", "World"); ... Read More

What is long long in C/C++?

Samual Sam
Updated on 30-Jul-2019 22:30:26

8K+ Views

In some cases we use long long in C or C++. Here we will see what is basically long long is? The long long takes twice as much memory as long. In different systems, the allocated memory space differs. On Linux environment the long takes 64-bit (8-bytes) of space, and the long long takes 128-bits (16-bytes) of space. This is used when we want to deal with some large value of integers.We can test the size of different types using this simple program.Example#include using namespace std; main() {    int a;    long b;    long long c;    cout

Advertisements