Problem

A binary tree can be used to sort n elements of an array data. First, create a complete bi...

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 1a 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 1b, so that the smallest element emin in the tree is assigned to the root. Next, until the element E is assigned to the root, execute a loop that in each iteration stores E in the leaf, with the value of emin, and that, also starting from the bottom, assigns to each node the minimum of its two children. Figure 1c displays this tree after one iteration of the loop.

Figure 1 Binary tree used for sorting.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 6
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT