
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

614 Views
Suppose we have a binary tree; we have to check whether its height is balanced or not. We know that for a height balanced tree, for every node in the tree, the absolute difference of the height of its left subtree and the height of its right subtree is 0 or 1.So, if the input is likethen the output will be TrueTo solve this, we will follow these steps −Define a function dfs(), this will take node, if node is null, then −return 0l := 1 + dfs(left of node)r := 1 + dfs(right of node)if |l - r| > ... Read More

435 Views
When we find statistical summary of an R data frame, we only get the minimum value, first quartile, median, mean, third quartile, and maximum value but in descriptive there are many other useful measures such as variance, standard deviation, skewness, kurtosis, etc. Therefore, we can use basicStats function of fBasics package for this purpose.Loading fBasics package −library(fBasics)Consider mtcars data in base R −Example Live Demodata(mtcars) head(mtcars, 20)Output mpg cyl disp hp drat wt qsec vs am gear carb Mazda RX4 21.0 6 160.0 110 3.90 ... Read More

251 Views
Suppose we have a number n, we have to find the number of strings of length n can be generated using the following rules −Each character is a lower case vowel [a, e, i, o, u]"a" may only be followed by one "e""e" may only be followed by any of "a" and "i""i" may not be followed by another "i""o" may only be followed by any of "i" and "u""u" may only be followed by one "a"If the result is very large, mod the result by 10^9 + 7.So, if the input is like n = 2, then the output ... Read More

8K+ Views
The R-squared value is the coefficient of determination, it gives us the percentage or proportion of variation in dependent variable explained by the independent variable. To display this value on the scatterplot with regression model line without taking help from any package, we can use plot function with abline and legend functions.Consider the below data frame −Example Live Demoset.seed(1234) x

485 Views
If a vector contains five values then there will be ten pairwise differences. For example, suppose we have five numbers starting from 1, then the pairwise combinations for these values will be (1,2), (1,3), (1,4), (1,5), (2,3), (2,4), (2,5), (3,4), (3,5), (4,5). Now to find the absolute pairwise differences, we would be need to find the differences between each of these combinations and take the absolute value of the answer hence the result will be 1, 2, 3, 4, 1, 2, 3, 1, 2, 1.Example Live Demox1

357 Views
Suppose we have a list of strings called genes where each element has the same length and each element contains characters "A", "C", "G" and/or "T". Now there are some rules −When two strings s1 and s2 are the same string except for one character, then s1 and s2 are in the same mutation group.When two strings s1 and s2 are in a group and s2 and s3 are in a group, then s1 and s3 are in the same group.We have to find the total number of mutation groups we can generate.So, if the input is like genes = ... Read More

1K+ Views
The best way to create a sequence of anything is creating it with the help of seq function and this also applies to sequences of dates. But in case of dates, we need to read the dates in date format so that R can understand the input type and create the appropriate vector. If we do not use the date format for the date value then it won’t make sense to R and it will result in error.Examples Live Demox1

2K+ Views
Suppose we have two lists, weights and values of same length and another value capacity. The weights[i] and values[i] represent the weight and value of ith element. So if we can take at most capacity weights, and that we can take a fraction of an item's weight with proportionate value, we have to find the maximum amount of value we can get (rounded down to the nearest integer)So, if the input is like weights = [6, 7, 3] values = [110, 120, 2] capacity = 10, then the output will be 178.To solve this, we will follow these steps −res ... Read More

2K+ Views
The sum of rows and columns on the margins in a contingency table are always useful because they are used for different type of calculations such as odds ratio, probability etc. If an R data frame has factor columns then we can create a contingency table for that data frame and it can be done by using addmargins function.ExampleConsider the below data frame − Live Demox1