write a function to initialize an array with n random values write a function to build this binary tree with the above definition with anydata structure write a function to display the tree information write a function to search an input value using recursion. If found, display all the subtree with the found node as the root of this subtree’ or else return -1. write a function to insert new nodes into the tree and another one to remove nodes from the tree

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

A binary tree can be used to sort n elements of an array data. First, create a
complete binary tree, a tree with all leaves at one level, whose height h = (lg n) + 1, and store all elements of the array in the first n leaves. In each empty leaf, store an element E greater than any element in the array.
Figure (a) shows an example for data = 8, 20, 41, 7, 2, h = (lg(5)) + 1 = 4,
and E = 42. Then, starting from the bottom of the tree, assign to each node the minimum of its two children values, as in Figure (b), so that the smallest element emin in the tree is assigned to the root.
If a leaf node is to be removed, this node is replaced by a new node with the same value of its parent node.
If a node is added into the tree, it will be a leaf node. Normally a node with value E is replaced with new value. It’s necessary to verify recursively all values of its parent and make any possible modification if necessary so that the tree rules are respected.
Implement this tree structure in C/C++ with the necessary functions.

  • write a function to initialize an array with n random values
  • write a function to build this binary tree with the above definition with anydata structure  
  • write a function to display the tree information
  • write a function to search an input value using recursion. If found, display all the subtree with the found node as the root of this subtree’ or else return -1.
  • write a function to insert new nodes into the tree and another one to remove nodes from the tree
8
20
41
7
42
42
42
(a)
2
7
2
7
2
42
8
20
41
7
2
42
42
42
(b)
Transcribed Image Text:8 20 41 7 42 42 42 (a) 2 7 2 7 2 42 8 20 41 7 2 42 42 42 (b)
Expert Solution
steps

Step by step

Solved in 4 steps with 24 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY