Products in an array

There are a set of 'n' integers. Describe an algorithm to find for each of all its subsets of n-1 integers the product of its integers.

For example, let consider (6, 3, 1, 2). We need to find these products :

- 6 * 3 * 1 = 18
- 6 * 3 * 2 = 36
- 3 * 1 * 2 = 6
- 6 * 1 * 2 = 12

Answer:


Solution 1:

Find the product of all elements in the array.
for ( i=0 to n-1)
{
compute product/a[i];
}

Solution 2:
Find the combinations, nCn-1 = n and compute the product for each combination.

No comments: