Server Side Programming Articles - Page 2258 of 2650

C++ Program to Check if any Graph is Possible to be Constructed for a Given Degree Sequence

Farhan Muhamed
Updated on 12-Jun-2025 17:23:27

181 Views

We are given an array of integers containing the degree of each vertex in a graph. Our task is to check if it is possible to construct a graph with the given degree sequence. Example: int degrees[] = {3, 2, 2, 0} Output: Not Possible Explanation: The first vertex has degree 3, which means it must be connected to three other vertices. But the last vertex has degree 0, meaning it cannot be connected to any other vertex. Hence, it is impossible to construct a graph with this degree sequence. To implement this in C++, we can ... Read More

C++ Program to print the diamond shape

Farhan Muhamed
Updated on 12-Jun-2025 17:26:36

610 Views

In this article, we will learn how to print a diamond shape with 2n rows and n columns for a given size n using C++. For example, if n = 4, the diamond shape will look like this: Algorithm to Print Diamond Shape To print the diamond shape, we can follow these steps: Take an integer input n from the user. To print upper half of the diamond, use a loop that runs from i = 1 to i

C++ Program to Implement the Vizing’s Theorem

Farhan Muhamed
Updated on 16-Jun-2025 18:14:31

296 Views

In this article, we will explain the Vizing's theorem and implement it in C++ to color a graph using the Greedy Coloring Algorithm. What is Vizing's Theorem? Vizing's theorem states that for any graph, the minimum number of colors needed to color the edges (chromatic index) is either equal to the maximum degree G of the graph or one more than maximum degree G + 1. The degree of a vertex is the number of edges connected to it. The maximum degree G refer to highest degree for any vertex in the graph. It is ... Read More

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

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

757 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

450 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

291 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

304 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

Use of bool in C

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

2K+ Views

In C there is no predefined datatype as bool. We can create bool using enum. One enum will be created as bool, then put the false, and true as the element of the enum. The false will be at the first position, so it will hold 0, and true will be at second position, so it will get value 1. Now we can use this as datatype.Example#include typedef enum {    F, T } boolean; main() {    boolean my_bool1, my_bool2;    my_bool1 = F;    if(my_bool1 == F) {       printf("my_bool1 is false");    } else { ... Read More

Advertisements