(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
(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
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:](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe0394dda-1230-46f2-92ff-9edb879436e7%2F5d1329bd-bf65-4350-baed-3a9f4be7c1a7%2Fc8l8hql_processed.png&w=3840&q=75)
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe0394dda-1230-46f2-92ff-9edb879436e7%2F5d1329bd-bf65-4350-baed-3a9f4be7c1a7%2F4yn1r5o_processed.png&w=3840&q=75)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
