previous | start | next

## Permutations

- We will develop a function that generates all permutations of a word.

  >     vector<string> generate_permutations(string word);

- The following code displays all permutations of the string "eat":

  >     vector<string> v = generate_permutations("eat");
  >     for(int i = 0; i < v.size(); i++)
  >        cout << v[i] << "\n";

- To generate the permutations recursively, generate all permutations that state with the letter 'e', the those that start with 'a', then those that start with 't'.
- Use the recursion to generate all the permutations of the shorter (two-letter) strings.
  - "at" "ta"
  - "et" "te"
  - "ae" "ea"
- Add the first letters to find the permutations.
  - "eat" "eta"
  - "aet" "ate"
  - "tae" "tea"

previous | start | next