STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 19, Problem 4PC
Program Plan Intro
Tree Height
Program Plan:
- Define a class BTreeNode to create nodes for binary search tree items.
- Include all the required header files.
- Initialize a value to the node, and set the left child of node to leftp and right child of node to rightp .
- Define a class to create a Binary Search Tree.
- Create a function int height that returns height of the tree.
- Create a function bool search to search a particular item in tree.
- Create function void insert to insert nodes into the tree.
- Create a function leafCount that counts no. of leaves present in a level.
- Create a function void inorder to sort items in inorder traversal.
- Declare the main function.
- Prompt the user to enter 5 numbers to be inserted into tree.
- Sort the items present in the tree in inorder traversal and return the height of the Binary Search Tree.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
By python
Recursive function tracing: drawing Recursion Tree for Smallest(a, 0, 6), where vector a contains the following numbers: a = {4, 5, 10, 1, 20, 23, 2}.
• clearly label each recursive call’s parameters• clearly label what each call returns to its caller
//Return smallest element in sublist a[first...last] int Smallest (vector<int> a, int first, int last){
if (first==last) return a[first]; mid = (first+last)/2; //integer division l1 = Smallest(a, first, mid); l2 = Smallest (a, mid+1, last); if (l1>l2) return l2; else return l1;
}
Data Structure and algorithms ( in Java )
Please solve it urgent basis:
Make a programe in Java with complete comments detail and attach outputs image:
Question is inside the image also:
a). Write a function to insert elements in the sorted manner in the linked list. This means that the elements of the list will always be in ascending order, whenever you insert the data. For example, After calling insert method with the given data your list should be as follows:
Insert 50 List:- 50
Insert 40 List:- 40 50
Insert 25 List:- 25 40 50
Insert 35 List:- 25 35 40 50
Insert 40 List:- 25 35 40 40 50
Insert 70 List:- 25 35 40 50 70
b). Write a program…
Chapter 19 Solutions
STARTING OUT WITH C++ MPL
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
- ] ] is_proper You are to write a function is_proper(graph,color) that has two inputs: one a graph, and the other a labelling of the vertices, and determines whether or not the labelling is a proper vertex-coloring of the given graph. In other words, return the Boolean value True if it is, and False if it is not. After compiling the above cell, you should be able to compile the following cell and obtain the desired outputs. print (is_proper({"A": ["B", "C"], "B": ["A", "C"], "C": ["A", "B"]}, {"A": 1, "B": 2, "C": 3}), is_proper({"A": ["B", "C"], "B": ["A", "C"], "C": ["A", "B"]}, {"A": 1, "B": 1, "C": 3})) This should return True False Python Pythonarrow_forwardquick Solution pleasearrow_forwardA BST is constructed in the usual way using the node definition below. Write a function int child2( bst node t *curr) that returns the number of nodes that have 2 children. typedef struct BST NODE T {int data;struct BST NODE T *left, *right; } bst node t; int child2( bst node t *curr){ }arrow_forward
- Recursive Multiplication Given an JavaScript object list of books that each have a pages attribute to define the number of pages in the book, find the product of all the pages in the object list of books using recursion (you must use recursion to solve this problem). Keep in mind: The input list object may be completely empty (ex. {}) The next attribute may not be defined function getPageCount(list) {// your code here// returns an integer}Example test case:Input: {"book":"A","pages":1,"next":{"book":"B","pages":2,"next":{"book":"C","pages":3,"next": null}}}Output: 6Reasoning: 1 * 2 * 3 pagesarrow_forwardMake sure the program run smooth and perfectly, make sure no error encounter. compatible for python software. Complete the sample code template to implement a student list as a binary search tree (BST).Specification1. Each Studentrecord should have the following fields: =studentNumber =lastname =firstName =course =gpa2. Run the program from an appropriate menu allowing for the following operations:* Adding a Student record * Deleting a Student record * Listing students by: • All students • A given course • GPA above a certain value • GPA below a certain value class Record:def __init__(self, studentNumber = None, lastname = None, firstName = None, course = None, gpa =None,):self.studentNumber = studentNumberself.lastname = lastnameself.firstName = firstNameself.course = courseself.gpa = gpadef __str__(self):record = "\n\nStudent Number : {}\n".format(self.studentNumber)record += "Lastname : {}\n".format(self.lastname)record += "FirstName : {}\n".format(self.firstName)record…arrow_forward] ] is_bipartite In the cell below, you are to write a function "is_bipartite (graph)" that takes in a graph as its input, and then determines whether or not the graph is bipartite. In other words, it returns True if it is, and False if it is not. After compiling the above cell, you should be able to compile the following cell and obtain the desired outputs. print (is_bipartite({"A" : ["B", "C"], "B" : ["A"], "C" : ["A"]}), is_bipartite({"A" : ["B", "C"], "B" : ["A", "C"], "C" : ["A", "B"]})) This should return True False Python Pythonarrow_forward
- Computer Science JAVA Write a program that maintains the names of your friends and relatives and thus serves as a friends list. You should be able to enter, delete, modify, or search this data. You should assume that the names are unique. use a class to represent the names in the friends list and another class to represent the friends list itself. This class should contain a Binary Search Tree of names as a data field. (TreeNode Class BinarySearchTree Class FriendsList Class)arrow_forwardMaze Runner Function - Implementation of this function is done in a1_partd.py We describe a maze as having row x col cells. For example if row was 3, and col was 4, then we would have a grid of cells as follows. We describe a wall by the two cell numbers the wall separates. If every single wall existed, there would be (row-1)(col) + (col-1)(row) walls. 0 | 1 | 2 | 3 4 | 5 | 6 | 7 8 | 9 | 10 | 11 A Maze class (which you do not need to implement) describes a maze as mentioned above. This class is defined in maze.py. It has methods that you can use to travel through the maze (i.e. figure out where you are, find a neighbour cell etc.) use a recursive maze runner function: def find_path(maze, from_cell, to_cell); The find_path function will find a path from cell number from_cell to cell number to_cell and will return it as a list containing all the cell numbers along the path, from the from_cell to the to_cell. You are allowed to use this function as a wrapper to a recursive function that…arrow_forwardin c++, write a function to find the height of a specific node in a Binary Search Tree.arrow_forward
- Recursive Count Write a recursive function rc_count(L:List[int], x:int) -> int that takes a list L and an integer x. The function returns the number of occurrences of x in L. For example, rc_count([1,1,2,3], 1) returns 2 and rc_count([1,1,2,3], 4) returns 0. Your Answer: 1 # Put your answer here 2 Submitarrow_forwardjava script programming language solutionarrow_forwardA binary tree is balanced if every node in the tree is such that the heights of its left and right subtrees do not differ by more than one. Complete the pseudo-code method isBalanced which determines if a binary tree is balanced. The function returns a value of -1 if the tree is not balanced, otherwise it returns the height of the tree. Add comments to explain what your code segment is doing. The following definition of a node in the tree is used. class BinaryNode { int element; BinaryNode left; BinaryNode right; } Complete the method below: int isBalanced (BinaryNode t) { int leftCount=0; int rightCount=0; if (t == null) //empty tree, height is 0 return 0; if ((t.left== null) and (t.right== null) return 0; else { . . . . . . . . . } }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