Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
C++ Articles
Found 5,961 articles
Binary Search Tree to Greater Sum Tree in C++
In this article, we are given a binary search tree. Our task is to transform the given BST to a Greater Sum tree. A Greater Sum Tree with respect to the given BST is a tree where each node's value is replaced by the sum of all values greater than that node's value in the original BST. Below is an example scenarios to convert the given BST to a Greater Sum Tree: Example Scenario Input: BST inorder traversal= {0, 1, 2, 3, 4, 5, 6, 7, 8} Output: Greater Sum Tree = {36, 35, 33, 30, 26, 21, 15, ...
Read MoreCompiling a C++ program with GCC
To compile a C++ program with GCC, we need to download GCC or install the g++ compiler on our system. Otherwise, you will not be able to compile C++ code using GCC. What is GCC? The GCC is a tool chain that compiles code. It stands for GNU Compiler Collection, which was developed by the GNU project. The GCC supports various programming languages such as C, C++, Go, etc. Specific to the C++ language, the GCC provides the g++ compiler, which is developed or designed to compile the C++ source code into executable programs. Note: When the C++ program compiles ...
Read More132 Pattern in C++
The 132 pattern indicates that, as the digits in "132" in any given value, the middle element should be greater than the last and first elements. Similarly, the last element must be greater than the first element. To check 132 patterns in C++, we will use the Array data structure. We have given an array nums[] of size S. Our task is to check whether the array elements at indices i, j, and k are such that i < j < k and nums[j] < nums[k] and nums[i] < nums[k]. If any three elements at positions i < j < k ...
Read MoreHow can we read Python dictionary using C++?
A dictionary in Python is a collection of key-value pairs where each key must be unique. The lists, which are indexed by numbers, are accessed using keys that can be immutable types, strings, numbers, or tuples. Lists cannot be used as keys because they can be modified. Dictionaries are created using {}, and key-value pairs are added with commas. We can store, retrieve, and delete values using their keys. Using the list() returns all keys, while sorting them. To check if a key exists, we can use the in keyword. If a key is replaced, then its old value is replaced. ...
Read MoreValidate Binary Search Tree in Python
A binary search tree is a special binary tree in which for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. In this article, we will discuss how to validate whether a given binary tree is a valid binary search tree (BST) in Python. Validate Binary Search Tree Algorithm to Validate Binary Search Tree Python Program to Validate Binary Search Tree Validate Binary Search Tree Given a root node of ...
Read MoreVerify Preorder Sequence in Binary Search Tree in C++
In this article will explain a popular coding problem that involves verifying whether a given preorder sequence can represent a valid binary search tree (BST). We will discuss the problem statement, provide examples, algorithm to solve, and a C++ implementation of the solution. Problem Statement Algorithm to Solve Problem C++ Program Time and Space Complexity Verify Preorder Sequence in Binary Search Tree Given an array containing the preorder traversal of a binary tree, we need to verify whether it ...
Read MoreAlignof operator in C++
C++ alignof() Operator The alignof operator is the operator that returns the memory alignment for a given variable type. This alignment tells how the data is arranged and accessed in memory. It returns the value in bytes and is the part of the header file in C++. which is mainly used for low-level programming like memory management or hardware requirements. Syntax Here is the following syntax of alignof operator, which returns memory alignment required for a given data type in bytes: alignof(data_type) Example Demonstrating Usage of alignof() Operator Here is the following example code of using alignof() operator ...
Read MoreC++ Programs To Create Pyramid and Pattern
In this article, we will show you how to write C++ programs to create different pyramids and patterns. You can create many kinds of patterns using stars, numbers, and alphabets. Below is the list of patterns we will cover in this article- Simple Pyramid Pattern in C++ Flipped Simple Pyramid Pattern in C++ Inverted Pyramid Pattern in C++ Flipped Inverted Pyramid Pattern in C++ Triangle Pattern in C++ Inverted Triangle Pattern in C++ ...
Read MoreWrite a program in C++ to find the length of the largest subarray with zero sum
We are given an array of N integers and the task is to find the length of the longest subarray whose elements sum up to zero. A subarray is a continuous sequence of elements within the array. If no such subarray exists, return 0. Let's look at a few example scenarios to understand the problem better- Scenario 1- Input: N = 7 arr = {1, 2, -3, 3, -1, 2, -2} Output: 5 Explanation: The subarray {2, -3, 3, -1, 2} has a sum of 0 and its length is 5, which is the longest such ...
Read MoreWrite a program in C++ to find the maximum and second maximum in a given unsorted array of integers
We are given an array of unsorted integers of size N. The task is to find the distinct maximum and second maximum elements which are present in the array. The array may contain duplicate elements also, so we have to find only distinct elements. If there is no second maximum, we will return -1 for the second maximum. Let's look at some example scenarios to understand the problem clearly - Scenario 1- Input: N = 5, A[] = {2, 2, 1, 3, 4} Output: 4 and 3 Explanation: From the given array, we can see that '4' is ...
Read More