(c) Evaluate this sum and then rewrite this as a function of n. You will probably have to [11 pts] look up an unfamiliar sum formula for this. Simplify this as much as possible - it will be very simple! Solution: 4. Suppose we have a perfect binary tree with height h 0 representing a heap, meaning it = has n 2+1 1 keys indexed from 1 to 2+1 1. When we run convertomaxheap we run maxheapify in reverse order on every key with children. Let's examine the worst-case - In the worst-case every single key gets swapped all the way to the leaf level. (a) For each level in the tree there are a certain number of nodes and each of those nodes [10 pts] requires a certain number of swaps. Fill in the appropriate values/expressions in the table: Level Number of Keys Number of Swaps per Key 0 2 .. (b) Write down a sum for the total number of swaps required. This should involve h, not n. [10 pts] Total

icon
Related questions
Question

Do not use AI, it will not work right.

(c) Evaluate this sum and then rewrite this as a function of n. You will probably have to [11 pts]
look up an unfamiliar sum formula for this. Simplify this as much as possible - it will be
very simple!
Solution:
Transcribed Image Text:(c) Evaluate this sum and then rewrite this as a function of n. You will probably have to [11 pts] look up an unfamiliar sum formula for this. Simplify this as much as possible - it will be very simple! Solution:
4. Suppose we have a perfect binary tree with height h 0 representing a heap, meaning it
=
has n 2+1 1 keys indexed from 1 to 2+1 1. When we run convertomaxheap we run
maxheapify in reverse order on every key with children.
Let's examine the worst-case - In the worst-case every single key gets swapped all the way to
the leaf level.
(a) For each level in the tree there are a certain number of nodes and each of those nodes [10 pts]
requires a certain number of swaps. Fill in the appropriate values/expressions in the
table:
Level
Number of Keys
Number of Swaps per Key
0
2
..
(b) Write down a sum for the total number of swaps required. This should involve h, not n.
[10 pts]
Total
Transcribed Image Text:4. Suppose we have a perfect binary tree with height h 0 representing a heap, meaning it = has n 2+1 1 keys indexed from 1 to 2+1 1. When we run convertomaxheap we run maxheapify in reverse order on every key with children. Let's examine the worst-case - In the worst-case every single key gets swapped all the way to the leaf level. (a) For each level in the tree there are a certain number of nodes and each of those nodes [10 pts] requires a certain number of swaps. Fill in the appropriate values/expressions in the table: Level Number of Keys Number of Swaps per Key 0 2 .. (b) Write down a sum for the total number of swaps required. This should involve h, not n. [10 pts] Total
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer