C++ Program to Implement AVL Tree

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

23K+ 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

Find Maximum Number of Edge Disjoint Paths in C++

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

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

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++ 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

Make a Shallow Copy of a List in Java

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

922 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

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

Turn ArrayList into a Set in Java

Aishwarya Naglot
Updated on 30-May-2025 18:10:34

11K+ Views

In this article, let's learn how to convert an ArrayList into a Set in Java. ArrayList is a collection that allows us to store duplicates, whereas Set is a collection that does not allow duplicates. So, when we convert an ArrayList to a Set, all the duplicate elements will be removed. If someone tries to add duplicate elements to a Set, it will not throw an error but will simply ignore the duplicate elements. Let's take an example: Input: [1, 2, 3, 4, 5, 5, 6] Output: [1, 2, 3, 4, 5, 6] Ways to Convert an ArrayList to ... Read More

Check If Input is Numeric in C++

Nishu Kumari
Updated on 30-May-2025 18:07:17

6K+ Views

Numeric input means a value that contains only digits from 0 to 9, without any letters or special characters. In this article, we'll show you how to write a C++ program to check whether the input is numeric. Let's understand this with a few examples: //Example 1: Input: 12345 Output: Valid numeric input //Example 2: Input: 12a5 Output: Not a numeric input We will cover two common ways to check if the input is numeric or not in C++. Using std::getline with std::isdigit Check Using stringstream to Parse ... Read More

Find the Size of an Int in C/C++

Nishu Kumari
Updated on 30-May-2025 18:05:34

8K+ Views

In C and C++, arrays can store multiple values of the same data type. This problem is about finding how many elements are present in a statically declared int[] array (not pointers or dynamically allocated arrays). We'll learn how to find the size of an int[] in both C and C++. Let's understand this with an example: //Example 1 input: int numbers[] = {10, 20, 30, 40, 50}; This array has 5 elements. Output: Number of elements: 5 //Example 2: Input: int values[] = {1, 2, 3}; This array has 3 elements. Output: Number of elements: 3 ... Read More

Advertisements