Programming Articles - Page 2649 of 3363

C++ Program to Implement the Vizing’s Theorem

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

326 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

797 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

471 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

309 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

152 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

340 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

Java Program to use Soft Bevel Border in Swing

Daniol Thomas
Updated on 30-Jul-2019 22:30:26

277 Views

Here, we are creating soft beven border on JComboBox:JComboBox comboBox = new JComboBox(list);Now, set bevel border:comboBox.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));The following is an example to use soft bevel border in Swing:Exampleimport java.awt.Font; import java.awt.GridBagLayout; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.BevelBorder; import javax.swing.border.SoftBevelBorder; public class SwingDemo {    static final String list[] = { "One", "Two", "Three", "Four", "Five", "Six" };    public static void main(String[] args) {       JFrame window = new JFrame("ComboBox Example");       JPanel panel = new JPanel();       panel.setLayout(new GridBagLayout());       JComboBox comboBox = new JComboBox(list);       comboBox.setBorder(new ... 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

Write your own memcpy() in C

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

4K+ Views

Here we will see how to implement memcpy() function in C. The memcpy() function is used to copy a block of data from one location to another. The syntax of the memcpy() is like below −void * memcpy(void * dest, const void * srd, size_t num);To make our own memcpy, we have to typecast the given address to char*, then copy data from source to destination byte by byte. Just go through the following code to get better idea.Example#include #include void custom_memcpy(void *dest, void *src, size_t n) {    int i;    //cast src and dest to char*    char ... Read More

Advertisements