Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
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
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…
]
]
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
Python
Chapter 19 Solutions
Starting Out with C++: Early Objects (9th 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
- quick 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_forwardRecursive 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_forward
- Make 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_forwardWrite a function that will return the maximum element of a Binary Search Tree, given the pointer to the root of the tree. Use the following function prototype: int getMaxOfBST(Node* root);arrow_forward*Please using JAVA only* Objective Program 3: Binary Search Tree Program The primary objective of this program is to learn to implement binary search trees and to combine their functionalities with linked lists. Program Description In a multiplayer game, players' avatars are placed in a large game scene, and each avatar has its information in the game. Write a program to manage players' information in a multiplayer game using a Binary Search (BS) tree for a multiplayer game. A node in the BS tree represents each player. Each player should have an ID number, avatar name, and stamina level. The players will be arranged in the BS tree based on their ID numbers. If there is only one player in the game scene, it is represented by one node (root) in the tree. Once another player enters the game scene, a new node will be created and inserted in the BS tree based on the player ID number. Players during the gameplay will receive hits that reduce their stamina. If the players lose…arrow_forward
- C programming I need a code that asks the user for how many times it'll run and run that many time and ask the user for a number and it puts that number into a binary search tree and an array using diffrent functionsarrow_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_forwardpython assignment Matrix class Implement a matrix class (in matrix.py). a) The initializer should take a list of lists as an argument, where each outer list is a row, and each value in an inner list is a value in the corresponding row. b) Implement the __str__ method to nicely format the string representation of the matrix: one line per row, two characters per number (%2d) and a space between numbers. For example: m = Matrix([[1,0,0],[0,1,0],[0,0,1]]) print(m)> 1 0 0> 0 1 0> 0 0 1 c) Implement a method scale(factor) that returns a new matrix where each value is multiplied by scale. For example: m = Matrix([[1,2,3],[4,5,6],[7,8,9]])n = m.scale(2)print(n)> 2 4 6> 8 10 12>14 16 18print(m)> 1 2 3> 4 5 6> 7 8 9 d) Implement a method transpose() that returns a new matrix that has been transposed. Transposing flips a matrix over its diagonal: it switches rows and columns. m = Matrix([[1,2,3],[4,5,6],[7,8,9]])print(m)> 1 2 3> 4 5 6> 7 8…arrow_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
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