Found 7197 Articles for C++

C++ Program to Implement Network_Flow Problem

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

602 Views

This is a C++ Program to implement Network_Flow problem using Ford Fulkerson algorithm.Algorithms:Begin    function bfs() returns true if there is path from source s to sink t in    the residual graph which indicates additional possible flow in the graph. End Begin    function fordfulkarson() return maximum flow in given graph:    A) initiate flow as 0.    B) If there is an augmenting path from source to sink, add the path to flow.    C) Return flow. EndExample Code#include #include #include #include #define n 7 using namespace std; bool bfs(int g[n][n], int s, int ... Read More

C++ Program to Perform Operations in a BST

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

3K+ Views

         A Binary Search Tree is a sorted binary tree in which all the nodes will have following properties−The right sub-tree of a node has a key greater than to its parent node's key.The left sub-tree of a node has a key lesser than to its parent node's key.All key values are distinct.Each node cannot have more than two children.Class Descriptions:Begin    class BST to declare following functions:       search() = To search an item in BST.       initialize temp = root;       while(temp != NULL)          Increase ... Read More

C++ Program to Find Maximum Number of Edge Disjoint Paths

Aman Kumar
Updated on 30-May-2025 18:41:09

182 Views

According to the problem statement, we have a directed graph and two vertices that are source s and destination/target t. Our task is to determine the maximum number of edge-disjoint paths that can be found from vertex s to vertex t. If two paths do not share any edge, then it is known as an edge-disjoint. A directed graph is a digraph where edges have a specific direction. They point from one vertex to another. There can be a maximum two-edge disjoint path from source 0 to destination 7 in the above graph. ... Read More

C++ Program to Perform Greedy Coloring

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

834 Views

Here is a C++ Program to Perform Greedy ColoringAlgorithm:Begin    Take the number of vertices and edges as input.    Create function greedyColoring() to assign color to vertices:    A) Assign the first color to first vertex.    B) Initialize the remaining vertices.    C) Declare a temporary array to store the available colors.    D) Assign color to the remaining vertices.    Print the solution. EndExample Code#include #include using namespace std; int n,e,i,j; vector g; vector col; bool visit[1001]; void greedyColoring() {    col[0] = 0;    for (i=1;i

C++ Program to Implement Dijkstra’s Algorithm Using Set

Nancy Den
Updated on 30-Jul-2019 22:30:25

632 Views

This is a C++ Program to Implement Dijkstra’s Algorithm using Set. Here we need to have two sets. We generate a shortest path tree with given source node as root. One set contains vertices included in shortest path tree and other set includes vertices not yet included in shortest path tree. At every step, we find a vertex which is in the other set (set of not yet included) and has minimum distance from source.Algorithm:Begin    function dijkstra() to find minimum distance:    1) Create a set Set that keeps track of vertices included in shortest    path tree, Initially, ... Read More

Exception Handling in C++ vs Java

Aman Kumar
Updated on 30-May-2025 18:40:08

722 Views

In both languages, exception handling is used to identify errors using the try, catch, and throw keywords. Exception handling is a programming mechanism that works with errors and unexpected events that occur during program execution. Exception Handling in C++ C++ provides an inbuilt feature for handling exceptions using try and catch block. It is an exception-handling mechanism; the code that has an exception is placed inside the try block, and the code that handles the exception is placed inside the catch block. Visit here to learn more about C++ Exception. Syntax Following is the syntax of C++ Exceptions: try { ... Read More

Set position with seekg() in C++ language file handling

Aman Kumar
Updated on 30-May-2025 18:39:14

4K+ Views

The setg() function sets the position of the file pointer in the file. C++ seekg() Function The seekg() is a function in the iostream library that allows us to seek an arbitrary position in a file. It is mainly used to set the position of the next character to be extracted from the input stream from a given file in C++ file handling. Syntax There are two types of syntax of seekg() function: istream&seekg(streampos position); Or, istream&seekg(streamoff offset, ios_base::seekdir dir); Parameters Following is the parameter of the seekg(): position: It is the new ... Read More

C++ Program to Implement Splay Tree

Aman Kumar
Updated on 30-May-2025 18:39:36

3K+ Views

Splay Tree Splay tree is a self-balanced binary searched tree. The idea of implementing the splay tree is to bring the most recently inserted element to the root of the tree by performing a sequence of tree rotations, called splaying. Following are the basic operation on AVL: Insertion Searching Deletion Rotation: There are two types of rotation in splay tree (zig rotation and zag rotation). Let's see the code snippet of the above operation: Insertion Efficiently inserts a new key into the ... Read More

C++ Program to Implement self Balancing Binary Search Tree

Aman Kumar
Updated on 29-May-2025 15:44:52

2K+ Views

Self Balancing Binary Search tree A self-balancing binary search tree (BST) is a height-balanced binary search tree that automatically keeps its height (the maximum number of levels below the root) as small as possible when insertion and deletion operations are performed on the tree. In the self-balancing binary search tree, the height is maintained in the order of O(logn), so that all operations take O(logn) time on average. Common examples of self-balancing binary search trees are: AVL Tree RED Black Tree Splay Tree AVL Tree An ... Read More

C++ Program to Implement Randomized Binary Search Tree

Aman Kumar
Updated on 29-May-2025 15:45:27

713 Views

A Randomized Binary Search Tree (RBST) is a variation of a Binary Search Tree (BST) that contains randomization to maintain balance and improve efficiency. One common implementation of an RBST is a Treap, which combines BST properties with heap properties. Why We Use Random Binary Tree Random binary trees are used for analyzing the average-case complexity of data structure based on the binary trees. Features of RBST Following are the features of the randomized binary tree: BST Properties: The left subtree contains smaller value, right subtree contains larger value. Randomization: ... Read More

Advertisements