Back to Cosmos

Rod Cutting

code/dynamic_programming/src/rod_cutting/README.md

latest1.7 KB
Original Source

Rod Cutting

Given a rod of length n units and an array of prices p<sub>i</sub> for rods of length i = 1, 2, . . . ,n. Determine the maximum revenue r <sub>n</sub> obtainable by cutting the rod and selling the pieces.

Explanation

Let the table of prices be -

length (i)12345678910
price (p<sub>i</sub>)1589101717202430

For a rod of length n = 4

Image credits: (CS Indiana)

Image credits: (Medium: Pratik Anand)

Maximum revenue is obtained by cutting the rod into two pieces each of length 2. Thus, maximum revenue obtained is 10.

This problem satisfies both properties of Dynamic programming and can be solved by the following recurrence relation.

Recurrence Relation

Complexity

Time complexity : O(n^2)

Space complexity : O(n)


<p align="center"> A massive collaborative effort by <a href="https://github.com/OpenGenus/cosmos">OpenGenus Foundation</a> </p>