Saturday, July 28, 2018

One of the benefits of using object storage is the ability to use namespaces, buckets and objects in a way that suits the requirement at hand. For example, if we want horizontal scalability, we provide a way to do so with objects. Since each of the objects can have a path specifier all the matching can be done based on path. There are only forward references from namespace to buckets to objects. Relationship between objects need not be found by traversal. These are mere storage entities. There is no restriction from keeping metadata per object or dedicating an object specifically to metadata. The latter is much more efficient for programs that want to maintain their own metadata for their objects so they are not limited to what they want to achieve with their objects. Even a simple adjacency matrix is sufficient to describe the graph overlaid on these objects. This means object storage can form the base of different query processing engines

#codingexercise
We were performing inversion count on an array of unsorted positive integers.
Given an array such as {1, 20, 6, 4, 5 } the number of inversions is 5. We could also count non-inversions by simply flipping the comparision
One way to do this is to count it by traversal with order of O(N^2)
Int GetCountNonInversions(List<int> A) 
{ 
Int count = 0; 
For (int I =0; I < A.Count(); i++) 
    For (int j = i+1; j < A.Count(); j++) 
       If (A[i]  < A[j]) 
            count++; 
return count; 

} 
The same applies to merge-sort and AVL tree based methods:
Node Insert(ref Node root, Node z, ref count) 

assert(z); 
z.height = -1; 
if (!root) 
     root = z; 
else if (z.data < root.data) 
     root.left = Insert(root.left, z, ref count); 
else 
     root.right = Insert(root.right, z, ref count); 
     count = count + root.right + 1 


root.height = 1 + max(height(root.left), height(root.right)); 
Balance(root); 


Node Balance(Node root) 

FixHeight(root); // 1 more than left or right 
if (Bfactor(root) == 2) // Bfactor is h(right)-h(left) 

      if (Bfactor(root.right) < 0) 
           root.right = RightRotate(root.right); // returns root.right.left 
      return LeftRotate(root); 

if(BFactor(root) == -2) 

      if (Bfactor(root.left) > 0) 
           root.left = LeftRotate(root.left); 
      return RightRotate(root); 

return root; 


Balance is based on rotation after fixing height. 

No comments:

Post a Comment