C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 12, Problem 12.23E
Program Plan Intro
Program plan:
- Item, root variablesare used for input. There is structure Treenode havingdata, leftptr, rightptrmember variables which represents the tree node. Structure qitem having treenode, nextPtrvariables which represents the queue and stores the Treenodetype value.
- voidinsertnode(node **ptr, int value) function inserts the node in the tree and create a tree.
- voidinorder(node *ptr) function displays the tree values in sorting order.
- voidpreorder (node *ptr) function displays the tree values in pre order fashion.
- voidpostorder(node *ptr) function displays the tree values in post order.
- voidlevelorder(node *ptr) function display the tree values in sorting order.
- voidenque(queue **front, queue **taiil, node *tnode) function stores the Treenodetype data in a queue.
- node*deque(queue **front, queue **tail) function delete the Treenode type from the queue and return the Treenode type value.
Program description:
The main purpose of the program is to create binary search tree and display the tree value using levelorder
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Course : Data Structure and Algorithms
Write a java/c++ code or an algorithm to solve the following problem. After that dry run and show output of algorithm using an example binary tree. .
Write a recursive function to write the parent of the all the nodes while traversing. Like if you traverse the root node write the current node a, parent null. Then if you go to left sub tree, your code will show, current node : b , parent a and so on.
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.
C++ please
Please complete Programming Exercise 4, from pages 1402, from chapter 19 from your textbook.
Write a function, singleParent, that returns the number of nodes in abinary tree that have only one child. Add this function to the classbinaryTreeType and create a program to test this function. (Note: Firstcreate a binary search tree.)
Chapter 12 Solutions
C How to Program (8th Edition)
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
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Exercise 1: (Divide and Conquer: Binary tree traversal) Write pseudocode for one of the classic traversal algorithms (preorder, inorder, and postorder) for binary trees. Assuming that your algorithm is recursive, find the number of recursive calls made.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_forward8. sum_binary_tree For this function, we are using a data structure called a binary tree, which is useful for storing all different kinds of data. In this problem a binary tree contains a single number, and it has two children, each of which may be either None, or they may be more binary trees. You can see, this is a recursively defined data structure! To recap: each binary tree contains a number and two children. The children are either None or a BinaryTree object. In this function we want to sum up all of the numbers contained in a binary tree and its children (recursively). Sample calls should look like this: >>> sum_binary_tree(BinaryTree(10, None, None)) 10 >>> sum_binary_tree(BinaryTree(10, None, BinaryTrate (10, None, BinaryTree(10, None, None)))) 30 >>> sum_binary_tree(None)arrow_forward
- 8. sum_binary_tree For this function, we are using a data structure called a binary tree, which is useful for storing all different kinds of data. In this problem a binary tree contains a single number, and it has two children, each of which may be either None, or they may be more binary trees. You can see, this is a recursively defined data structure! To recap: each binary tree contains a number and two children. The children are either None or a BinaryTree object. In this function we want to sum up all of the numbers contained in a binary tree and its children (recursively). Sample calls should look like this: | >>> sum_binary_tree(BinaryTree(10, None, None)) 10 >>> sum_binary_tree(BinaryTree(10, None, BinaryTree(10, None, BinaryTree(10, None, None)))) 30 >>> sum_binary_tree(None)arrow_forwardA tree can be represented using lists as follows. (root listOfSubTrees ) tree listOfSubTrees tree = root listOfSubTrees = tree Consider the tree defined by: (FD (G (AHI) C) E B) Give the order of letters visited in when using a pre-order traversal implemented recursively as seen in class. (separate each element with a space where the left is the first element visited and the right is the last element visited, example: A B C D E F)arrow_forwardQ-13. Recursive binary tree code. Write a recursive C++ function called insert which takes two arguments: a pointer to the root of a binary scarch tree whose nodes are as defincd above, and an integer key. The function inscrts a new key into the tree and returns a pointer to the node. The tree should only store unique keys. When a duplicate key is encountered, the function increments the appropriate node count variable and returns a pointer to the node.arrow_forward
- Write a C++ code for A) Removal of node from Binary Search Tree. Hand written code and screen shot of output is required before and after deletion. B) Display code is required for In-Order and Post Order traversal of binary search tree.arrow_forwardHelp on the following question A co-worker emails you and said she developed a recursive version for doing search in a binary search tree. Here’s the code for the function: public boolean searchRecursive(Node current, int searchValue) { if (current == null) return false; if (current.data == searchValue) return true; else if (current.data > searchValue) return searchRecursive(current.right, searchValue); else return searchRecursive(current.left, searchValue); } She’s not sure if there is an error or not because the code does compile. You analyze the code and respond to her as follows: Draw a picture of what a binary search tree would look like after inserting values of 10, 15, 18, 13, 5, 1, and 8 in that order Next, if you believe there is no error with the code, then show her how the code executes when searching for different values using the tree you made in step 1) Or, if you believe there is…arrow_forward1). Write a program to construct a binary tree to support the following operations. Assume no duplicate elements while constructing the tree. i. Given a key, perform a search in the binary search tree. If the key is found then display "key found" else insert the key in the binary search tree. ii. Display the tree using inorder, preorder and post order traversal methodsarrow_forward
- 4-) Write a recursion function which counts the number of nodes with at least one child in a BST.arrow_forwardAlgorithm Design 1. In-order traversal a binary tree in two ways. 1) Use recursive method 2) Use iterative methodarrow_forwardCO LL * Question Completion Status: QUESTION 3 Write a recursive function, OnlyChild(..), that returns the number of nodes in a binary tree that has only one child. Consider binaryTreeNode structure is defined as the following. struct binaryTreeNode int info; binaryTreeNode *llink: binaryTreeNode *rlink; The function is declared as the following. You must write the function as a recursive function. You will not get any credits if a non-recursive solution is used. int OnlyChild(binaryTreeNode *p); For the toolbar, press ALT+F10 (PC) or ALT+FN+F10 (Mac). Paragraph Arial 10pt B. ^三へ三 三山 三Ex? X2 = E E E 9 Click Save and Submit to save and submit. Click Save All Answers to save all ansuwers. Is E English (United States) Focus || 15 stv MacBook Air D00 O00 F4 F5 F8 64arrow_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