All problems
Multigrid V-Cycle Cost
Problem
Estimate the cost of a multigrid V-cycle given the grid sizes of each level from finest to coarsest.
Each level is visited twice (once going down, once coming up) except the coarsest level, which is solved once. If one visit costs one unit per grid point, the total cost is 2*sum(sizes) - sizes[-1].
Hint
The geometric series keeps the V-cycle cost proportional to the finest level.
Test cases
case 1
in: [[8,4,2]]
expected: 26
case 2
in: [[16,8,4,2,1]]
expected: 61
case 3
in: [[1]]
expected: 1
case 4
in: [[4,2]]
expected: 10
Starter codePython
def v_cycle_cost(levels):
# Your code here
pass4 test cases · run your code against them in the editor