Segment Trees in Data Structure

Arnab Chakraborty
Updated on 11-Aug-2020 07:52:15

547 Views

In this section we will see what is the segment tree. Before discussing that, let us see one problem.Suppose we have an array arr[0, …, n-1], We can do following operations −Find the sum of elements from index l to r, where 0 ≤ l ≤ r ≤ n-1Change the value of a specified element of the array to a new value x. We need to do arr[i] = x. The i in range 0 to n – 1.We can solve this problem by using the Segment tree. The segment tree can help us to get the sum and query ... Read More

Interval Trees in Data Structure

Arnab Chakraborty
Updated on 11-Aug-2020 07:50:46

2K+ Views

In this section we will see what is the interval tree. As the name suggests, that the interval trees are the trees which are associated with the intervals. So before discussing about the interval trees, let us see the elementary intervals.An interval is basically a range. So if one interval is written as [a, b] it indicates that the range is starting from a, and ending at b.Now suppose there is an interval [10, 20]. So there are three range values. First one is -∞ to 10, 10 to 20 and finally 20 to ∞Now, suppose we will create second ... Read More

Change Y-Axis Values in a Bar Plot using ggplot2 in R

Nizamuddin Siddiqui
Updated on 11-Aug-2020 07:49:09

6K+ Views

Bar plot is frequently used to analyze the number of times a level of factor variable occurs in a data set and the Y-axis values are crucial to the bar plot. Sometimes these values are not in the form we want, therefore, we want to replace them with the new ones. This can be done with the help of breaks argument of scale_y_continuous function in ggplot2.ExampleConsider the below data frame −> set.seed(1) > x df library(ggplot2)Creating the plot without specifying the Y-axis values −> ggplot(df, aes(x))+ + geom_bar()OutputPlotting with new Y-axis values −> ggplot(df, aes(x))+ + geom_bar()+ + scale_y_continuous(breaks=c(0, 2, ... Read More

B+ Tree Deletion in Data Structure

Arnab Chakraborty
Updated on 11-Aug-2020 07:47:36

892 Views

Here we will see, how to perform the deletion of a node from B+ Tree. Suppose we have a B+ Tree like below 7minus;Example of B+ Tree −Deletion has two parts. At first we have to find the element. That strategy is like the querying. Now for deletion, we have to care about some rules. One node must have at-least m/2 elements. So if we delete, one element, and it has less than m-1 elements remaining, then it will adjust itself. If the entire node is deleted, then its children will be merged, and if their size is same as ... Read More

Extract Initial, Last, or Middle Characters from a String in R

Nizamuddin Siddiqui
Updated on 11-Aug-2020 07:46:59

2K+ Views

In Text analysis, we might want to extract characters from a single string or from a vector of strings. This extraction might be required to create a new string with some specific words required for further analysis. We can do this with the help of str_sub function of stringr package.ExampleConsider the below string −> x1 library(stringr) > str_sub(x1, 1, 8) [1] "Removing" > str_sub(x1, 1, 23) [1] "Removing harmful things" > str_sub(x1, 29, 37) [1] " the road" > str_sub(x1, 30, 37) [1] "the road" > str_sub(x1, -58, -51) [1] "Removing" > str_sub(x1, -58, -1) [1] "Removing harmful things from ... Read More

Convert Matrix Columns to a List of Vectors in R

Nizamuddin Siddiqui
Updated on 11-Aug-2020 07:42:45

589 Views

If we want to use columns of a matrix as a vector then we can convert them in a list of vectors. To convert matrix columns to a list of vectors, we first need to convert the matrix to a data frame then we can read it as list. This can be done as as.list(as.data.frame(matrix_name)).ExampleConsider the below matrix −> M M [, 1] [, 2] [, 3] [, 4] [, 5] [1, ] 1 6 11 16 21 [2, ] 2 7 12 17 22 [3, ] 3 8 13 18 23 [4, ] 4 9 14 ... Read More

Count Rows for Combinations of Categorical Variables in R

Nizamuddin Siddiqui
Updated on 11-Aug-2020 07:36:38

505 Views

When we have two categorical variables then each of them is likely to have different number of rows for the other variable. This helps us to understand the combinatorial values of those two categorical variables. We can find such type of rows using count function of dplyr package.ExampleConsider the CO2 data in base R −> head(CO2, 20) > head(CO2, 20)       Plant    Type    Treatment    conc     uptake 1     Qn1     Quebec   nonchilled     95      16.0 2     Qn1     Quebec   nonchilled    175   ... Read More

B-Tree Deletion in Data Structure

Arnab Chakraborty
Updated on 11-Aug-2020 07:31:37

1K+ Views

Here we will see, how to perform the deletion of a node from B-Tree. Suppose we have a BTree like below −Example of B-Tree −Deletion has two parts. At first we have to find the element. That strategy is like the querying. Now for deletion, we have to care about some rules. One node must have at-least m/2 elements. So if we delete, one element, and it has less than m-1 elements remaining, then it will adjust itself. If the entire node is deleted, then its children will be merged, and if their size issame as m, then split them ... Read More

B-Tree Query in Data Structure

Arnab Chakraborty
Updated on 11-Aug-2020 07:27:13

738 Views

Here we will see, how to perform the searching in B-Tree. The B-Tree searching is also known as B-Tree Querying. Suppose we have a B-tree like below −Example of B-Tree −The searching technique is very similar to the binary search tree. Suppose we want to search 66 from the above tree. So we will start from root, now 66 is larger than root element 46. So we will move to the right child of the root. Then the right child has more than one element. The elements are sorted, they are [56, 81]. Our target key is larger than 56, ... Read More

B-Tree Insertion in Data Structure

Arnab Chakraborty
Updated on 11-Aug-2020 07:25:53

827 Views

Here we will see, how to perform the insertion into a B-Tree. Suppose we have a B-Tree like below −Example of B-Tree −To insert an element, the idea is very similar to the BST, but we have to follow some rules. Each node has m children, and m-1 elements. If we insert an element into one node, there are two situations. If the node has elements less than m-1, then the new element will be inserted directly into the node. If it has m-1 elements, then by taking all elements, and the element which will be inserted, then take the ... Read More

Advertisements