We were reviewing DynamoDB. We will compare it with Cosmos DB but first let us review Cosmos DB. Azure Cosmos DB was written to be the industry's first globally-distributed, multi-model database services. It is built to collect data from a plethora of IoT devices as well as to be handle the processing of machinelearning. It is a globally distributed data service that can elastically scale througphut and storage with data consistency, low latency and high availability. There are five different consistency levels which include strong, bounded-staleness, session, consistent-prefix and eventual consistency levels. No schema or index is required because the database automatically indexes all data and the engine does not know or care about any schemas. Key-value, documents and graph data models are easily supported.
{
Node root = new Node();
root.data = PreOrder[index];
root.left = null;
root.right = null;
int inIndex = Array,indexOf(InOrder, Preorder[index]);
if ( index+1 < Preorder.Length &&
IsLeftSubtree(Preorder[index+1], inOrder, inIndex) == true)
root.left = BuildTree(Preorder, InOrder, index + 1);
if ( inIndex+1 < InOrder.Length &&
isPredecessor(InOrder[inIndex+1], Preorder, index) == false)
root.right = BuildTree(Preorder, InOrder, Array.IndexOf(PreOrder, InOrder[inIndex + 1]));
return root;
}
bool is Predecessor(char c, char[] Preorder, int index)
{
return Array.IndexOf(Preorder, c) < index;
}
bool isLeftSubtree(char c, char[] inOrder, int index)
{
Array.IndexOf(Inorder,c) < index;
}
// Preorder A B C D E F
// Inorder C B D A E F
// Build tree
a
b e
c d f
Node BuildTree(char[] Preorder, char[] InOrder, char parent, int index = 0, int start, int end)
{
Node root = new Node();
char current = PreOrder[index];
root.data = current;
root.left = null;
root.right = null;
if (start == end) return root;
int size_left = indexOfFromStart(InOrder, current, parent, index, start, end);
if (size_left > 0)
root.left = BuildTree(Preorder, InOrder, current, index+1, index+1, index+size_left);
int size_right = end-start-size_left;
if (size_right > 0)
root.right = BuildTree(Preorder, InOrder, current, index+size_left+1, index+size_left+1, end);
return root;
}
int indexOfFromStart(char[] InOrder, char c, char parent, int index, int start, int end)
{
if (start >= end) return 0;
int inIndex= InOrder.IndexOf(c);
// start and end are in pre-order
// index in from inorder but the size of the left subtree
// must be contained in preorder between start and end
// and must be between 0 and index in inorder
if (inIndex<start) return 0;
assert(inindex <= end);
int begin = 0;
if (parent != '/0')
begin = InOrder.IndexOf(parent);
if (begin<inIndex)
return inIndex-begin-1;
return inIndex;
}
This database allows the developers to add any number of regions while retaining the same fidelity as the one closest. The database also seamlessly replicates data across regions. It elastically scales throughput and storage. The applications can also be built to be more responsive. The database engine is said to be write-optimized, log structured and latch-free which enables it to guarantee writes in single digit millisecond latencies anywhere in the world.
#codingexercise
Node BuildTree(char[] Preorder, char[] InOrder, int index = 0){
Node root = new Node();
root.data = PreOrder[index];
root.left = null;
root.right = null;
int inIndex = Array,indexOf(InOrder, Preorder[index]);
if ( index+1 < Preorder.Length &&
IsLeftSubtree(Preorder[index+1], inOrder, inIndex) == true)
root.left = BuildTree(Preorder, InOrder, index + 1);
if ( inIndex+1 < InOrder.Length &&
isPredecessor(InOrder[inIndex+1], Preorder, index) == false)
root.right = BuildTree(Preorder, InOrder, Array.IndexOf(PreOrder, InOrder[inIndex + 1]));
return root;
}
bool is Predecessor(char c, char[] Preorder, int index)
{
return Array.IndexOf(Preorder, c) < index;
}
bool isLeftSubtree(char c, char[] inOrder, int index)
{
Array.IndexOf(Inorder,c) < index;
}
// Preorder A B C D E F
// Inorder C B D A E F
// Build tree
a
b e
c d f
Node BuildTree(char[] Preorder, char[] InOrder, char parent, int index = 0, int start, int end)
{
Node root = new Node();
char current = PreOrder[index];
root.data = current;
root.left = null;
root.right = null;
if (start == end) return root;
int size_left = indexOfFromStart(InOrder, current, parent, index, start, end);
if (size_left > 0)
root.left = BuildTree(Preorder, InOrder, current, index+1, index+1, index+size_left);
int size_right = end-start-size_left;
if (size_right > 0)
root.right = BuildTree(Preorder, InOrder, current, index+size_left+1, index+size_left+1, end);
return root;
}
int indexOfFromStart(char[] InOrder, char c, char parent, int index, int start, int end)
{
if (start >= end) return 0;
int inIndex= InOrder.IndexOf(c);
// start and end are in pre-order
// index in from inorder but the size of the left subtree
// must be contained in preorder between start and end
// and must be between 0 and index in inorder
if (inIndex<start) return 0;
assert(inindex <= end);
int begin = 0;
if (parent != '/0')
begin = InOrder.IndexOf(parent);
if (begin<inIndex)
return inIndex-begin-1;
return inIndex;
}
No comments:
Post a Comment