Found 7401 Articles for C++

Maximum width of a Binary Tree with null values

Satvik Watts
Updated on 01-Nov-2023 12:34:52

75 Views

A binary tree is defined as a tree data structure where each has at most two children. The width of a binary tree for a level is defined as the number of nodes between the rightmost and leftmost nodes of that level, including the NULL nodes that come in between. The maximum width of a binary tree is defined as the maximum of all the widths at each level of the binary tree. In this first approach, we represent the binary tree as an array representation of the Heap data structure. At each level, the width of that level will ... Read More

Longest subsegment of 1’s formed by changing at most k 0’s (Using Queue)

Satvik Watts
Updated on 01-Nov-2023 12:30:09

45 Views

In this article, we will find the longest subsegment of 1’s which can be formed by changing at most k 0’s to 1’s. We will be using queue data structure to solve this problem. In the approach discussed in this article, we will use a queue data structure to find the longest subarray containing only 1’s, which can be formed by changing at most k 0’s into 1’s. The queue data structure will be used to store the indices of 0 elements that have occurred previously. Whenever we encounter a new 0, we will check the size of the queue. ... Read More

FIFO Push Relabel Algorithm

Satvik Watts
Updated on 01-Nov-2023 12:15:11

78 Views

The FIFO Push Relabel algorithm is an algorithm that is used to solve the maximum flow problem. The maximum flow problem is a problem in graph theory in which we have to find the maximum amount of flow of resources or information that can be sent via an interconnected network of components, like pipes, wires, etc. With constraints on how much capacity a single component can handle. In other words, we have a directed graph on N nodes. We are given a source node and a sink node. We also have M edges in the graph, each edge has a ... Read More

Count of pair of nodes at even distance (Using BFS)

Satvik Watts
Updated on 01-Nov-2023 11:56:06

29 Views

In this article, we will find the number of the pair of nodes, which are at an even distance of each other in a graph. We will be using the breadth first search (BFS) approach to find the total count. In the approach discussed in this article, we will use a queue data structure which will contain pair of integers. The queue data structure will allow us to go through the graph using the breadth first search algorithm (BFS). We will pick a random node and apply the breadth first search from that node. We will use two variables to ... Read More

Minimize count of alternating subsequences to divide a given Binary String with subsequence number

Thanweera Nourin A V
Updated on 31-Oct-2023 16:17:51

35 Views

The aim of this article is to implement a program Minimize count of alternating subsequences to divide a given binary string with subsequence number. Here, you are provided with a binary string as part of the issue. In order to prevent any subsequence from including adjacent zeros and ones, we must reduce the number of subsequences and output the subsequence number that corresponds to each string element. A subsequence represents a sequence which can be created by taking the supplied sequence and eliminating zero or more members while maintaining the initial position of the elements that remain. Input Let ... Read More

C++ Program to Check if all rows of a matrix are circular rotations of each other

Thanweera Nourin A V
Updated on 30-Oct-2023 16:46:06

39 Views

The aim of this article is to implement a program C++ program to check if all rows of a matrix are circular rotations of each other. Here is a small glimpse on what a matrix exactly is. The rectangular array of symbols or numbers organized in rows and columns is known as a matrix. A matrix can be of many distinct types, including row, column, horizontal, vertical, square, diagonal, identity, equal, and singular. Addition, subtraction, as well as multiplication are the three fundamental matrix operations. The goal is to determine whether all rows of a matrix of size n*n ... Read More

Minimize given Number by swapping adjacent digits with odd difference

Thanweera Nourin A V
Updated on 30-Oct-2023 15:57:27

31 Views

The aim of this article is to implement a program to minimize a given number by swapping adjacent digits with odd differences. The goal is to determine the lowest amount that can be created from a string of size N indicating an integer using only the characters '1', '2', and '3' by exchanging adjacent characters any number of times. As we all know, a string is a group of characters that ends with the null character "0" in C programming. Characters from the C String are kept in a character array. A C string differs from a character array in ... Read More

Check if given String is K-periodic for all K in range [1, N]

Thanweera Nourin A V
Updated on 30-Oct-2023 15:14:19

62 Views

The aim of this article is to implement a program to check if a given String is K-periodic for all K in range [1, N]. The aim is to determine whether the supplied string is K-periodic provided the string s and the integer K. If a string repeats the sub-string str[0... k-1], it is said to be k-periodic; for example, the string "ababab" is 2 periods long. Print Yes if the supplied string is k-periodic; otherwise, print No. If a character string can be created by concatenating at least one repeats from another string of length k, it is said ... Read More

C++ Program to Find Lexicographically minimum string rotation

Thanweera Nourin A V
Updated on 30-Oct-2023 15:54:20

53 Views

The aim of this article is to implement a C++ Program to Find Lexicographically minimum string rotation. Coming on to the definition of string, a string is a group of characters that ends with the null character "0" in C programming. Characters from the C String are kept in a character array. A C string differs from a character array in that it ends with the distinctive character "\0." Finding the rotation of a string that has the lowest lexicographical order among all feasible rotations is known to be the lexicographically minimal string rotation as well as lexicographically smallest circular ... Read More

Check if a path exists for a cell valued 1 to reach the bottom right corner of a Matrix before any cell valued 2

Divya Sahni
Updated on 25-Oct-2023 13:28:50

77 Views

Problems involving grids and matrices are mostly solved using either BFS or DFS traversal algorithms. Taking a look into the first one, Breadth First Traversal − BFS or Breadth First Traversal is an algorithm for searching a tree or a graph data structure. It starts at the root node and explores all the nodes at the present level before moving on to the next level. Algorithm procedure BFS(G, root) is let Q be a queue label root as explored Q.enqueue(root) while Q is not empty do ... Read More

Advertisements