Server Side Programming Articles

Page 1214 of 2109

How to display the curve on the histogram using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 3K+ Views

Mostly, we use histogram to understand the distribution of a variable but if we have an overlay line on the histogram that will make the chart smoother, thus understanding the variation will become easy. To display the curve on the histogram using ggplot2, we can make use of geom_density function in which the counts will be multiplied with the binwidth of the histogram so that the density line will be appropriately created.ExampleConsider the below data frame:> x df head(df, 20)Output x 1 4 2 5 3 6 4 4 5 9 6 ...

Read More

Program to find Inorder Successor of a binary search tree in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 795 Views

Suppose we have a binary search tree BST and another value of a node, we have to find the in-order successor of that node in the BST. As we all know that the successor of a node p is the node with the smallest key greater than the value of p.So, if the input is likeAnd p = 1, then the output will be 2, To solve this, we will follow these steps −Define recursive method inorderSuccessor(), this will take root and pif root null, then:return nullif val of root val val){             return inorderSuccessor(root->right, ...

Read More

Moving Stones Until Consecutive II in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 303 Views

Suppose we are considering an infinite number line, here the position of the i−th stone is given by array stones and stones[i] is indicating ith stone position. A stone is an endpoint stone if it has the smallest or largest position. Now in each turn, we pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.If the stones are at say, stones = [1, 2, 5], we cannot move the endpoint stone at position 5, because moving it to any position (such as 0, or 3) will still keep ...

Read More

How to check if values in a column of an R data frame are increasingly ordered or not?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 354 Views

The values are increasingly ordered if the first value is less than the second, the second is less than the third, the third is less than the fourth, the fourth is less than the fifth, and so on. In base R, we have a function called is.unsorted that can help us to determine whether the values in a column of an R data frame are increasingly ordered or not. Check out the below examples to understand how it works.Example1> set.seed(3257) > x df1 df1Output x 1 9 2 8 3 8 4 7 5 10 6 2 7 7 ...

Read More

How to find the sum based on a categorical variable in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

Finding group-wise mean is a common thing but if we go for step-by-step analysis then sum of values are also required when we have a categorical variable in our data set. This can be easily done with the help of group_by and summarise_each function of dplyr package.ExampleConsider the below data frame:> Group Salary Emp EmpOutputGroup Salary 1 D 28256 2 B 31092 3 A 23147 4 C 28209 5 B 37676 6 C 33374 7 D 44864 8 B 40152 9 A 25843 10 A 40946 11 D 23321 12 A 42854 13 C 36960 14 A 35285 15 B ...

Read More

Cousins in Binary Tree in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 606 Views

Suppose we have a binary tree, the root node is present at depth 0, and children of each depth k node are at depth k+1.Here two nodes of a binary tree are called cousins if they have the same depth, but have different parents.All values of the tree will be unique, and the values x and y of two different nodes in the tree. We have to check whether the nodes corresponding to the values x and y are cousins or not.So, if the input is likex = 5, y = 4, then the output will be trueTo solve this, ...

Read More

Rotting Oranges in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 286 Views

Suppose we have a grid, here in each cell can have one of three values −value 0 for an empty cell;value 1 for a fresh orange;value 2 for a rotten orange.In every minute, any fresh orange that is adjacent to a rotten orange becomes rotten.We have to find the minimum number of times that must elapse until no cell has a fresh orange. If this is not possible, then return -1.So, if the input is like [[2, 1, 1], [1, 1, 0], [0, 1, 1]], then the output will be 4To solve this, we will follow these steps −minutes := ...

Read More

Construct Binary Tree from String in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have a string consisting of parenthesis and integers. We have to construct a binary tree from that string. The whole input represents a binary tree. It holds an integer that followed by zero, one or two pairs of parentheses. The integer represents the root's value and a pair of parenthesis contains a child binary tree with the same structure.So, if the input is like "4(2(3)(1))(6(5))", then the output will be [3, 2, 1, 4, 5, 6] (inorder traversal)To solve this, we will follow these steps −Define a function solve(), this will take s, idx, if idx >= size ...

Read More

Output Contest Matches in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 263 Views

Suppose we have n teams and we always arrange the rather strong team to play with the rather weak team, like make the rank 1 team play with the team with rank n, this strategy is to make the contest more interesting. Now we have to find their final contest matches in the form of a string.These teams are given in the form of positive integers from 1 to n, which represents their initial rank. So, rank 1 is the strongest team, and Rank n is the weakest team. We will use parentheses and commas to represent the contest team ...

Read More

How to create boxplot using mean and standard deviation in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 10K+ Views

The main statistical parameters that are used to create a boxplot are mean and standard deviation but in general, the boxplot is created with the whole data instead of these values. If we don’t have whole data but mean and standard deviation are available then the boxplot can be created by finding all the limits of a boxplot using mean as a measure of central tendency.ExampleConsider the below data frame:> df dfOutputmean sd Category 1 24 1.1 A 2 25 2.1 B 3 27 1.5 C 4 24 1.8 DLoading ggplot2 package and creating the boxplot of each category in ...

Read More
Showing 12131–12140 of 21,090 articles
Advertisements