Found 33676 Articles for Programming

C++ Program to find out the maximum amount of score that can be decreased from a graph

Arnab Chakraborty
Updated on 02-Mar-2022 06:59:39

327 Views

Suppose, there is a weighted, undirected graph that has n vertices and m edges. The score of the graph is defined as the addition of all the edges weights in the graph. The edge weights can be negative, and if they are removed the score of the graph increases. What we have to do, we have to make the score of the graph minimum by removing the edges from the graph while keeping the graph connected. We have to find out the maximum amount of score that can be decreased.The graph is given in an array 'edges', where each element ... Read More

C++ Program to find out the number of cells to block in a grid to create a path

Arnab Chakraborty
Updated on 02-Mar-2022 06:54:00

413 Views

Suppose, there is a grid of dimensions h * w. There is a robot in cell position (0, 0) and it has to go to the position (h - 1, w - 1). There are two types of cells in a grid, blocked and unblocked. The robot can pass through the unblocked cells but cannot pass through the blocked cells. The robot can go in four directions; it can go left, right, up, and down. But the robot may go in any direction from a cell to another (ignoring the previous cell it was in), so we have to make ... Read More

C++ to perform certain operations on a sequence

Arnab Chakraborty
Updated on 02-Mar-2022 06:47:04

423 Views

Suppose, we are given an empty sequence and n queries that we have to process. The queries are given in the array queries and they are in the format {query, data}. The queries can be of the three following types−query = 1: Add the supplied data to the end of the sequence.query = 2: Print the element at the beginning of the sequence. After that delete the element.query = 3: Sort the sequence in ascending order.Note that, query types 2 and 3 always have data = 0.So, if the input is like n = 9, queries = {{1, 5}, {1, ... Read More

C++ Program to find out the moves to read a point from another point in a 2D plane

Arnab Chakraborty
Updated on 02-Mar-2022 12:40:34

321 Views

Suppose, there are two points in a 2D plane a and b that have the coordinates (x1, y1) and (x2, y2) respectively. Currently, we are at point 'a' and we can move at a distance of 1 either vertically or horizontally. We move to point b from point a, then get back to point a, and we go to point b again. It is not allowed to move through the same points more than once except the points a and b. We have to find out the moves we will make in this whole trip, and output it. If we ... Read More

Generate a Pseudo Vandermonde matrix of the Laguerre polynomial and x, y, z complex array of points in Python

AmitDiwan
Updated on 02-Mar-2022 07:08:28

157 Views

To generate a pseudo Vandermonde matrix of the Laguerre polynomial with x, y, z sample points, use the laguerre.lagvander3d() in Python Numpy. The parameter, x, y, z returns an Array of points. The dtype is converted to float64 or complex128 depending on whether any of the elements are complex. If x is scalar it is converted to a 1-D array. The parameter, deg is a list of maximum degrees of the form [x_deg, y_deg, z_deg].StepsAt first, import the required library −import numpy as np from numpy.polynomial import laguerre as LCreate arrays of point coordinates, all of the same shape using ... Read More

Evaluate a Legendre series at points x and the shape of the coefficient array extended for each dimension of x in Python

AmitDiwan
Updated on 02-Mar-2022 06:37:10

130 Views

To evaluate a Legendre series at points x, use the polynomial.legendre.legval() method in Python Numpy. The 1st parameter is x. If x is a list or tuple, it is converted to an ndarray, otherwise it is left unchanged and treated as a scalar. In either case, x or its elements must support addition and multiplication with themselves and with the elements of c.The 2nd parameter, C, an array of coefficients ordered so that the coefficients for terms of degree n are contained in c[n]. If c is multidimensional the remaining indices enumerate multiple polynomials. In the two dimensional case the ... Read More

Evaluate a Legendre series at points x when coefficients are multi-dimensional in Python

AmitDiwan
Updated on 02-Mar-2022 06:35:26

133 Views

To evaluate a Legendre series at points x, use the polynomial.legendre.legval() method in Python Numpy. The 1st parameter is x. If x is a list or tuple, it is converted to an ndarray, otherwise it is left unchanged and treated as a scalar. In either case, x or its elements must support addition and multiplication with themselves and with the elements of c.The 2nd parameter, C, an array of coefficients ordered so that the coefficients for terms of degree n are contained in c[n]. If c is multidimensional the remaining indices enumerate multiple polynomials. In the two dimensional case the ... Read More

Differentiate a Hermite series and set the derivatives in Python

AmitDiwan
Updated on 02-Mar-2022 06:33:23

157 Views

To differentiate a Hermite series, use the hermite.hermder() method in Python. The 1st parameter, c is an array of Hermite series coefficients. If c is multidimensional the different axis correspond to different variables with the degree in each axis given by the corresponding index. The 2nd parameter, m is the number of derivatives taken, must be non-negative. (Default: 1)The 3rd parameter, scl is a scalar. Each differentiation is multiplied by scl. The end result is multiplication by scl**m. This is for use in a linear change of variable. (Default: 1). The 4th parameter, axis is an Axis over which the ... Read More

C++ Program to find out the maximum number of moves to reach a unblocked cell to another unblocked cell in a grid

Arnab Chakraborty
Updated on 02-Mar-2022 06:37:29

320 Views

Suppose, we are given a grid of dimensions h * w that contains two types of cells, blocked and unblocked. Blocked cells mean that the cells aren't accessible and unblocked means that the cells are accessible. We represent the grid in a 2D array where the blocked cells are given as '#' and the unblocked cells are given as '.'. Now, we have to reach from an unblocked cell to another unblocked cell in the grid. We can perform only two moves, we can either go vertical or we can go horizontal. We can't move diagonally. We have to keep ... Read More

Differentiate a Hermite series with multidimensional coefficients in Python

AmitDiwan
Updated on 02-Mar-2022 06:31:48

163 Views

To differentiate a Hermite series, use the hermite.hermder() method in Python. The 1st parameter, c is an array of Hermite series coefficients. If c is multidimensional the different axis correspond to different variables with the degree in each axis given by the corresponding index. The 2nd parameter, m is the number of derivatives taken, must be non-negative. (Default: 1)The 3rd parameter, scl is a scalar. Each differentiation is multiplied by scl. The end result is multiplication by scl**m. This is for use in a linear change of variable. (Default: 1). The 4th parameter, axis is an Axis over which the ... Read More

Advertisements