Solution:
(32)
=>Node to be inserted = 62
The answers will be:
left of right: left
node: 64
Explanation:
=>In binary search tree(BST) a node with value less than node is inserted at the left part of root otherwise right part of the node.
=>The above property is being followed for every node of the tree.
=>62 > 50 hence it will be inserted at the right side of 50.
=>62 < 70 hence it will be inserted at the left side of 70.
=>62 > 60 hence it will be inserted at the right side of 60.
=>62 < 65 hence it will be inserted at the left side of 65.
=>62 < 64 hence it will be inserted at the left side of 64.
(33)
The answers will be:
Predecessor: 40
Successor: 60
Explanation:
Finding predecessor of 50:
=>Predecessor of a node is the maximum value in the left subtree of that node.
=>Precessor of 50 = 40
Finding successor of 50:
=>Successor of a node is the minimum value in the right subtree of that node.
=>Successor of 50 = 60
(34)
=>Successor is used for deleting the nodes.
=>Nodes to be deleted in order = 80, 40, 50
Explanation:
I have explained each and every part with the help of statements as well as images attached to the answer above.
package hw3; import java.util.LinkedList; /* *********************************************************************** * A simple BST with int keys and no values * * Complete each function below. * Write each function as a separate recursive definition (do not use more than one helper per function). * Depth of root==0. * Height of leaf==0. * Size of empty tree==0. * Height of empty tree=-1. * * TODO: complete the functions in this file. * DO NOT change the Node class. * DO NOT change the name...
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...
QUESTION 9 Consider the following binary search tree: If the root node, 50, is deleted, which node will become the new root? A 15 B 24 C 37 D 62 QUESTION 10 In the following trees EXCEPT______, the left and right subtrees of any node have heights that differ by at most 1. A complete trees B perfect full trees C balanced binary trees D binary search trees QUESTION 11 A perfect full binary tree whose height is 5 has...
P $70 $65 $60 $55 $50 ATC $45 $40 $35 AVC MR $30 $25 $20 $15 $10 $5 01234 56789 10 11 12 13 14 Based on the graph above, what is the profit maximizing price? o $45 $25 $5 S40 O $20 $10 $70 $50 S60 $65 S55 SI5 S30 $35
80 75 70 65 60 55 50 45 40 35 30 25 20 D2 S Price of TV Remote in Dollars D1 0 20 40 60 80 100 120 140 160 Quantity of TV Remotes The above graph shows the supply curve and 2 possible demand curves for a perfectly competitive, constant cost TV remote market. Assume the demand curve is initially D1 and the market is in long run equilibrium. Now assume a very popular new TV show comes...
Write a C++ program to validate computer user-ids and passwords. A list of valid ids and passwords (unsorted) is read from a file and stored in a Binary Search Tree (BST) of UserInfo objects. When user-ids and passwords are entered during execution, this BST is searched to determine whether they are legal. Input (file): UserInfo records for valid users Input (keyboard): Ids and passwords of users logging in Output (screen): Messages indicating whether user-ids and passwords are valid, as well...
Assignment on Java programing 1. Write programs for the following exercises in Java. Each file should have short description of the implemented class and for files with main method the problem it is solving. Make sure your files have appropriate names. Programs should write output to the Console. b) BST: Implement Binary Search Tree ADT with insert(int key), delete(int key), Node find(int key), and in-order traverse() where it prints the value of the key. Your operations should use recursion. The...
30 25 20 Pwfl+t) 15 Pw 10 0 10 20 30 40 50 60 70 80 90 100 Q -jets Suppose the world market price of jets is P 10 but that economic policy initia What is the closed economy market equilibrium price and quantity of of jets? P all jet If imports are allowed at Pr = 10 , how many jets would be imported? o and domestic produced supply indicate domestic demand on the horizontal axis on the...
Willy's widgets, a monopoly, faces the following demand schedule (sales of widgets per month): Price $20 30 40 50 60 70 80 90 100 Quantity 40 35 30 25 20 15 10 5 0 Calculate marginal revenue over each interval in the schedule (for example, between Q = 40 and Q=35). Recall that the revenue is the added revenue from an additional unit of production/sales and assume MR is constant within each interval. If marginal cost is constant at $20...