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 194 of 2544
Equable Shapes in C++
In this problem, we are given the coordinates of a polygon. Our task is to create a program to check whether the given polygon is equable or not.Equable Shape is the shape whose perimeter is equal to the area of the shape.Let’s take an example to understand the problem, Input: polygon[][] = {{0, 0}, {5, 7}, {2, 0}}Output: Not equableExplanation: Perimeter = 18.21Area = 7Solution Approach:The solution to the problem lies in find the area and perimeter of the shape and then compare both of them to check weather the given shape is an equable shape or not.Finding a perimeter using the coordinates is ...
Read MoreHow to retrieve multiple elements from a series when the index is customized Python?
When the index values are customized, they are accessed using series_name[‘index_value’].The ‘index_value’ passed to series is tried to be matched to the original series. If it is found, that corresponding data is also displayed on the console.Let us see how multiple elements can be displayed.Exampleimport pandas as pd my_data = [34, 56, 78, 90, 123, 45] my_index = ['ab', 'mn' ,'gh', 'kl', 'wq', 'az'] my_series = pd.Series(my_data, index = my_index) print("The series contains following elements") print(my_series) print("Accessing multiple elements using customized index") print(my_series[['mn', 'az', 'wq', 'ab']])OutputThe series contains following elements ab 34 mn 56 gh 78 kl 90 wq 123 ...
Read MoreHow to create boxplot for matrix columns in R?
To create a boxplot for data frame columns we can simply use boxplot function but it cannot be done directly for matrix columns. If we want to create boxplot for matrix columns then we need to convert the matrix into data frame and then use the boxplot function. For example, if we have a matrix called M then the boxplot for columns in M can be created by using boxplot(as.data.frame(M)).Example> M MOutput[,1] [,2] [,3] [,4] [,5] [1,] 1.688556 1.697216 1.9469573 1.873956 2.010246 [2,] 1.655357 1.927145 2.0937415 2.273638 1.966972 [3,] 1.886917 1.182852 2.0291452 2.507944 2.338664 [4,] 2.013053 1.995526 1.8122830 2.531708 2.483359 [5,] 1.812015 1.950053 1.8902859 2.453222 2.123253 [6,] 1.781764 1.786285 2.3384120 2.275382 2.509708 [7,] 1.836378 1.192781 1.5382031 2.012324 2.290340 [8,] 2.061482 1.705481 2.5542404 1.958202 1.991252 [9,] 2.162214 1.958862 1.8096081 1.810033 1.856942 [10,] 1.897020 1.614834 2.3407207 2.199068 1.807968 [11,] 2.491147 2.317192 2.4486029 2.131722 1.947841 [12,] 1.860307 1.932982 2.2034280 1.982581 2.720482 [13,] 1.814205 2.214286 1.6917036 1.854341 2.150684 [14,] 1.224437 1.800944 1.7600398 1.503382 2.775012 [15,] 2.309462 2.534766 1.5111472 2.058761 1.823550 [16,] 2.190564 1.588298 1.8854163 1.694651 1.939035 [17,] 2.521611 2.339012 2.2959581 2.501148 1.951673 [18,] 1.808799 2.314207 1.8704730 1.937851 1.877917 [19,] 2.476626 1.806194 2.7111663 2.156506 1.521197 [20,] 1.819725 1.633549 1.9438948 2.213533 2.247944 [21,] 2.412117 1.797531 2.5320892 1.889267 2.586912 [22,] 1.679395 2.276218 1.6120445 1.648766 1.889033 [23,] 2.286285 2.221312 0.9408758 1.896072 1.996449 [24,] 2.274975 2.398884 2.0146319 1.814092 2.350100 [25,] 2.106620 1.640401 1.6416454 2.452356 1.638885 [26,] 1.556329 1.706762 1.8324196 2.348518 1.593293 [27,] 2.171867 1.707615 1.9667116 2.191344 1.595531 [28,] 1.796751 2.753674 2.1741976 1.623239 2.399018 [29,] 2.635992 2.180735 2.2114669 2.258419 2.277367 [30,] 1.874671 2.113165 2.3653358 2.231705 1.919449Example> boxplot(as.data.frame(M))Output
Read MoreEqual Sum and XOR in C++
In this problem, we are given an integer n. Our task is to create a program to find the count of integers from i = 0 to n, where sum is equal to XOR i.e. (n+i) = (n^i).Let’s take an example to understand the problem, Input: n = 4Output: 4Explanation: Considering all values of i from 0 to n, i = 0, 4 + 0 = 4, 4^0 = 4i = 1, 4 + 1 = 5, 4^1 = 5i = 2, 4 + 2 = 6, 4^2 = 6i = 3, 4 + 3 = 7, 4^3 = 7i = 4, ...
Read MoreWhat happens if the specified index is not present in the series Python Pandas?
When the index values are customized, they are accessed using series_name[‘index_value’]. The ‘index_value’ passed to series is tried to be matched to the original series. If it is found, that corresponding data is also displayed on the console.When the index that is tried to be accessed is not present in the series, it throws an error. It has been shown below.Exampleimport pandas as pd my_data = [34, 56, 78, 90, 123, 45] my_index = ['ab', 'mn' ,'gh', 'kl', 'wq', 'az'] my_series = pd.Series(my_data, index = my_index) print("The series contains following elements") print(my_series) print("Accessing elements using customized index") print(my_series['mm'])OutputThe series contains ...
Read MoreProgram to find k where given matrix has k by k square of same value in C++
Suppose we have a 2d matrix, we have to find the largest k × k submatrix where all of its elements are containing the same value, then find the value of k.So, if the input is like1183155525554555then the output will be 3, as there is a 3 × 3 square matrix of value 5.To solve this, we will follow these steps −n := row count of matrixm := column count of matrixDefine one 2D array dp of size (n x m) and fill with 1ret := 1for initialize i := n - 1, when i >= 0, update (decrease i ...
Read MoreHow to identify the difference between Kolmogorov Smirnov test and Chi Square Goodness of fit test in R?
The Chi Square Goodness of fit test is used to test whether the distribution of nominal variables is same or not as well as for other distribution matches and on the other hand the Kolmogorov Smirnov test is only used to test to the goodness of fit for a continuous data. The difference is not about the programming tool, it is a concept of statistics.Example> x xOutput[1] 0.078716115 -0.682154062 0.655436957 -1.169616157 -0.688543382 [6] 0.646087104 0.472429834 2.277750805 0.963105637 0.414918478 [11] 0.575005958 -1.286604138 -1.026756390 2.692769261 -0.835433410 [16] 0.007544065 0.925296720 1.058978610 0.906392907 0.973050503Example> ks.test(x, pnorm) One-sample Kolmogorov-Smirnov test data: x D ...
Read MoreEqualize an array using array elements only in C++
In this problem, we are given an array of n elements. Our task is to create a program to count the number of operations to equalize an array using elements only.We need to count the number of adding or subtraction operations that will be performed to make all the elements of the array equal.Let’s take an example to understand the problem, Input: arr[] = {4, 0, 3, 1, 2}Output: 3Explanation: The equal value will be 2.The overall sum will be the same. We will be taking 1 from value at arr[3] and then adding it to value at arr[1].Then we will take 2 ...
Read MoreExplain how a dataframe structure can be created using list of dictionary values 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.It can be created using the following constructor −pd.Dataframe(data, index, columns, dtype, copy)The ‘data’, ‘index’, ‘columns’, ‘dtype’ and ‘copy’ are not compulsory values.A list of dictionaries can be passed as input to the dataframe. The keys of dictionary are taken as column names by default. Let us see an example −Exampleimport pandas as pd my_data = [{'ab' : 34}, {'mn' : 56}, { 'gh' : 78}, ...
Read MoreProgram to expand string represented as n(t) format in Python
Suppose we have a string s, this is encoding a longer string. s is represented as the concatenation of n(t), n(t) represents the concatenation of t, n times, and t is either a regular string or it is another encoded string recursively. We have to find the decoded version of s.So, if the input is like s = "3(pi)2(3(am))0(f)1(u)", then the output will be "pipipiamamamamamamu"To solve this, we will follow these steps −i := 0Define a function parse() . This will takeans := a new listwhile i < size of s and s[i] is not same as ")", doif s[i] ...
Read More