Question: Let a 1 , . . . , an be a sequence of positive integers. A labeled tree for this sequence is a binary tree
Let a an be a sequence of positive integers. A labeled tree for this sequence is a binary tree
T of n leaves named v vn from left to right. We label vi by ai
for all i i n Let
Di be the length of the path from vi to the root of T The cost of T is given by
costT Xn
i
aiDi
The problem is: Given a sequence of n positive integers a an construct a labeled tree
for this sequence that has the lowest cost. Your algorithm should run in On
time. Hint:
Use Dynamic Programming.
Your answer should include: i The main ideas in words behind the algorithm which makes
the correctness selfevident, ii pseudocode, and iii an analysis of the running time and
space
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
