Given an array of elements, find all its permutations.
Best Case: Ω(nn!)
Average Case: θ(nn!)
Worst Case: O(nn!)
where n represents the size of the array.
Worst Case: O(1)
The function generate_permutations
has the following parameter(s):
a
: a vector of integers
Return value: None.
The function prints each permutation on the standard output.
The first line contains an integer n
, the size of array.
The next line contains n
space-separated integers a[i]
where 0 ≤ i
< n
.
n! lines denoting all possible permutations.
3
2 1 3
2 1 3
2 3 1
1 2 3
1 3 2
3 1 2
3 2 1