Found 33676 Articles for Programming

Making a Palindrome pair in an array of words (or strings) in C++

Prateek Jangid
Updated on 07-Mar-2022 07:45:56

558 Views

"Madam" or "racecar" are two words that read the same backward as forwards, called palindromes.If we are given a collection or list of strings, we have to write a C++ code to find out if that can join any two strings in the list together to form a palindrome or not. If any such pair of strings exist in the given list, we have to print "Yes, " else we have to print "No."In this tutorial, input will be an array of strings, and output will be a string value accordingly, for exampleInputlist[] = {"flat", "tea", "chair", "ptalf", "tea"}OutputYesThere is ... Read More

How does the pandas series.expanding() method work?

Gireesha Devara
Updated on 07-Mar-2022 07:43:15

2K+ Views

The series.expanding() method is one of the window methods of pandas and it Provides expanding transformations. And it returns a window subclassed for the particular operation.The parameters for this method are min_periods, center, axis, and method. The default value for the min_periods is 1 and it also takes an integer value. The center parameter takes a boolean value and the default one is False. In the same way, the default value for the axis parameter is 0, and for the method is ‘single’.Example 1In this following example, the series.expanding() method calculated the cumulative sum of the entire series object# importing ... Read More

How does the pandas series.ffill() method work?

Gireesha Devara
Updated on 07-Mar-2022 07:36:09

2K+ Views

The pandas series.ffill() method works equal to the series.fillna() with “method = ffill” function or we can say that the series.ffill() is a synonym for the forward fill method.The series.ffill() method replaces the Nan or NA values in the given series object using the forward fill method. The parameters for this method are inplace, axis, limit, and downcast.It does not have parameters like value and method. Because it takes the series element as a replacement value and fills the missing values using the forward fill method.Example 1In this following example, we have applied the ffill() method to the series object ... Read More

Largest BST in a Binary Tree in C++

Prateek Jangid
Updated on 07-Mar-2022 07:35:19

459 Views

In a binary tree, there are only two nodes (left and right) in each child node. Tree structures are simply representations of data. Binary Search Trees (BSTs) are special types of Binary Trees that meet these conditions −Compared to its parent, the left child node is smallerThe parent node of the right child is larger than the child nodeSuppose we're given a binary tree, and we are supposed to find out what's the largest binary search tree (BST) within it.In this task, we will create a function to find the largest BST in a binary tree. When the binary tree ... Read More

How to replace NaN values of a series with the mean of elements using the fillna() method?

Gireesha Devara
Updated on 07-Mar-2022 07:31:02

17K+ Views

In the process of pandas data cleaning, replacing missing values takes a very important role and in some conditions we must replace those missing values with the mean of series elements. This can be done by using the fillna() method.The basic operation of this pandas series.fillna() method is used to replace missing values (Nan or NA) with a specified value. Initially, the method verifies all the Nan values and replaces them with the assigned replacement value.Example 1Here we will see how the series.fillna() method replaces the missing value with mean.# importing pandas package import pandas as pd import numpy as ... Read More

Kruskal's Minimum Spanning Tree Algorithm-Greedy algorithm in C++

Prateek Jangid
Updated on 07-Mar-2022 07:27:02

4K+ Views

A spanning tree is a linked and undirected graph subgraph that connects all vertices. Many spanning trees can exist in a graph. The minimum spanning tree (MST) on each graph is the same weight or less than all other spanning trees. Weights are assigned to edges of spanning trees and the sum is the weight assigned to each edge. As V is the number of vertices in the graph, the minimum spanning tree has edges of (V - 1), where V is the number of edges.Finding minimum spanning tree using Kruskal’s algorithmAll of the edges should be arranged in a ... Read More

Evaluate a 2D Legendre series at points (x, y) with 3D array of coefficient in Python

AmitDiwan
Updated on 07-Mar-2022 07:21:00

138 Views

To evaluate a 2D Legendre series at points x, y, use the polynomial.legendre.legval2d() method in Python Numpy. The method returns the values of the two dimensional Legendre series at points formed from pairs of corresponding values from x and y.The 1st parameter is x, y. The two dimensional series is evaluated at the points (x, y), where x and y must have the same shape. If x or y is a list or tuple, it is first converted to an ndarray, otherwise it is left unchanged and if it isn’t an ndarray it is treated as a scalar.The 2nd parameter ... Read More

Evaluate a 2D Legendre series at points (x, y) in Python

AmitDiwan
Updated on 07-Mar-2022 07:19:06

283 Views

To evaluate a 2D Legendre series at points x, y, use the polynomial.legendre.legval2d() method in Python Numpy. The method returns the values of the two dimensional Legendre series at points formed from pairs of corresponding values from x and y.The 1st parameter is x, y. The two dimensional series is evaluated at the points (x, y), where x and y must have the same shape. If x or y is a list or tuple, it is first converted to an ndarray, otherwise it is left unchanged and if it isn’t an ndarray it is treated as a scalar.The 2nd parameter ... Read More

Evaluate a Legendre series at list of points x in Python

AmitDiwan
Updated on 07-Mar-2022 07:17:24

157 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

How to use pandas series.fillna() to replace missing values?

Gireesha Devara
Updated on 07-Mar-2022 07:22:57

3K+ Views

The pandas series.fillna() method is used to replace missing values with a specified value. This method replaces the Nan or NA values in the entire series object.The parameters of pandas fillna are as follows −Value − it allows us to specify a particular value to replace Nan’s, by default it takes None.Method − it is used to fill the missing values in the reindexed Series. It takes any of these values like ‘backfill’, ‘bfill’, ‘pad’, ‘ffill’, and None(default).Inplace − this parameter takes a boolean value. If it takesTrue, then the modifications are applied to the original series object itself, otherwise, ... Read More

Advertisements