Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

combinations algorithm

I want to make simple sorting algorithm.

given the input "abcde", I would like the output below. could you tell me the algorithm for that?

arr[0] = "a"
arr[1] = "ab"
arr[2] = "ac"
arr[3] = "ad"
arr[4] = "ae"
arr[5] = "abc"
arr[6] = "abd"
arr[7] = "abe"
...
arr[n] = "abcde"

arr[n+1] = "b"
arr[n+2] = "bc"
arr[n+3] = "bd"
arr[n+4] = "be"
arr[n+5] = "bcd"
arr[n+5] = "bce"
arr[n+5] = "bde"
...
arr[n+m] = "bcde"
...
...
like image 639
mysterious jean Avatar asked Mar 24 '10 07:03

mysterious jean


People also ask

What is combination algorithm?

The algorithm assumes that we have a set containing elements: {0, 1, … , }. Then, we generate the subsets containing elements in the form , starting from the smallest lexicographic order: The algorithm visits all -combinations. It recursively represents multiple nested for loops.

How do you calculate algorithm combinations?

Traditional formula of r-combination (or n choose r) is: C(n, r) = n! / (r! . (n-r)!)

How many combinations of 3 items are there?

* 3!) = 10 different ways. This generalises to other combinations too and gives us the formula #combinations = n! / ((n - r)! * r!)

How many combinations of 4 items can you make?

I.e. there are 4 objects, so the total number of possible combinations that they can be arranged in is 4! = 4 x 3 x 2 x 1 = 24.


1 Answers

An algorithm for "generating Power Set" from an array is what you are looking for. You can try Google or some other search engine to find the algorithm that best fits your needs.

like image 101
rahmivolkan Avatar answered Sep 30 '22 18:09

rahmivolkan