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
Given the following infix expression:
(28 * (33 - 3) + 10) / (4 * 0.5) % 4
Give the equivalent postfix expression
Draw the tree corresponding to the recursive calls to evaluate the postfix expression. What is the depth of your tree?
C++, Write a recursion function that counts the positive elements multiple of 5 in a binary search tree and counts the elements less than 0 and multiple of 2, then returns the two counts multiplied to the main.Note that you have to write only one function and you can add parameters to the function as needed
1. 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?
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
- Answer (iii) with detailed and concise explanations. Give the content of the stack after each of the following operations takes place.arrow_forwardplease answer in scheme racket flavor 1. Create the recursive function far-left that will find the left-most value 2.Create the recursive function far-right that will find right-most value 3. Write depth, a procedure that takes a tree as an argument and returns the largest number of nodes connected through parent-child links. That is, a leaf node has depth 1; a tree in which all the children of the root node are leaves has depth 2. Our world tree has depth 4 (because the longest path from the root to a leaf is, for example, world, country, state, city). 4. Write count-nodes, a procedure that takes a tree as an argument and returns the total number of nodes in the tree. (Earlier we counted the number of leaf nodes.) (define (leaf? node) (null? (children node))) (define (datum node) (car node)) (define (children node) (cdr node)) (define (count-leaves tree) (if (leaf? tree) 1 (count-leaves-in-forest (children tree)) ) ) (define (count-leaves-in-forest forest) (if (null? forest) 0 (+…arrow_forward3.Divide & Conquer and Dynamic Programming have one thing in common, and that is a focus onThe "subproblem" solution. In terms of Recursion tree size, subproblem size, subproblem The difference between Divide & Conquer and DP is illustrated in terms of Recursion tree size, subproblem size, overlapping.arrow_forward
- Notes:-Give priority to the left child over the right. -Use a space to separate the node values! 1. List the first 5 nodes, in order, visited by a preorder traversal. 2. List the first 5 nodes, in order, visited by an inorder traversal. 3. List the first 5 nodes, in order, visited by a postorder traversal. 4. List the first 5 nodes, in order, visited by a level order traversal.arrow_forward1. Write a recursive function named RecursiveSum that, given a positive number n (n> 0), returns the sum of the numbers from 1 to n. Also, show the process of finding the result using a recursion 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_forward
- Convert the following postfix statements into expression trees AB/CD+* ABCDE+-/+arrow_forwardDraw the recursion tree:arrow_forwardOne-friend recursion vs iteration.1. Your task is to accept a tuple a1, a2, ... , an and return the reversed tuple an, an−1, ... , a1. Being lazy, you will only strip off an element from one end or add an element back onto one end. But you have recursive friends to help you. Provide both a paragraph containing the friend’s explanation of the algorithm, and the recursive code.2. Now suppose that you have a stack, but no friends. (See Chapter 3). Quickly sketch an iterative program that solves this same problem. Be sure to include loop invariants and other the key steps required for describing an iterative algorithm.3. Trace each of these two programs. Step by step, compare and contrast their computations on a computer. i already uploaded this question 3 times and getting wrong answer so if you don't know right answer dont write rubbih ans otherwise you will get downvotearrow_forward
- One-friend recursion vs iteration.1. Your task is to accept a tuple a1, a2, ... , an and return the reversed tuple an, an−1, ... , a1. Being lazy, you will only strip off an element from one end or add an element back onto one end. But you have recursive friends to help you. Provide both a paragraph containing the friend’s explanation of the algorithm, and the recursive code.2. Now suppose that you have a stack, but no friends. (See Chapter 3). Quickly sketch an iterative program that solves this same problem. Be sure to include loop invariants and other the key steps required for describing an iterative algorithm.3. Trace each of these two programs. Step by step, compare and contrast their computations on a computer. i already uploaded this question 3 times and getting wrong answer so if you don't know right answer dont write rubbih ans otherwise you will get downvote don't copy bartleby old or chegg its wrongarrow_forwardProblem Statement: (The following problem is based on a problem in a number of Java texts, including the text by Gaddis.) Given a numeric expression in prefix form, develop a Java program to evaluate the expression. ================================================================================ NOTE 1: Your program should internally convert the prefix expression into a binary tree before evaluating it Feel free to use any other data structures, in addition to the binary tree, that you may deem necessary to set up and evaluate your prefix expression ================================================================================ The following site provides some explanation on prefix expressions, as well as other forms of numeric expressions: Infix, Prefix and Postfix Expressions (Links to an external site.) Input Data: Repeatedly, enter one prefix expression (as a string) at a time at the keyboard alternatively, you may set up an input data file and get the data from the…arrow_forwardGiven the following expression trees, manually evaluate them. Show step by step solution.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