MYPROGRAMMINGLAB WITH PEARSON ETEXT
8th Edition
ISBN: 9780134225340
Author: Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 12, Problem 12.19E
Program Plan Intro
Program plan:
- item, root, d variableare used for input. There is structure Treenode havingdata, leftptr, rightptr member variables which represents the tree node.
- void insertnode(node **ptr, int value) function inserts the node in the tree and create a tree.
- void inorder(node *ptr) function display the tree values in sorting order.
- int depth(node *ptr) determine the height of depth of tree and return max depth between left or right nodes path.
Program description:
The main purpose of the program is to create binary search tree, display the tree values and measure and display the depth of the tree.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Don't reject
Complete the TODOs in C++
1. Implement sumNodes function which sums the data of all the nodes of the tree. (Silver Problem)2. Implement printLeafNode function which prints just the leaf nodes of thetree. (Gold Problem)
(.hpp file in image)
1st code is driver.cpp
#include <iostream>
#include "tree.hpp"
using namespace std;
#define COUNT 10
int main()
{
Treet;
t.createTree();
//cout<<t.root->data<<endl;
t.print2DUtil(t.root, 0);
// 1, 2, 4, 5, 3, 6, 7
cout<<"\nPreorder traversal of binary tree is \n";
t.preOrderTraverse(t.root);
cout<<endl;
/**********************
Silver problem
***********************/
cout<<"\nSum of all the nodes in tree is: "<<t.sumNodes(t.root);
cout<<endl;
/**********************
Gold problem
***********************/
cout<<"\nPrinting leaf nodes of the tree \n";
t.printLeafNode(t.root);
cout<<"\nDeleting the tree \n";
t.deleteTree(t.root);
t.root=NULL;
cout<<endl;
return0;
}
2nd code:…
Use function def showList(self)
Precondition: None.
Postcondition: Outputs the keys of the elements of the order list. If the list is empty, outputs “Empty list”
note: Use python and the concept of doubly Linked List
Chapter 12 Solutions
MYPROGRAMMINGLAB WITH PEARSON ETEXT
Ch. 12 - Prob. 12.6ECh. 12 - (Merging Ordered Lists) Write a program that...Ch. 12 - Prob. 12.8ECh. 12 - (Creating a Linked List, Then Reversing Its...Ch. 12 - Prob. 12.10ECh. 12 - Prob. 12.11ECh. 12 - Prob. 12.12ECh. 12 - Prob. 12.13ECh. 12 - Prob. 12.14ECh. 12 - (Supermarket Simulation) Write a program that...
Knowledge Booster
Similar questions
- c) An expression of A + B^3 – C/D is obtained using a rooted tree. i. Draw a rooted tree with the height of 2 to represent the postorder traversal. ii. Justify whether the rooted tree in 3-c(i) is balanced or not. iii. From tree in c(i), get the mathematical expression using the inorder traversal. d) Figure 3 represents a network of paths in a park. The number on each edge represents the length of the path in meters. The cost per meter is RM120. To gain as much profit, the contractor asked one of his staff to find the minimum network needed using Kruskal's algorithm. G 21 16 17 21 F 11 23 E 11 7 15 18 В 11 20 A Figure 3 i. Explain why the staff's work which is highlighted in red is incorrect. ii. Help the staff to find the correct minimum network using Kruskal's algorithm and states its length and total cost. iii. Is there any possibiliy, more than one distint MST obtained for the Figure 3?. If yes, justify your answer and show the network.arrow_forwardquick Solution pleasearrow_forward1.) Design a Binary Search Tree ADT by using following functions. Include the function definitions & run the program (Kindly include header files as well). Paste the output as a screenshot and write the code in your answer sheet. insert(int val)find(int x)************************************************************************************ class btNode { public: int info; btNode *lLink; btNode *rLink; btNode(int e, btNode *l = NULL, btNode *r = NULL) { info = e; lLink = l; rLink = r; } btNode() { lLink = NULL; rLink = NULL; } }; class binarySTADT { private: btNode *root; int count = 0; public: binarySTADT() { root = NULL; } void insert(int val); // function to insert a given value in the tree.…arrow_forward
- C in pythonarrow_forward(Java) How can I implement a binary search tree in a program to store data, and use the delete method to trim the tree? The program should have a 'populate' button that obtains a string from the user, creates a sorted binary search tree of characters, and prints the tree using the DisplayTree class. It should also print the characters on one line in sorted order by traversing the tree in inorder fashion. The program should also have a 'Trim Tree' button that obtains a second line of input to delete characters from the tree, trimming the tree accordingly. It should ignore characters that are not in the tree, and only delete one character for each occurrence in the second line of input. When all characters from the second line have been deleted from the tree, the program should print the remaining characters in the tree using the DisplayTree class. The output should be labeled appropriately, and no spaces or commas should be used between tree elements in the inorder traversal.Here is the…arrow_forwardInstructions. c++ binary search trees. 1. Implement a function that will build a binary search tree. 2. Using the function above create a binary search tree. 3. Implement a swapSubtrees() function that will take a pointer to a root node and a target value. Function will search for the target value in the tree and swap all left nodes with right nodes for all descendant nodes. 4. Pass the tree created in step 2 to test swapSubtrees() function. 5. You can use the inorder, postorder or preorder traversal implemented in class to display and confirm the logic. (trace it by hand as well) TreeNode{ int val; TreeNode* left = nullptr; TreeNode* right = nullptr; TreeNode(){} TreeNode(int val): val(val){} };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++) Change the tree shown in the figure below to an AVL tree. Assume that the tree in the figure below is a BST tree. Please include the final answer and also show the steps needed to get to the final answer.arrow_forward1. Do some research about binary search trees. 2. Create a structure in C for the nodes of this tree. Which variables do the structure have? 3. Write a function that builds a balanced binary search tree. The input argument of this function is a sorted array of integers. 4. Write a recursive function that inserts a new element to the tree. The input argument of this function is a pointer to the head node of the tree. 5. What is the time complexity of this insertion function?arrow_forward
- code:arrow_forwardInstructions. c++ binary search trees. 1. Implement a function that will build a binary search tree. 2. Using the function below create a binary search tree. 3. Implement a swapSubtrees() function that will take a pointer to a root node and a target value. Function will search for the target value in the tree and swap all left nodes with right nodes for all descendant nodes. 4. Pass the tree created in step 2 to test swapSubtrees() function. TreeNode{ int val; TreeNode* left = nullptr; TreeNode* right = nullptr; TreeNode(){} TreeNode(int val): val(val){} };arrow_forwardLanguage : Carrow_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