Please help this.
Q. When is the right subtree of a binary tree processed before the left?
When using an inorder traversal algorithm.
When using a preorder traversal algorithm.
When using a postorder traversal algorithm.
Never. The left always goes before the right in the standard traversal algorithms.
Q. In a postorder tree traversal, each node is processed ____ its children.
instead of
after
before
relative to the ordinal values of
Q17. If you have an array of 4,000 sorted data items, about how many comparisons will it take for a binary search to discover that a certain value is not present?
64
4000
12
It depends on where the value would fall in the array.
Q. Which of the following statements is true about this recursive function?
long f(int n)
{ return n * f(n - 1);
}
A) Invoking f(1) returns 1.
B) Invoking f(0) returns 0.
C) This function works perfectly for all n > 0.
D) The function runs infinitely and causes a crash.
Q. A binary tree whose left and right subtrees are similar in height is said to be ________.
inefficient
abstract
fictitious
balanced
1) Never. The left always goes before the right in the standard traversal algorithms.
Reason --->
Inorder traveral = (left, root, right)
Preorder traversal = (root, left, right)
Postorder traversal = (left, right, root)
none of the standard traversal algorithm process right before the left.
2) after
Reason ---> Postorder traversal = (left, right, root)
the children are processed before the root node.
3) It will take 12 comparisons to check if a certain value is not present.
Reason ---> In binary search, worst case is when you search for a value which is lower than first element or greater than last element because we compare the element we are searching with middle element of any range.
Approxiamte number of comparisons = = 12
4) D) The function runs infinitely and causes a crash.
Reason ---> there are no end condition to stop the recursion. To stop or to correct the function should be like :
long f(int n) {
if(n == 0) return 1;
else return n * f(n-1);
}
5) Balanced binary tree has left and right subtree of similar height.
Reason ---> By definition, Balanced binary tree has "minimum possible maximum height"
i.e min(maximum height of tree containing x no. of nodes) is the one which is Balanced Binary Tree.
Please help this. Q. When is the right subtree of a binary tree processed before the...
QUESTION 8 In the _____ traversal, the root is processed first, before its subtrees. breadth first preorder postorder inorder 0.10000 points QUESTION 9 What kind of traversal does the following algorithm (in pseudo-code) describe? Algorithm traversal (root) if (root is not null) traversal (leftSubTree) process (root) traversal (rightSubTree) end if end traversal breadth first preorder inorder postorder 0.10000 points QUESTION 10 What kind of traversal does the following algorithm (in pseudo-code) describe? Algorithm traversal (root) if...
Can someone help with these two problems? The following binary tree contains the characters 'A' through 'G' in its nodes. List the nodes in the order that they are visited by: A preorder traversal. An inorder traversal. A postorder traversal. The binary tree in Problem 2 is a Binary Search Tree since for every node, all elements stored in the left subtree of the node are smaller than the element in the node and all elements stored in the right...
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...
In Java. How would this method look? LinkedBinaryTree.java import java.util.Iterator; public class LinkedBinaryTree implements BinaryTreeADT { private BinaryTreeNode root; /** * Creates an empty binary tree. */ public LinkedBinaryTree() { root = null; } /** * Creates a binary tree from an existing root. */ public LinkedBinaryTree(BinaryTreeNode root) { this.root = root; } /** * Creates a binary tree with the specified element...
Write a function, swapSubtrees, that swaps all of the left and right subtrees of a binary tree. Add this function to the class binaryTreeType and create a program to test this function. #include <iostream> using namespace std; //Definition of the Node template <class elemType> struct nodeType { elemType info; nodeType<elemType> *lLink; nodeType<elemType> *rLink; }; //Definition of the class template <class elemType> class binaryTreeType { public: //Overload the assignment operator. const binaryTreeType<elemType>& operator=(const binaryTreeType<elemType>&) { if (this != &otherTree) //avoid self-copy...
Please address all the questions on the photo. 5. Consider the following binary tree: A B C E F e De G H. K . M NO RO P Q T a. What is the height of the tree? b. What is the height of vertex H? c. Write the preorder traversal representation of the tree. d. Write the array representation of the tree by completing the following table: Right Child Left Child Vertex A C D G H K...
JAVA CODE Topic: BST Animation For each task, submit the source code with detail comments. Objective: javafx GUI program for BST Animation. BSTAnimation.java, AbstractTree.java and Tree.java. Modify the BSTAnimation.java (1) Add Show Preoreder and Show Postorder button. Insert these two buttons next to the Show Inorder button to display tree in selected order. (2) Currently removing node method is to replace the removed node by the highest node on left-subtree. Modify the method by using lowest node on the right-subtree instead....
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...
write a new test program called RemoveDuplicates.java. The program reads text input from keyboard or a text file and adds the words to a BST. The program then traverses the BST and prints out the words in order (based on ASCII/UNICODE order) on the screen (or to output text file). Note that you may need to make some changes to BST.java. Sample test: ----jGRASP exec: java -ea removeDuplicates Original Text: a B 2 n w C q K l 0...