Question: Problem 1 ( 1 0 marks ) . A binary ponga is a binary tree whose leaves are labelled with integers and Problem 1 (
Problem marks A binary ponga is a binary tree whose leaves are labelled with integers and Problem marks A binary ponga is a binary tree whose leaves are labelled with integers and
every internal node is labelled with the sum of its immediate children.
a Describe an algorithm that, given a list of integers constructs a binary ponga whose leaves
are the elements of in the same order they are given. Explain why the algorithm is correct
and compute its running time. To obtain full marks your algorithm should run in linear time.
b Describe an algorithm that, given the binary ponga corresponding to a list of integers and
indices i and outputs the sum cdots Explain why the algorithm is
correct. To obtain full marks your algorithm should make use of the information stored on
internal nodes and not merely sum the leaves.
Represent the binary ponga with an array and implicit pointers, analogously to how a binary heap
is represented with an array. You may assume for simplicity that the size of is a power of and
hence the tree is complete.
Bonus not marked: Show that the sum algorithm runs in logarithmic time.
every internal node is labelled with the sum of its immediate children.
a Describe an algorithm that, given a list of integers constructs a binary ponga whose leaves
are the elements of in the same order they are given. Explain why the algorithm is correct
and compute its running time. To obtain full marks your algorithm should run in linear time.
b Describe an algorithm that, given the binary ponga corresponding to a list of integers and
indices i and outputs the sum cdots Explain why the algorithm is
correct. To obtain full marks your algorithm should make use of the information stored on
internal nodes and not merely sum the leaves.
Represent the binary ponga with an array and implicit pointers, analogously to how a binary heap
is represented with an array. You may assume for simplicity that the size of is a power of and
hence the tree is complete.
Bonus not marked: Show that the sum algorithm runs in logarithmic time.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
