Please provide the big oh notation for running time and space complexity for the following methods (splay, findSplay, putSplay, eraseSplay:
void
SplayTreeMap::splay(Node* x) {
if(x!=NULL){
while (x -> parent != NULL )
{
Node *p = x -> parent;
Node *g = p -> parent;
if (g == NULL) zig(x);
else if (g -> left == p && p -> left == x) zigZig(x);
else if (g -> right == p && p -> right == x) zigZig(x);
else zigZag(x);
}
this -> root = x;
}
}
Node*
SplayTreeMap::findSplay(string k) {
Node** wAndZ = this->find(k);
Node* w = wAndZ[0]; // w is the node with key k, if it exists, or NULL otherwise
Node* z = wAndZ[1]; // z is the parent of node w, or if w is NULL, the last node found while searching for key k
if(w!=NULL){
delete wAndZ;
Node* x = (w) ? w : z;
this->splay(x);
return x;
}
else{
return NULL;
}
}
Node*
SplayTreeMap::putSplay(string k, int v) {
Node* x = this->put(k,v);
this->splay(x);
return x;
}
Node*
SplayTreeMap::eraseSplay(string k) {
Node* x = this->erase(k);
this->splay(x);
return x;
}
Splay Tree is nothing but it is a self-balanced binary search tree with having some additional property that are accessing the elements which are quick to access again.
Time complexity in Average case: O (log N)
Time complexity in Worst case: O (log N)
Space complexity in Worst case: O (N)
Time complexity in Average case: O (log N)
Time complexity in Worst case: O (log N)
Space complexity in Worst case: O (N)
Time complexity in Average case: O (log N)
Time complexity in Worst case: O (log N)
Space complexity in Worst case: O (N)
Time complexity in Average case: O (log N)
Time complexity in Worst case: O (log N)
Space complexity in Worst case: O (N)
Please provide the big oh notation for running time and space complexity for the following methods...
Please provide the big oh notation for running time and space complexity for the following functions (available, into, out, size, and printAll): int SplayTreeInventory::available(string id){ Node* temp=stmap->findSplay(id); if(temp!=NULL) return temp->value; else return -1; } void SplayTreeInventory::into(string id, int amount) { Node* temp=stmap->findSplay(id); if(temp==NULL){ stmap->putSplay(id, amount); } else{ temp->key+=amount; } } void SplayTreeInventory::out(string id, int amount) { Node* temp=stmap->findSplay(id); if(temp==NULL){ } else{ if(temp->value<=amount) stmap->erase(id); else temp->value-=amount; } } int SplayTreeInventory::size() { return stmap->size(); } void SplayTreeInventory::printAll() { printAllHelper(this->stmap->root); }
Using the following implementation of Tree class Node { public int iData; // data item (key) public double dData; // data item public Node leftChild; // this node's left child public Node rightChild; // this node's right child public void displayNode() // display ourself { System.out.print('{'); System.out.print(iData); System.out.print(", "); System.out.print(dData); System.out.print("} "); } } // end class Node //------------------------------------------------------------------ import java.io.IOException; import java.util.Stack; public class Tree { private Node root; // first node of tree // ------------------------------------------------------------- public Tree() // constructor { root = null; }...
Writing traversal methods You will create two files in the csc403 package: one called A3SimplerBST.java and the other TestA3.java. Details on these programs appears below. Copy the file SimplerBST.java from the week 1 examples package and rename the file and class A3SimplerBST. Add two public methods: one named twoChildrenCount that takes no parameters and that, when called, traverses every node of the tree to count how many nodes have two children. one named sameValueCount that takes a paremeter of generic...
Q. write the algorithm for each function in this code: void insert(int x, node*&p) { //cheak if the pointer is pointing to null. if (p==NULL) { p = new node; p->key=x; p->left=NULL; p->right=NULL; } else { //Cheak if the element to be inserted is smaller than the root. if (x < p->key) { //call the function itself with new parameters. insert(x,p->left); } //cheak if the alement to be inserted...
C++: PLEASE HELP~!!! ~~~~~~~~ Implement bool AVLTree::deleteNode(string ss) method. Function deleteNode() tries to delete the node containing value ss. If there is no such node, it returns false. Otherwise, it deletes the node, check the balance of the tree, rebalance the tree if it is necessary. When you delete a node, consider three different scenarios: -The node is a leaf -The node has only ONE child subtree -The node has two child subtrees Important: When you implement this project, do...
Need help in the below question. Answer in java Start with the tree.java program (Listing 8.1) and modify it to create a binary tree from a string of letters (like A, B, and so on) entered by the user. Each letter will be displayed in its own node. Construct the tree so that all the nodes that contain letters are leaves. Parent nodes can contain some non-letter symbol like +. Make sure that every parent node has exactly two children....
Start with the tree.java program (Listing 8.1) and modify it to create a binary tree from a string of letters (like A, B, and so on) entered by the user. Each letter will be displayed in its own node. Construct the tree so that all the nodes that contain letters are leaves. Parent nodes can contain some non-letter symbol like +. Make sure that every parent node has exactly two children. Don’t worry if the tree is unbalanced. Note that...
I need help to write this code in C++, I am struggling to find
max node's parent's right child and max node's left child.
Node* maxValueNode(Node* node)
{
Node* current = node;
while (current && current->right !=
NULL)
current = current->right;
return current;
}
void deleteNode(BST* tree, Node* node, Node* parent)
{
//TODO - follow the lecture pseudocode to write the
deleteNode function
// - returns true if the value was deleted, false if
not
// - don't forget to...
Removing Nodes from a Binary Tree in Java This section requires you to complete the following method within BinaryTree.java: public void remove(K key) { } The remove method should remove the key from the binary tree and modify the tree accordingly to maintain the Binary Search Tree Principle. If the key does not exist in the binary tree, no nodes should be removed. In case there is a non-null left child, it should take the place of the removed node....
Professionally and thoroughly comment on this code. //BinarySearchTree.java package Project.bst; //imports required import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; class BSTTreeNode{ BSTTreeNode left, right; String data; public BSTTreeNode(){ left = null; right = null; data = null; } public BSTTreeNode(String n){ left = null; right = null; data = n; } public void setLeft(BSTTreeNode n){ left = n; } public void setRight(BSTTreeNode n){ ...