Question

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 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;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

  • The Big oh notation for running time and space complexity for the following method (splay or zigZig):

Time complexity in Average case:   O (log N)

Time complexity in Worst case:      O (log N)

Space complexity in Worst case:     O (N)

  • The Big oh notation for running time and space complexity for the following method (findSplay):

Time complexity in Average case:   O (log N)

Time complexity in Worst case:      O (log N)

Space complexity in Worst case:     O (N)

  • The Big oh notation for running time and space complexity for the following method (putSplay):

Time complexity in Average case:   O (log N)

Time complexity in Worst case:      O (log N)

Space complexity in Worst case:     O (N)

  • The Big oh notation for running time and space complexity for the following method (eraseSplay):

Time complexity in Average case:   O (log N)

Time complexity in Worst case:      O (log N)

Space complexity in Worst case:     O (N)

Add a comment
Know the answer?
Add Answer to:
Please provide the big oh notation for running time and space complexity for the following methods...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please provide the big oh notation for running time and space complexity for the following functions...

    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...

    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; }...

  • Q. write the algorithm for each function in this code: void insert(int x, node*&p) { //cheak...

    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...

    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)...

    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....

  • I need help to write this code in C++, I am struggling to find max node's parent's right child and max node&#39...

    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...

    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....

  • From the code below with Binary Search Tree recurrence T(n)=? use the recursion method and substitution method to solve the recurrence. Find the tightest bound g(n) for T(n) you can for which T(n)= O(...

    From the code below with Binary Search Tree recurrence T(n)=? use the recursion method and substitution method to solve the recurrence. Find the tightest bound g(n) for T(n) you can for which T(n)= O(g(n)). Explain your answer and use recursion tree method. void insert(int data) { struct node *tempNode = (struct node*) malloc(sizeof(struct node)); struct node *current; struct node *parent; tempNode->data = data; tempNode->leftChild = NULL; tempNode->rightChild = NULL; //if tree is empty if(root == NULL) { root = tempNode;...

  • Lab 6 Help

    I need help with this lab assignment. I use C++, thank you. Derive a MinHeap class from the BST class of your Lab 4 code.Define/Override only the Search/Insert/Delete methods in the new class.Write a new main for this lab which:Will only be a test program for the MinHeap.Declares and creates a MinHeap object as necessary.Declares and creates the Dollar objects as necessary.Inserts the 20 Dollar objects specified in Lab 4 in the same order.Performs all 4 traversals after the inserting...

  • Add printRang method to BST.java that, given a low key value, and high key value, print...

    Add printRang method to BST.java that, given a low key value, and high key value, print all records in a sorted order whose values fall between the two given keys. (Both low key and high key do not have to be a key on the list). BST.java import java.lang.Comparable; /** Binary Search Tree implementation for Dictionary ADT */ class BST<Key extends Comparable<? super Key>, E> implements Dictionary<Key, E> { private BSTNode<Key,E> root; // Root of the BST int nodecount; //...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT