Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Programming Articles
Page 198 of 2545
How to get top values of a numerical column of an R data frame in decreasing order?
To get the top values in an R data frame, we can use the head function and if we want the values in decreasing order then sort function will be required. Therefore, we need to use the combination of head and sort function to find the top values in decreasing order. For example, if we have a data frame df that contains a column x then we can find top 20 values of x in decreasing order by using head(sort(df$x, decreasing=TRUE), n=20).ExampleConsider the CO2 data frame in base R −> str(CO2)OutputClasses ‘nfnGroupedData’, ‘nfGroupedData’, ‘groupedData’ and 'data.frame': 84 obs. of 5 ...
Read MoreCheck if all levels of two trees are anagrams or not in Python
Suppose, we are provided with two binary trees. We have to check if each level of a binary tree is an anagram of the other binary tree's same level. We return True if it is an anagram, otherwise we return False.So, if the input is like, then the output will be True.To solve this, we will follow these steps −tree_1 is the root node of the first tree and tree_2 is the root node of the second tree.if tree_1 is same as null and tree_2 is same as null, thenreturn Trueif tree_1 is same as null or tree_2 is same ...
Read MoreEuler's Four Square Identity in C++
In this problem, we are given two numbers and we need to find the product of the numbers using Euler's four square Identity. Euler’s Four Square Identity is the method to find the product of two numbers which can be represented using the sum of four squares of the number if the numbers can be represented as sum of four squares.The product a * b can be represented as the sum of four squares ifa = x12 + x22 + x32 + x42 b = y12 + y22 + y32 + y42 a * b = z12 + z22 + z32 + z42Let’s take an example ...
Read MoreCount Pairs of Consecutive Zeros in C++
We have a sequence generator that starts with 1. At each step 0 becomes 10 and 1 becomes 01. So following changes will occur at consecutive steps −Step 1 − 01Step 2 − 1001Step 3 − 01101001 ……The goal is to find the number of pairs of consecutive 0’s for a given number of steps.If input step is 1 pair of 0’s - 0, input step is 2 pair of 0’s - 1, input step is 3 pair of 0’s 1Step 4 − 1001011001101001Step 5 − 01101001100101101001011001101001We can observe that sequence is increasing in powers of 2 and repeats itself ...
Read MoreProgram to Find Out the Minimal Submatrices in Python
Suppose we have a 2D matrix and another value k. Our goal is to return a matrix that contains the lowest values of all k x k sub-matrices.So, if the input is like3568654312and k =2, then the output will be [[3, 5], [3, 3]] .From the input, we can see that the top left submatrix has the lowest value of 33 5 8 6The top right submatrix has the lowest value of 55 6 6 5The bottom left submatrix has the lowest value of 38 6 4 3The bottom right submatrix has the lowest value of 36 5 3 12To ...
Read MoreEulerian Number in C++
In mathematics, the Eulerian number is a special type of combination number. It defines the number of permutations in which the next element is a specific number greater than the previous one.Denoted as, A(n, m) is permutation from 1 to n in which two numbers vary by m.Problem Statement: In this problem, we are given two numbers m and n. And we need to find the number of permutations that are the Eulerian Number.Let’s take an example to understand the problem, Input: n = 4, m = 2Output: 11Explanation: All permutations of number from 1 to 4 are −1 2 3 4 ...
Read MoreCount pairs in an array that hold i*arr[i] > j*arr[j] in C++
We are given an array of numbers. The goal is to find the pair of elements of array such that they hold the conditionIf (i*arr[i] > j*arr[j]) then (arr[i], arr[j]) is a valid pair.If the array is [ 5, 4, 3, 2, 1 ] then pairs will be [3, 1] and [2, 1].Let us understand with examples.Input − arr[] = [ 1, 5, 4, 1, 2, 8, 3 ]Output − Count of pairs in an array that hold i*arr[i] > j*arr[j] are − 3Explanation − Pairs are (5, 1), (4, 1), (8, 3)Input − arr[] = [ -1, -2, 3, ...
Read MoreHow to delete a column of a dataframe using the ‘pop’ function in Python?
Dataframe is a two dimensional data structure, where data is stored in a tabular format, in the form of rows and columns.It can be visualized as an SQL data table or an excel sheet representation. A column in a dataframe can be deleted using different methods.We will see the pop function that takes the name of the column that needs to be deleted as a parameter, and deletes it.Exampleimport pandas as pd my_data = {'ab' : pd.Series([1, 8, 7], index=['a', 'b', 'c']), 'cd' : pd.Series([1, 2, 0, 9], index=['a', 'b', 'c', 'd']), 'ef' : pd.Series([56, 78, 32], index=['a', 'b', 'c']), ...
Read MoreProgram to Find Out the Minimum Parsing Tree in C++
Suppose we have a list of unique and sorted numbers that represent breakpoints in a string. We want to create a tree out of these rules −There are nodes that have a value (a, b) where a and b are breakpoints. This means the node spans from indices [a, b] in the string.The root node spans over every breakpoint. (the whole string).The spans of a node's left and right child are ordered, contiguous, and contains the parent node's span.Leaf nodes' index of 'a' in breakpoints is 1 before the index of 'b' in breakpoints.The cost of a tree is determined ...
Read MoreHow to create a residual plot in R with better looking aesthetics?
The default residual plot can be created by using the model object name in base R but that is not very attractive. To create a residual plot with better looking aesthetics, we can use resid_panel function of ggResidpanel package. It is created in the same way as the residual plot in base R, also it results in all the relevant graph in one window.ExampleConsider the below data frame −> x y df dfOutputx y 1 0.48508894 0.217379409 2 0.75113573 -0.657179470 3 -0.13075185 -0.549613217 4 -0.26867557 1.156736294 5 0.40407850 0.640387394 6 -0.23816272 -0.807847198 7 -0.57278583 0.600249694 8 -0.78222676 -0.711133218 9 1.70161645 ...
Read More