Found 7346 Articles for C++

Add and Remove Vertex in Adjacency Matrix Representation of Graph

Ayush Singh
Updated on 13-Jul-2023 19:04:18

427 Views

Including a vertex within the contagiousness network representation of a chart means expanding the measure of the network by one push and one column. The unused push and column speak to the associations of the recently included vertex with the existing vertices. Additionally, expelling a vertex requires evacuating its comparing push and column from the contagiousness lattice, subsequently altering the measure of the network in like manner. Including a vertex includes adding a push and column with beginning values of 0, whereas evacuating a vertex includes erasing the comparing push and column, viably decreasing the measure of the lattice. Methods ... Read More

Add and Remove Edge in Adjacency List Representation of Graph

Ayush Singh
Updated on 13-Jul-2023 18:51:28

713 Views

Adjacency lists effectively store graph relationships. Graph algorithms and operations use it. Adding and deleting edges can dynamically change the connections between vertices. Graph modification, connection analysis, and evolution need this procedure.Adding and deleting edges link and detach vertices, respectively. The adjacency list representation commonly performs these actions by altering the vertices' adjacency lists. Using a vector of vectors, sets, or maps of sets may change the implementation.New edges create pathways and linkages in the graph. However, removing edges breaks connections, changing graph structure and dynamics. These procedures are essential for graph adjacency list integrity and evolution. Methods Used ... Read More

Number of isosceles triangles in a binary tree

Riya Kumari
Updated on 12-Jul-2023 12:42:37

84 Views

A binary tree is a data structure in which each node can have two children (at most). These children are known as left and right child respectively. Suppose we are given a parent array representation using which you have to a create a binary tree. The binary tree may have several isosceles triangles. We have to find the total number of possible isosceles triangles in that binary tree. In this article, we will explore several techniques in C++ to solve this problem. Understanding the Problem You are given a parent array. You have to represent it in the form ... Read More

Number of full binary trees such that each node is product of its children

Riya Kumari
Updated on 12-Jul-2023 12:41:11

68 Views

A full binary tree is a special type of binary tree in which all the parent nodes either have two or no children. In data structures, these kinds of trees are considered as balanced and organized representation. Full binary trees may have a unique feature where each of the parent node is a product of its children. In this article, we will discuss about different methods for counting the number of full binary trees such that each node is product of its children using C++. Input Output Scenarios For example, in the array {1, 5, 3, 4}, we have ... Read More

Number of jumps required for a thief to cross walls

Riya Kumari
Updated on 12-Jul-2023 12:39:56

171 Views

Imagine a prisoner (or thief) wants to escape from a jail. In order to do so, he needs to cross N number of walls of varying lengths. He can climb X feet for each jump. But, since the walls are slippery, he falls down by Y feet after each jump. So, we need to calculate number of jumps required to cross all the walls. In this article, we will explore different C++ techniques to find the number of jumps required to escape the jail. Input Output Scenarios We have different heights of the N walls in the form of ... Read More

Number of jumps required of given length to reach a point of (d, 0) from origin in 2D plane

Riya Kumari
Updated on 12-Jul-2023 12:35:08

56 Views

In this article, we will discuss the possible solution of an exciting analytical question of how many jumps are required to reach a point (d, 0) from the origin in a 2D plane where you have been specified fixed length of jumps. We will use the fixed length of jumps and the target coordinates to find the minimum number of jumps required. Input Output Scenarios Suppose jump length can be a or b while the target point is (d, 0). Then, the given output is the minimum number of jumps required to reach target. Input: a = 7, b ... Read More

Number of integral solutions for equation x = b*(sumofdigits(x) ^ a)+c

Riya Kumari
Updated on 12-Jul-2023 12:33:41

168 Views

Suppose you are given three integral numbers a, b and c and you have an equation x = b* (sumofdigits(x)^a) +c. Here, sumofdigits(x) is the total sum of all the digits in x. To find all the possible integral solutions which satisfy the equation, we will explore various approaches in C++. Input Output Scenarios Given below are values of a, b and c. Different integral solution which satisfies the equation x = b* (sumofdigits(x)^a) +c is given as output. Input: a = 2, b = 2, c = -3 Output: 125, 447, 575 In the above scenario the ... Read More

Number of horizontal or vertical line segments to connect 3 points

Riya Kumari
Updated on 12-Jul-2023 12:31:43

149 Views

Suppose you are given three different points (or coordinates) and you want to find out number of horizontal or vertical line segments which can be made by connecting those three points. Such line segments together are also known as polyline. You need concepts of computational geometry in order to solve this problem. In this article, we will discuss various approaches in C++ to tackle this problem. Input Output Scenarios Suppose c1, c2 and c3 are coordinates of 3 points in a cartesian plane. The number of horizontal or vertical line segments to connect these 3 points will be given as ... Read More

Number of handshakes such that a person shakes hands only once

Riya Kumari
Updated on 12-Jul-2023 12:29:47

124 Views

Suppose you are in a social gathering. Can you calculate how many handshakes you can do if you were to shakes only once? This question might sound intriguing to you. This can be solved mathematically by using permutations and combinations. However, the mathematical operation might be time-consuming. In this article, we will discuss how to solve such problem using C++. We will explore different approaches which ranges from mathematical formulas, to recursion, and other combinatorial techniques. Input Output Scenarios Suppose you have N number of people in a gathering. You want to calculate the number of handshakes possible ... Read More

Number of elements greater than K in the range L to R using Fenwick Tree (offline queries)

Riya Kumari
Updated on 12-Jul-2023 12:28:27

220 Views

In the field of computer science, we have to process large datasets which includes query selection and update operations. It is a challenging task for the developers to execute these operations in real-time with less time complexity. Using Fenwick tree is an efficient way to tackle these range-based query problems. Fenwick Tree is a data structure which updates elements and calculates the prefix sums of the numbers in a table efficiently. It is also known as Binary Indexed Tree. In this article, we will discuss how to use Fenwick Trees for finding the number of elements greater ... Read More

Advertisements