Answer A->
In tree there are at most n nodes. It is right chained so it is having 1 leaf node and n-1 parent nodes.
So to get right chained binary tree from binary tree.Take right most element as leaf node
and then for every parent if it has left child make parent as right child of its left child by right rotation.In case if left child is already having right child then there is left rotation is done I am giving you example to solve this problem
So, there can be at most rotation for each parent node
So each time parent will become right child of its left child in right rotation.
parent will become left child of its right child in left rotation.So there are at max 1 rotation is required to make a parent to child.
Answer 2->If you are having right chained binary tree.You need p rotation to make x as root where p is total number ancestors of x.To make root we will need to perform p left rotation .example is shown in below picture
Answer c-> To transform Tree T1 to T2 we need left and right rotation accordingly. We need to reverse back all operations of b and a to get back the tree
Algorithm ->
as we know the depth can be more so , we need to first go till leaf node so that roatation can be performed
function (btree):
if btree->leftchild
function(btree->leftchild);
roatate_right(btree)
else if btree->leftchild=NULL and btree->rightchild
rotate_left(btree)
rotate_left ( btree ):
btree->leftchild=btree->leftchild->rightchild
btree->leftchild->rightchild=btree;
rotate_right ( btree ):
btree->rightchild=btree->rightchild->leftchild
btree->rightchild->leftchild=btree;
These rotation are same as AVL tree.
If you have any doubt.Please feel free to ask.Thanks
Problem 2 [35 points (155 15)]: Let Ti and T2 be two binary search trees containing the same elem...
*****************************In Java***************************************In Java***********************************In Java************************* In this problem, you will implement various algorithms operating on binary search trees. We have provided with you a standard implementation of a generic BST in BinarySearchTree.java. Note that this class is an abstract class, which means that some of its methods are not implemented. In previous assignments, you have implemented interfaces which specified methods that you needed to write. Very similarly, an abstract class is a class with some unimplemented methods (it can be thought...
C++ Binary Search Tree question. I heed help with the level 2 question please, as level 1 is already completed. I will rate the answer a 100% thumbs up. I really appreciate the help!. Thank you! searching.cpp #include <getopt.h> #include <iostream> #include <sstream> #include <stdlib.h> #include <unistd.h> using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree //...
C++ Binary Search Tree question. I heed help with the level 2 question please, as level 1 is already completed. I will rate the answer a 100% thumbs up. I really appreciate the help!. Thank you! searching.cpp #include <getopt.h> #include <iostream> #include <sstream> #include <stdlib.h> #include <unistd.h> using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree //...
1) Extend the Binary Search Tree ADT to include a public method leafCount that returns the number of leaf nodes in the tree. 2) Extend the Binary Search Tree ADT to include a public method singleParent-Count that returns the number of nodes in the tree that have only one child. 3) The Binary search tree ADT is extended to include a boolean method similarTrees that receives references to two binary trees and determines whether the shapes of the trees are...
Please I need help ASAP Java Programing: Binary Search Tree Fully implement the BST class in Listing 25.4 (on page 961 of the 11th Edition of the text). Design and write a (main) driver program to completely test every method in the BST class to ensure the class meets all its requirements. You should read the Listing 25.5: TestBST.java for an idea of what your program should look like. Listing 25.4 BST.java public class BST> extends AbstractTree { protected TreeNode...
For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...
JAVA 3 PLEASE ANSWER AS MANY QUESTIONS AS POSSIBLE! ONLY 2 QUESTIONS LEFT THIS MONTH!!! Question 12 pts Which is a valid constructor for Thread? Thread ( Runnable r, int priority ); Thread ( Runnable r, String name ); Thread ( int priority ); Thread ( Runnable r, ThreadGroup g ); Flag this Question Question 22 pts What method in the Thread class is responsible for pausing a thread for a specific amount of milliseconds? pause(). sleep(). hang(). kill(). Flag...