What is the best algorithm to get all possible string combinations from a given array with a minimum & maximum length value.
Note: This adds complexity since the
Accumulative set product for k times with a set S which is empty initially will produce all permutations up to k-long, with n = |S| ..
Time: O(kn^2)
Space: O(kn^2)
// Enumerate all permutations, PHP
// by Khaled A Khunaifer, 25/3/2013
function setProduct($a, $b)
{
$arr = array();
foreach ($a as $s)
{
foreach ($b as $t)
{
$arr[] = $s . $t;
}
}
return $arr;
}
function enumerate ($arrary, $maxLen)
{
$enumeration = array();
for (var $i = 1; $i <= $maxLen; $i++)
{
$enumeration += setProduct($enumeration, $array);
}
}