EBK STARTING OUT W/JAVA:...DATA...
4th Edition
ISBN: 9780134757179
Author: GADDIS
Publisher: PEARSON CO
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 21, Problem 1MC
Program Description Answer
A binary tree is a collection of nodes in which each node “has at most two successors”.
Hence, the correct answer is option “D”.
Expert Solution & Answer
Explanation of Solution
Binary tree:
- Binary tree is a hierarchical structure to represent the data. The element of the tree is called as a node or item.
- Here, the branches are used to connect the nodes.
- Each node may have zero, one, or two children.
- A node that does not have a superior node is called the root node.
- The root node is the starting node, and it is the ancestor for all other nodes in the tree.
- The set of children node in a binary tree form a subtree rooted at that node.
- A node that does not have a children is called as a leaf node or an end node.
Explanation for incorrect options:
Has no successor:
A binary tree may have zero, one, or two successor node. So, it cannot be predicted that a binary tree has no successor.
Hence, option “A” is wrong.
Has one successor:
A binary tree may have zero, one, or two successor node. So, it cannot be predicted that a binary tree has one successor.
Hence, option “B” is wrong.
Has exactly two successors:
A binary tree may have zero, one, or two successor node. So, it cannot be predicted that a binary tree has exactly two successors.
Hence, option “C” is wrong.
Want to see more full solutions like this?
Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Create class node.Create class Binary tree: Implement Insertion and search function in it. Implement Pre-order, In-order, Post-order Traversals Recursively. Create Binary Search Tree Class: Override Insert and search functions in it. In Main: Create objects of Both the trees and access their insertion searching, Delete and traversal functions.
1. Create a Java program that prompts the user the initial choices for the Binary Search Treea. User chooses
1: Insert, User chooses
2: Delete, User chooses
3: Show BinaryTree, User chooses
4: Exit Program
2. Insertion in a tree should be such that it obeys the main properties of the binary searchtree. The basic algorithm should be:a. If the node to be inserted is greater than the existing root, move down a levelthrough the right pointer of the root.b. If the node to be inserted is lesser than the existing root, move down a levelthrough the left pointer of the root.c. Repeat this process for all nodes till the leaves are reached.d. Insert the node as the left or right pointer for the leaf (based on its value - if it issmaller than the leaf, it should be inserted as the left pointer; if it is larger than theleaf, it should be inserted as the right pointer)
3. Deletion is a bit more complicated than insertion because it varies depending on the nodethat needs to be deleted from the…
}
20. In a binary search tree, the immediate predecessor of a given node is the largest node in its left subtree.
For example, the immediate predecessor of node 25 in the following tree is 23 while it is 15 for node 16.
Nodes 21 and 39 do not have an immediate predecessor because none of them has a left child.
25
/ 1
Write a non-recursive method immediate Predecessor, which takes a
BSTNode parameter node (a reference to a node in a binary search tree)
and returns a reference to its immediate predecessor in the tree. If node is
null or it does not have an immediate predecessor, the method returns
null.
public class BSTNode
4
{
private int m_info;
private BSTNode m_left;
private BSTNode m_right;
public int getInfo() {return m_info; }
public void setInfo (int value) {m_info
= info; }
public BSTNode getLeft () {return m_left; }
public void setLeft (BSTNode left) (m_left = left; }
public BSTNode getRight () {return m_right;}
public void setRight (BSTNode right) {m_right
= right;}
}
public…
Chapter 21 Solutions
EBK STARTING OUT W/JAVA:...DATA...
Ch. 21.1 - Prob. 21.2CPCh. 21.1 - Prob. 21.3CPCh. 21 - Prob. 1MCCh. 21 - Prob. 2MCCh. 21 - Prob. 3MCCh. 21 - Prob. 4MCCh. 21 - Prob. 5MCCh. 21 - Prob. 6MCCh. 21 - Prob. 7MCCh. 21 - Prob. 8MC
Ch. 21 - Prob. 9MCCh. 21 - Prob. 10MCCh. 21 - Prob. 11TFCh. 21 - Prob. 12TFCh. 21 - Prob. 13TFCh. 21 - Prob. 14TFCh. 21 - Prob. 15TFCh. 21 - Prob. 16TFCh. 21 - Prob. 17TFCh. 21 - Prob. 18TFCh. 21 - Prob. 19TFCh. 21 - Prob. 20TFCh. 21 - Prob. 21TFCh. 21 - Prob. 1FTECh. 21 - Prob. 2FTECh. 21 - Prob. 3FTECh. 21 - Prob. 1SACh. 21 - Prob. 2SACh. 21 - Prob. 3SACh. 21 - Prob. 4SACh. 21 - What is a priority queue?Ch. 21 - Prob. 6SACh. 21 - Prob. 7SACh. 21 - Prob. 1AWCh. 21 - Prob. 2AWCh. 21 - Prob. 3AWCh. 21 - Prob. 4AWCh. 21 - Prob. 5AWCh. 21 - Prob. 6AWCh. 21 - Prob. 7AWCh. 21 - Prob. 4PCCh. 21 - Prob. 6PC
Knowledge Booster
Similar questions
- Create a binary linked tree, and traverse the tree by using the recursive function. The structure of the tree is as follow: You should input the nodes in pre-order sequence. If a child of a node is NULL, input a space. Write the function of create binary tree, pre-order to print the nodes, in-order to print the nodes and post-order to print the nodes. Count the height of the tree. Header file typedef char ElemType; typedef struct node//define the type of binary tree node { }BTnode; Source file #include <stdio.h> #include <stdlib.h> #include "tree.h" BTnode * createTree()//create the binary tree,return the root { BTnode *tnode;// tnode is the root char elem; ;//input the character //if the input is a space,set the pointer as NULL Else// if the input is not a space,generate the binary node and create its left sub-tree and right…arrow_forwardComputer Science Binary Search Tree Implement Binary search Tree (BST) and perform the following operations a. Insert the keys 11,66, 6,9,40,28,5, 88,125,90 b. Print the keys in sorted order using suitable traversal method. C. Search for a key x and prints its address if it is present. d. Compute height of the BST e. Print successor/predecessor of a given key f. Delete the keys 40 and 88 one by one and print the tree in level order after each delete. Note: use only recursive functions for all the operations. Write the c code with proper comments.arrow_forward1. Create a Java program that prompts the user the initial choices for the Binary Search Treea. User chooses 1: Insert, User chooses 2: Delete, User chooses 3: Show Binary Tree, User chooses 4: Exit Program 2. Insertion in a tree should be such that it obeys the main properties of the binary search tree. The basic algorithm should be: a. If the node to be inserted is greater than the existing root, move down a level through the right pointer of the root. b. If the node to be inserted is lesser than the existing root, move down a level through the left pointer of the root. c. Repeat this process for all nodes till the leaves are reached. d. Insert the node as the left or right pointer for the leaf (based on its value - if it is smaller than the leaf, it should be inserted as the left pointer; if it is larger than the leaf, it should be inserted as the right pointer) 3. Deletion is a bit more complicated than insertion because it varies depending on the node that needs to be deleted…arrow_forward
- The data types of binary tree are defined as follows. Write a recursive function "int CounDegreeTwo( BiTree T )" which count the number of nodes with degree 2 in a binary tree. struct BiTreeNode { ElementType Element; struct BiTreeNode *Left; struct BiTreeNode *Right; }; typedef struct BiTreeNode *Position , *BiTree;arrow_forward21. A B-tree of order m has maximum of _____________ children. a. m b. m+1 c. m-1 d. m/2arrow_forwardWhen inorder traversing a complete binary tree resulted E A C K F H D; the postorder traversal would return Select one: a.E C A F H D K b.E C A F D H K c.E A C F D H K d.E C F A D H Karrow_forward
- 29. A binary search tree where each node has either 0 or 1 subtrees is said to be a. Perfect b. Balanced c. Degenerate d. Complete 30. A binary search tree where the nodes at all levels except the lowest are filled, and at the lowest level, the values are filled from left to right is said to be a. Perfect b. Balanced c. Degenerate d. Complete 31. logic_error, runtime_error, syntax_error and bad_cast are all examples of standard C++ exceptions. a. True b. False 32. All standard exceptions in C++ are derived from the exception class. a. True b. False 33. User defined exception classes can be created by deriving the class from the exception class and overriding the "error_message" function. a. True b. False 34. A data structure where elements are processed in the same order in which they are added to the container is known as a a. Stack b. Queue c. Linked list d. Deque 35. A data structure where elements are processed in the opposite order in which they are added to the container is known…arrow_forwardUsing c# , Write a constructor for the binary search tree class that accepts a sorted list L and builds aperfectly balanced binary search tree. Because constructors cannot be recursive, anothermethod called Build must be defined to carry out the actual construction of the tree.arrow_forward11. From the following trees, select the balanced BSTS: (A BST is balanced if the height of its left and right sub-trees are different by at most one, recursively applied.) A. M D R B. A 6 10 38 55 64 P 72 91 W 92 z 123arrow_forward
- In JAVA code Write an algorithm for deleting a node of a Binary Search Tree. Take note that the Binary Search Tree property must be satisfied after a node is removed from a Binary Search Tree.arrow_forwardQ4: Is BST Write a function is_bst, which takes a Tree t and returns True if, and only if t is a valid binary search tree, which means that: Each node has at most two children (a leaf is automatically a valid binary search tree) The children are valid binary search trees • For every node, the entries in that node's left child are less than or equal to the label of the node • For every node, the entries in that node's right child are greater than the label of the nodearrow_forwardBST - Binary Search Tree - implement a BSTNode ADT with a data attribute and two pointer attributes, one for the left child and the other for the right child. Implement the usual getters/setters for these attributes -implement a BST as a link-based ADT whose data will be Dollar objects - the data will be inserted based on the actual money value of your Dollar objects as a combination of the whole value and fractional value attributes. - BST, implement the four traversal methods as well as methods for the usual search, insert, delete, print, count, isEmpty, empty operations and any other needed. - BST - Binary Search Tree - implement a BSTNode ADT with a data attribute and two-pointer attributes, one for the left child and the other for the right child. Implement the usual getters/setters for these attributes -implement a BST as a link-based ADT whose data will be Dollar objects - the data will be inserted based on the actual money value of your Dollar objects as a combination of the…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education