C++ Program to Check the Connectivity of Directed Graph Using DFS

Ravi Ranjan
Updated on 30-May-2025 18:59:12

776 Views

To check if a directed graph is connected or not, we need to check if there exists a path between every pair of vertices. A directed graph (or digraph) is a graph where each edge has a direction, edges are in ordered pairs, and edges traverse from the source vertex (the tail) to the destination vertex (the head). In this article, we have a directed graph with five vertices and its respective adjacency matrix. Our task is to use Depth-first Search(DFS) to check the connectivity of the given graph. Example of Connected Graph In the figure given below, we have ... Read More

Check if a graph is strongly connected - Set 1 (Kosaraju using DFS) in C++

Ravi Ranjan
Updated on 30-May-2025 18:58:57

358 Views

To check a strongly connected graph using Kosaraju's algorithm, we need to understand the strongly connected graph and Kosaraju's algorithm. For a graph to be strongly connected, it should be a directed graph, and for any pair of vertices u and v in the directed graph, there exists a directed path from u to v and a directed path from v to u. In this article, we have a directed graph with five vertices. Our task is to use Kosaraju's algorithm to check if the given graph is strongly ... Read More

Java program to replace a character at a specific index

Aishwarya Naglot
Updated on 30-May-2025 18:47:21

4K+ Views

In this article, we'll learn how to replace a character at a specific index in a string. Strings in Java are sequences of characters enclosed in double-quotes (" "). We use strings to represent text in our programs. Problem Statement You are given a string, an index, and a character. Your task is to replace the character at the specified index in the string with the new character. Input string: Java Programming, Index: 6 Output: Java P%ogramming Different Approaches There are multiple ways to achieve this in Java. Below are two common approaches: Using substring() ... Read More

C++ Program to Implement AVL Tree

Aman Kumar
Updated on 30-May-2025 18:42:56

24K+ Views

In this article, we will demonstrate how to implement an AVL tree. An AVL tree is a self-balancing binary search tree in which the height difference between the left and right subtrees (balance factor) of any node cannot exceed one. AVL TREE Following are the points of an AVL tree − Tree rotation is a way to change the structure of an AVL tree without changing the order of the elements. It helps keep the tree balanced by moving one node up and one node down. Tree rotations are mainly used ... Read More

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

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

186 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

Exception Handling in C++ vs Java

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

726 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

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

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

How do you make a shallow copy of a list in Java?

Aishwarya Naglot
Updated on 30-May-2025 18:35:52

930 Views

In this article, we will learn how to make a shallow copy of a List in Java. What is the List in Java? List is a part of the Java collection framework. It stores elements sequentially and also allows us to store duplicate elements. It is an interface, not a class, so it cannot be instantiated directly. However, there are several classes that implement the List interface, such as ArrayList, LinkedList, and Vector. Shallow Copy of a List A shallow copy means it is a copy of the original list, but elements in the copied list are still referencing the ... Read More

How do you search for an element in an ArrayList in Java?

Aishwarya Naglot
Updated on 30-May-2025 18:29:25

7K+ Views

In this article, we will learn how to search for an element in an ArrayList in Java. ArrayList is an interface that extends another interface called the List interface. It provides a way to store elements and also provides resizable functionality. Let's take an example: Input: [1, 2, 3, 4, 5] Element to search: 3 Output: Element 3 found at index 2 Ways to Search for an Element in an ArrayList Below are the different approaches to searching for an element in an ArrayList: Using indexOf() method Using contains() method Using for loop Using Stream API ... Read More

Advertisements