Mohan
BAN USERLets say we have a database table with below columns:
UserID, lastDownloadresetDateTime, lastDownloadDateTime, downloadCount.
lastDownloadresetDateTime would store the datetime when user tries to download something and the lastDownloadedDateTime > 24hrs.
That is: pseudo logic
if (lastDownloadresetDateTime - currentDateTime < 24 hrs AND downloadCount == 10)
{
// deny access for downloading
}
else
{
// allow download access and set the below values for the user
if (lastDownloadresetDateTime - currentDateTime > 24 hours)
{
update lastDownloadresetDateTime = currentDateTime
update downloadCount = 1;
}
else
{
update downloadCount++;
}
}
Performing action on the given (processing\visiting) node is denoted as "D". And traversing left child node denoted with "L" and right child node denoted with "R". So, there are three possible ways one can traverse the tree.
1. Preorder (DLR) traversal
2. Inorder (LDR) traversal
3. Postorder (LRD) traversal
All of them are O(n) complexity and O(n) space complexity. No major difference between them except the sequence of the actions. All of them can be achieved using either recursive or non-recursive method. Here is one of the implementation using PreOrder Traversal with recursive method.
struct Node {
int data;
struct Node *left;
struct Node *right;
};
//
// Pre-Order Traversal method (DLR)
// i.e. 1. Visit the root 2. Traverse Left subtree 3. Traverse the right subtree
//
void BinaryTreeTraversal(struct Node *root)
{
if (root) // make sure the node is not NULL, that is the recursive terminator
{
printf("%d ", root->data);
BinaryTreeTraversal(root->left);
BinaryTreeTraversal(root->right);
}
}
Repmonicahbess, SDET at Adap.tv
Hi Everyone, I'm Monica H. Bess. I love to build props...everything from a casket to pneumatic monsters.My ...
Repberrysvickers, Associate at Absolute Softech Ltd
Spent 2001-2004 developing strategies for country Luxury Car Rental Miami. Had some great experience building robots for the underprivileged. Have ...
- Mohan December 21, 2015