Jan 11, 2009

Given an array of N numbers, in how many ways can you choose k numbers such that no two adjacent are selected. For eg.. given 5 numbers , 1 2 3 4 5, W

Given an array of N numbers, in how many ways can you choose k numbers such that no two adjacent are selected.
For eg.. given 5 numbers , 1 2 3 4 5,
We can select 3 numbers from this lot such that no two are adjacent in only one way.

If we call Q(n,k) the number you're asking about, then
Q(n,k) = C(n-k+1,k)
with C(n,r) being the usual "n choose r".
Basically, as you choose numbers out of the set of N, the only difference in making them nonadjacent is that each time you select a number you also remove one more (following one) from the full set (except the last time).
So suppose we're choosing 4 elements out of a set of 10. The first 3 times we choose an element, we also remove the element following from consideration. Thus the process of selecting 4 nonadjacent numbers from a set of 10 is equivalent to choosing 4 possibly adjacent numbers from a set of 7. (The numbers would be different, but the number of possible combinations isn't.)

No comments:

Post a Comment