Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm not sure how to find part B and C. 3. A sorting algorithm that uses a binary tree to sort a list of positive

image text in transcribed

I'm not sure how to find part B and C.

3. A sorting algorithm that uses a binary tree to sort a list of positive integers a,a2,... .an from largest to smallest can be described as follows. In the first step, we construct the binary tree. The elements a at a time from there. From left to right, compare the elements in pairs, and put the larger of the two as the parent vertex. Do this at each level until reaching the root, which will be the largest element. Output the value at the root. For example, if the list to be sorted is 22,8, 14, 17,3,9,27,11, the tree would look like this: 1, a2.an are the leaves of the tree, and we build up the tree one level 27 27 9 27 22) 4 7 3 (9 27 (11 Then, in the second step, remove the leaf corresponding to that largest element, and replace it with a leaf labeled 0, which is defined to be smaller than all the other list elements. Recompute the labels of all vertices on the path from this 0 to the root. That is, relabel all vertices on the path from the 0 to the root by choosing the larger of the values of their two children Then the root will become the second-largest element. Output the value at the root. In our example, the tree would now look like this: 17 9 22) ( 14 (17) 3 (9 0) (11 We can repeat this procedure a total of n times, which will be enough to output the entire list in decreasing order (a) (4 points) Trace through the algorithm as applied to the list 17,4, 1.5. 13, 10,14,6. Show the tree at each step. each step? throughout the entire algorithm? What is the order of the algorithm in notation? (b) (3 points) If n is a power of two, as in the example, how many comparisons are done at (c) (3 points) If n is a power of two, as in the example, how many comparisons are done

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago