Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 19, Problem 12RQE
Program Plan Intro
Binary tree:
- Binary tree is a non-linear data structure.
- Binary tree contains node such as root node that is pointed to two child nodes.
- A root node will have left reference node and right reference node.
- Binary tree will contain more than one self-referenced field.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Implement a binary search tree and write a function to determine if it is a valid binary search tree.
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…
Construct a Binary Search Tree (BST) using the data provided in shaded row and name it “BST-1”.
50
45
65
60
75
90
15
35
70
45
55
40
20
80
95
85
25
50
74
5
Provide answers to the following considering your constructed BST-1:
Write a C++ code for the in-order traversal of BST-1. Also, dry run your code on it and elaborate its each step.
Compute the total number of used and unused (null) references defined in BST-1. And construct an equivalent two-way in-order threaded BST-1 that has minimum number of null references.
Chapter 19 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 19.1 - Prob. 19.1CPCh. 19.1 - Prob. 19.2CPCh. 19.1 - Prob. 19.3CPCh. 19.1 - Prob. 19.4CPCh. 19.1 - Prob. 19.5CPCh. 19.1 - Prob. 19.6CPCh. 19.2 - Prob. 19.7CPCh. 19.2 - Prob. 19.8CPCh. 19.2 - Prob. 19.9CPCh. 19.2 - Prob. 19.10CP
Ch. 19.2 - Prob. 19.11CPCh. 19.2 - Prob. 19.12CPCh. 19 - Prob. 1RQECh. 19 - Prob. 2RQECh. 19 - Prob. 3RQECh. 19 - Prob. 4RQECh. 19 - Prob. 5RQECh. 19 - Prob. 6RQECh. 19 - Prob. 7RQECh. 19 - Prob. 8RQECh. 19 - Prob. 9RQECh. 19 - Prob. 10RQECh. 19 - Prob. 11RQECh. 19 - Prob. 12RQECh. 19 - Prob. 13RQECh. 19 - Prob. 14RQECh. 19 - Prob. 15RQECh. 19 - Prob. 16RQECh. 19 - Prob. 17RQECh. 19 - Prob. 18RQECh. 19 - Prob. 19RQECh. 19 - Prob. 20RQECh. 19 - Prob. 1PCCh. 19 - Prob. 2PCCh. 19 - Prob. 3PCCh. 19 - Prob. 4PCCh. 19 - Prob. 5PCCh. 19 - Prob. 6PCCh. 19 - Prob. 7PCCh. 19 - Prob. 8PCCh. 19 - Prob. 9PCCh. 19 - Prob. 10PC
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 follows: //check pic// 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. Hints: 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…arrow_forward4. a) The preorder traversal of a Binary Search Tree (BST) is given below. 75 55 45 50 60 65 95 85 110 100 Draw the BST and briefly explain the process you followed to build the tree. b) Write a function f1 that takes the root of a binary tree as a parameter and returns the sum of the nodes, which are the right child of another node. The root of the tree is not a child of any node. Consider the following class definitions while writing your code. class Node { public: int key; Node* left; Node* right; } ;arrow_forwardPLEASE PROVIDE ME THE CODE IN C LANGUAGE.arrow_forward
- Create a function that checks whether a binary tree is balanced. For the sake of this issue, a balanced tree is one in which the heights of the two subtrees of each node never deviate by more than one.arrow_forwardBuild a Binary Search Tree with the given input order. You must show step by step process of inserting the inputs including both recursive calls and tree diagrams for each step. [ refer to the Insertitem function of Lecture 10 slides to get an idea of doing this.] N.B: Unique Input orders for each student to build the tree are given on a separate file. Write down the input order on your answer script before answering the question. You must use the assigned input order. Do not change the order. TREE INPUT: 4,1,9,3,2,5,6,8,7arrow_forwardb. Given a BST whose root node is represented by the node root. Write a function findroots(Node * root) to traverse the BST and print the number of total parent (atleast have a child node) nodes of the BST. N.B: Print order doesn't matter Fig 1: An example Binary Search Tree. 5 For example: In this figure, there are total 4 parentsarrow_forward
- Construct a Binary Search Tree (BST) using the data provided in shaded row and name it “BST-1”. 50 45 65 60 75 90 15 35 70 45 55 40 20 80 95 85 25 50 74 5 Provide answers to the following considering your constructed BST-1: Write a C++ code that finds and delete a node having exactly two Childs in a BST. Simulate your code on BST-1 and provide a step-by-step procedure to delete “15” and “75” from it.arrow_forwardCreate a function that rapidly identifies whether any two nodes u and v in a tree T with s as the root node are ancestors or descendants of each other.arrow_forwardAnswer the following questions using python and without using any of its libraries or OOP . a) Using the helper function insert (bst, key), create the binary search tree that results from inserting the following keys in the order given: 68, 88, 61, 89, 94, 50, 4, 76, 66, and 82. b) Using the helper function exist (bst, key), check whether key 50 exists in resultant Binary Search Tree. c) Using the helper function exist (bst, key), check whether key 49 exists in resultant Binary Search Tree. d) Using the helper function minimum (bst, starting_node), find the node with the minimum value in resultant Binary Search Tree from starting node = 68. e) Using the helper function minimum (bst, starting_node), find the node with the minimum value in resultant Binary Search Tree from starting node = 88. f) Using the helper function maximum (bst, starting_node), find the node with the maximum value in resultant Binary Search Tree from starting node = 68. g) Using the helper function maximum (bst,…arrow_forward
- 1. A Binary Search Tree (BST) is a binary tree where each node contains a value from a well-ordered set. (a) Draw a BST for each of the following set of data: i. 20, 30, 45, 31, 19, 15, 18, 13, 50, 21 i. М, О, R, T, С, F, E, A, S, N, Qarrow_forwardb. Given the array representation of a binary tree (null value means the node is empty]: [null, P, T, X, null, S, Q, U, null, null, Y, W, R, null, null, VM i. Draw the binary tree. [2]arrow_forwardGiven a pre-order traversal of a binary search tree(BST) and a range,say [x,y], write a program that constructs a binary tree with the giventraversal and then removes all the nodes for which the values are inthe given range maintaining the BST nature of the tree with necessarychanges/modifications. You may assume that the ‘pre-order’ traversalgiven initially as input is a valid one and need not verify that.Input: The input should be a ‘pre-order’ traversal of a binary search treeand two values which are the non-negative bounds of the range.Output: The output should be a the ‘pre-order’ traversal of the modifiedbinary tree with no nodes in that range. Write using C programming.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