#include
#include //in this version, you only need left //and right rotation, not 4 cases
#include
#include using namespace std;
struct Node
{
int data; struct Node* left; struct Node* right; int height;
};
//a function to calculate height of the tree int height(struct Node* root)
{
if(root == NULL) { return 0; //if there is no node, return 0 } return root->height; //else, repeat the function
}
//a helper function to create a new node faster
Node* newNode(int data)
{
Node* node = new Node(); node->data = data; node->left = NULL; node->right = NULL; node->height = 1; // new node is added at leaf return (node); //return the pointer to the newly created node
}
//rotations
Node* rightRotate(Node* input)
{
Node* x
…show more content…
If this node is unbalanced, there are 4 cases //Left Left case //notice balance will change depends on how you //calculate your balance factor if(balance > 1 && data < node->left->data) { return rightRotate(node); }
//Right Right case if(balance < -1 && data > node->right->data) { return leftRotate(node); }
//Left Right case if(balance > 1 && data > node->left->data) { node->left = leftRotate(node->left); return rightRotate(node); }
//Right Left case if(balance < -1 && data < node->right->data) { //swapping using rightRotate, since it is a pointer node->right = rightRotate(node->right); return leftRotate(node); }
//return the (unchanged) node pointer return node; }
Node* FindMinNode(Node* root) //find the minimum value node in the tree
{
Node* current = root; //keep traversing to the leftest leaf since it WILL be in the left while(current->left != NULL) { current = current->left; } return current;
}
//recursion are like moving from stations to
//stations
Node* deleteNode(Node* root, int data)
{
//1. Perform standard BST delete if(root == NULL) { return root; } //if the key to be deleted is smaller than //root's key, then go left, recursively if( data < root->data) { root->left = deleteNode(root->left, data); }
//if the key to be deleted is bigger than //root's key, then go right, recursively else if(data > root->data) { root->right =
create a tree from the data encountered in the following order. 78.2, -35.1, 48.2, 12.9,
The right branch has records 1,3,8,9,10. Now we split the right child which has records 1,3,8,9,10. Candidate Split Left Child Node, tL Right Child Node, tR
Modifying the path to the leaf: After inserting “Ent” into a leaf, we must bring up to date the CF information for each nonleaf entry on the path to the leaf. In the absence of a split, this basically involves adding CF vectors to reflect the addition of “Ent”. A leaf split requires us to insert a new nonleaf entry into the parent node, to illustrate the newly created leaf. If the parent has space for this entry, at all higher levels, we only need to bring up to date the CF vectors to reflect the addition of “Ent”. In general, however, we may have to split the parent as well, and soon up to the root. I f the root is split, the tree height increases by
The tree diagram is a graphic representation of the tree model. This tree diagram shows that:
Factor C: Tree stand (3 levels: Tree 1, Tree 2 and Tree 3). The experimental layout is presented in table 1 below.
As tree structures are a abstract concept to get a good grasp on for the first time, I eventually settled to what I have now.
template (-- removed HTML --) JaggedArray (-- removed HTML --) & JaggedArray (-- removed HTML --) ::operator=(const JaggedArray (-- removed HTML --) & v) {
// print out character, frequency, and code for this leaf (which is just the prefix)
lic Node(int value) { val = value; } } / * * Binary search tree class * supports inserting, searching, and printing * nodes as in-order array */ public class BST { private Node _root; public BST() { _root = null; } /* * Insert a number into the tree * @param val integer to insert */ public void insert(int val) { /* insert at root if empty */ if (_root = = null) _root = new Node(val); /* call recursive insert */ else insert(val, _root); } /* *
A tree-structure diagram is the schema for a hierarchical database. Such a diagram consists of two basic components:
The above illustrates the summary of different relation of function. Below we will focus on further explaining of how to isolate the recursions from the code in order to gain the benefit of convenience, which is easier to control, repair and further develop the code.
Number of branches in tree = number of nodes – 1 = 5 – 1 = 4
Today’s world of computer systems are used by large set of individuals across organisations either collocated or distributed geographically. This has decreased the level of trust as compared to the past where there were small set of users entrusted in an organisation (Van der Geest G J, 2008) . In a bid to make sensitive data and infrastructure secured from unauthorized users, a security policy is developed by the system administrator of the organisation in other to control “who gets in”, “who does what” and “who sees what”. This duty has seemed to be one of the difficult problems faced by the admin and could turn out bad If not controlled properly (Kizza, 2009). However, due to differences in geographical
= head->header; // Create chain linking to first element item->prev = head->header; // Add new link to old item } } else { // Queue is empty head->header = item; // Make header point to new item item->prev = NULL; // Only 1 element so set to NULL item->next = NULL; // Only 1 element so set to NULL } return; }
For starting node, consider all unvisited neighboring nodes and calculate distance from starting node. If the distance assigned is Zero or non-zero value greater than calculated value, assign the calculated value. Else keep the assigned value