C++ Program to Implement the Vizing’s Theorem

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

287 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 Check Cycle in a Graph using Topological Sort

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

467 Views

In this problem, we are given adjacency lists of a directed graph and we need to check if there is a cycle in the graph using topological sort. If a cycle exists, it is not possible to perform a topological sort. Example: // Input Graph ( as adjacency list ) 0 -> 1 1 -> 2 1 -> 3 2 -> 0 Output: Cycle exists Explanation: The graph has a cycle (0 -> 1 -> 2 -> 0). To solve this problem, we can use Khan's Algorithm, which is a BFS based topological sorting algorithm. To ... Read More

C++ program to Implement Threaded Binary Tree

Farhan Muhamed
Updated on 16-Jun-2025 18:10:10

4K+ Views

Threaded binary tree is a binary tree that provides the facility to traverse the tree in a particular order. In this article, we will learn all about threaded binary trees, their types, and how to implement them in C++. What is a Threaded Binary Tree? A threaded binary tree is a type of binary tree in which NULL pointers are replaced with pointers to the in-order predecessor and successor nodes. This treading will help in faster traversal of the tree without using a stack or recursion. The image below shows a threaded binary tree. There are two types ... Read More

C++ Program to Find All Forward Edges in a Graph

Farhan Muhamed
Updated on 16-Jun-2025 18:09:57

323 Views

In this article, we will learn how to write an algorithm an C++ code to find all forward edges in a directed graph. What is a Forward Edge? A forward edge is an edge in a directed graph that points from a node to one of it's descendants in the depth-first search (DFS) tree. To understand this concept better, consider the image of a directed graph below: In the above graph, the edge from node 2 to node 5 is a forward edge because to reach node 5 in DFS traversal, we need to move through node ... Read More

C++ Program to Check if a Given Set of Three Points Lie on a Single Line or Not

Farhan Muhamed
Updated on 16-Jun-2025 18:09:45

826 Views

In this problem, you are given three coordinates in a 2D plane, and you need to check if these three points are collinear, meaning they lie on a single straight line. There are two approaches to solve this problem. In this article, we will explain both the approaches with example code in C++. // Input: Coordinates of three points points = {{2, 3}, {4, 6}, {6, 9}}; // Output The points are collinear. Check if Three Points are Collinear If three points lie on a single line, then the points are called as collinear points. ... Read More

C++ Program to Show the Duality Transformation of Line and Point

Farhan Muhamed
Updated on 16-Jun-2025 18:09:29

246 Views

The duality transformation is concept in computational geometry that maps coordinate points to lines and lines to coordinate points. In this article, we will learn all about the duality transformation of lines and points, and implement C++ code to show this transformation. What is Duality Transformation? The duality transformation is a process that converts 2 dimensional lines and coordinates into dual plane. In this transformation, a point in the 2D plane can be represented as a line in the dual space, and a line in the 2D plane can be represented as a point in the dual space. This ... Read More

C++ Program to Search for an Element in a Binary Search Tree

Ravi Ranjan
Updated on 16-Jun-2025 17:41:41

2K+ Views

A Binary Search Tree (BST) is a type of binary tree such that the left subtree has elements smaller than the root element and the right subtree has elements greater than the root element. In this article, our task is to search for an element in the given Binary Search Tree. Characteristics of Binary Search Tree Here are some of the characteristics of the BST: The left subtree of the BST has elements less than the root element. The right subtree of the BST has elements greater than the root ... Read More

How do I define string constants in C++?

Revathi Satya Kondra
Updated on 16-Jun-2025 17:34:21

15K+ Views

In C++, a string constant also called a string literal is a fixed sequence of characters enclosed in double quotes (" "). For example: "This is a string" and it is used to read-only memory, and its value cannot be changed during the program. Defining C++ Strings ConstantsYou can define your own named string constants by using: String Literals The const keyword The #define preprocessor directive The constexpr keyword(in modern C++) Let us understand each type of String Constant in C++ by ... Read More

enum vs. const vs. #define in C/C++

Akansha Kumari
Updated on 16-Jun-2025 17:23:14

726 Views

The #define, const, and Enum are all used for declaring constant values, but their behaviours and use cases differ. The #define is a preprocessor directive, which is used to define a macro (it is a string or name, in which you can assign a constant value), whereas const is a keyword with which you can declare a variable with a constant value. Whereas, an Enum is a special user-defined data type that represents a group of constants. In the following article, we will learn about all three in detail. Enumeration (Enum) An Enumeration (or Enum) is a user-defined data type ... Read More

What is the difference between iostream and iostream.h in C++?

Tapas Kumar Ghosh
Updated on 16-Jun-2025 17:07:37

1K+ Views

Both and are the header files of C++ language. The .h extension was common in older, non-standard implementations like Turbo C++. The  has been deprecated in modern C++ compilers and the  became part of the C++ standard starting from the 1998 ANSI/ISO standard. The Header File The iostream.h header file was part of the early 1990s I/O streams library, developed at AT&T for use with early C++. At that time, C++ was not yet standardized. The purpose of this header file is used to perform the input-output operations. Example Following is an example of iostream.h as per ... Read More

Advertisements