Professional Documents
Culture Documents
This analysis is used when the occasional operation is very slow, but most of the operations
which are executing very frequently are faster. Data structures we need amortized analysis for
Hash Tables, Disjoint Sets etc.
In the Hash-table, the most of the time the searching time complexity is O(1), but sometimes it
executes O(n) operations. When we want to search or insert an element in a hash table for most
of the cases it is constant time taking the task, but when a collision occurs, it needs O(n) times
operations for collision resolution.
Aggregate Method
The aggregate method is used to find the total cost. If we want to add a bunch of data, then we
need to find the amortized cost by this formula.
Here we will see what are the B+ Trees. The B+ Trees are extended version of B-Trees. This tree
supports better insertion, deletion and searching over B-Tree.
B-trees, the keys and the record values are stored in the internal as well as leaf nodes. In B+ tree
records, can be stored at the leaf node, internal nodes will store the key values only. The leaf
nodes of the B+ trees are also linked like linked list
Example of B+ Tree −
This supports basic operations like searching, insertion, deletion. In each node, the item will be
sorted. The element at position i has child before and after it. So children sored before will hold
smaller values, and children present at right will hold bigger values.
Key are primarily utilized to aid the search by directing to the proper Leaf.
B+ Tree uses a "fill factor" to manage the increase and decrease in a tree.
In B+ trees, numerous keys can easily be placed on the page of memory because they do
not have the data associated with the interior nodes. Therefore, it will quickly access tree
data that is on the leaf node.
A comprehensive full scan of all the elements is a tree that needs just one linear pass
because all the leaf nodes of a B+ tree are linked with each other.
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 B-Tree, if one element is inserted, that will be
stored at the leaf node. If that is present in some internal node, then it will also be there, at the
leaf as right child of itself.
Suppose we want to insert 65 into the tree. So that is greater than 60, and less than 75. Then it
will be inserted into the middle sub-tree. Now, 65, will be inserted into node after 63, then that
node will be divided into two parts, 65 will go up, and 65 will also be there at the right node of it.
We will assume, that the key is not present into the list
Start from root node, perform exact match for key as ‘key’ till a leaf node.
Let the search path
be x1, x2, … , xh. The x1 is first node so root, then xh is leaf node. Each node
xi is parent of xi+1
Insert the new object where key is ‘key’, and value is v into xh.
i := h
while xi overflows, do
divide xi into two nodes, by moving the larger half of the keys into a new
node p.
if xi is leaf node, link p into the linked list among leaf nodes.
identify a key k, to be inserted into the parent level along with child
pointer pointing p.
The choice of k depends on the type of the node xi. If xi is leaf node, we
will perform
copy up. So smallest key in p, is copied as k to the parent level. On the
other hand, if xi is
non-leaf node, then we will perform push up. So smallest key in p, will be
copied into k,
in the parent node.
if i = 0, then
create a new index node as the new root. In the new root store node with
key k,
and two child xi and p.
return
else
insert a key k and a child pointer pointing to p, into node xi-1.
i := i – 1
end if
done
During insertion following properties of B+ Tree must be followed: Each node except root can have a
maximum of M children and at least ceil(M/2) children. Each node can contain a maximum of M – 1 keys
and a minimum of ceil(M/2) – 1 keys. The root has at least two children and atleast one search key.
In this article, we are going to discuss about the strassen matrix multiplication, formula of
matrix multiplication and algorithms for strassen matrix multiplication.
Submitted by Prerana Jain, on June 22, 2018
Introduction
Strassen in 1969 which gives an overview that how we can find the multiplication of two 2*2
dimension matrix by the brute-force algorithm. But by using divide and conquer technique
the overall complexity for multiplication two matrices is reduced. This happens by decreasing
the total number if multiplication performed at the expenses of a slight increase in the number of
addition.
For multiplying the two 2*2 dimension matrices Strassen's used some formulas in which there
are seven multiplication and eighteen addition, subtraction, and in brute force algorithm, there is
eight multiplication and four addition. The utility of Strassen's formula is shown by its
asymptotic superiority when order n of matrix reaches infinity. Let us consider two matrices A
and B, n*n dimension, where n is a power of two. It can be observed that we can contain four
n/2*n/2 submatrices from A, B and their product C. C is the resultant matrix of A and B.
1. Divide a matrix of order of 2*2 recursively till we get the matrix of 2*2.
2. Use the previous set of formulas to carry out 2*2 matrix multiplication.
3. In this eight multiplication and four additions, subtraction are performed.
4. Combine the result of two matrixes to find the final product or final matrix.
In Strassen’s matrix multiplication there are seven multiplication and four addition, subtraction
in total.
C11 = d1 + d4 – d5 + d7
C12 = d3 + d5
C21 = d2 + d4
C22 = d1 + d3 – d2 – d6
begin
If n = threshold then compute
C = a * b is a conventional matrix.
Else
Partition a into four sub matrices a11, a12, a21, a22.
Partition b into four sub matrices b11, b12, b21, b22.
Strassen ( n/2, a11 + a22, b11 + b22, d1)
Strassen ( n/2, a21 + a22, b11, d2)
Strassen ( n/2, a11, b12 – b22, d3)
Strassen ( n/2, a22, b21 – b11, d4)
Strassen ( n/2, a11 + a12, b22, d5)
Strassen (n/2, a21 – a11, b11 + b22, d6)
Strassen (n/2, a12 – a22, b21 + b22, d7)
C = d1+d4-d5+d7 d3+d5
d2+d4 d1+d3-d2-d6
end if
return (C)
end.
#include <stdio.h>
int main()
{
int a[2][2],b[2][2],c[2][2],i,j;
int m1,m2,m3,m4,m5,m6,m7;
c[0][0]=m1+m4-m5+m7;
c[0][1]=m3+m5;
c[1][0]=m2+m4;
c[1][1]=m1-m2+m3+m6;
return 0;
}
Output: