January 2018
Intermediate to advanced
332 pages
7h 36m
English
Before writing the pseudo code, let's break down the solution for a better understanding. What we want to do is to create a binary tree, and at each level of the tree we want to assign the cost to get to the node, the value of the node and the upper bound of the cost that it takes to reach to that node.
However, how do we calculate the upper bound of the tree? To determine that, let's first break our problem down into smaller parts:
const costs = [4, 1, 2, 2, 3, 2, 3];const value = [12, 1, 4, 6, 6, 4, 9];const v2c = [12/4, 1/1, 4/2, 6/2, 6/3, 4/2, 9/3];const maxCost = 10
Once we have that, we will rearrange our elements in the decreasing order of our value to cost ratio because we want to pick the ...
Read now
Unlock full access