Here's the question. You are given rods of lengths 2 and 3. You are to line them up so that the total length is 20. How many different ways are there to make length of 20? You have sufficient quantity of both types of rods. Not meant to be a non-sense / tricky question. There are at least two major distinct types of approaches.
[1] Algebraic / Mathematical
Let x and y represent the number of rods of lengths 2 and 3, respectively. Then the governing equation is 2x + 3y = 20 with x and y being non-negative integers. For each (x, y) combination, there are f(x,y) = (x+y)!/(x!y!) different ways of arranging them. So for each combination,
(x, y) = (10, 0) gives f(10, 0) = 1
(x, y) = (7, 2) gives f(7, 2) = 36
(x, y) = (4, 4) gives f(4, 4) = 70
(x, y) = (1, 6) gives f(7, 6) = 7
and the answer is 1 + 36 + 70 + 7 = 114.
[2] Computational
We can incrementally increase the length of the rod, using rod of lengths shorter by 2 or 3. For L = 7 for example, you can add L=2 rod to the right end of each configuration for L=7-2=5, or add L=3 to right end of configuration for L=7-3=4. So the governing equation here is g(7) = g(4) + g(5), or in general g(L) = g(L-3) + g(L-2), with g(0) = 0, g(1) = 0, g(2) = 1, g(3) = 1. We can 'climb the ladder' one by one, or increase L by one until L=20. To list a few intermediate cases,
g(4) = 1
g(5) = 1
g(6) = 2
g(7) = 3
g(10) = 7
g(12) = 12
g(15) = 28
g(20) = 114
[1] requires systematic understanding of underlying principle. You can write a general solution, but you would need to compute each cases from scratch. If you need to figure out an answer for only one final length, this might be a better option.
[2], on the other hand, does not require (or require far less) understanding of logical structure. You only need to find recurrence relation from simpler / smaller cases. And you reuse answers for shorter lengths, so [2] could be your choice if you need to repeat this computations a lot of times.
I have been a type [1] person for a long time. I would have been upset at [2] since it does not conform to 'solving' a problem. It could only be called finding the answer.
But there are classes of problem you can solve only with [2]. Or type [1] approach is far less efficient. What if you have more than two types of rod, like 5 types of rods? Thus I have been making a gradual transition to (or adoption of) type [2] thinking.
Which of the two came up to you first?
PS - approach [2] is called Dynamic Programming in computer science, in that one can think of the original problem being made up of smaller problems of the same logic. In mathematics it belongs to sequence (described by recurrence relation), so you may call both approaches mathematical. Taxonomy is not the main point of this article.
No comments:
Post a Comment