Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Permutations: Applications


1. Permutations: Applications
This page contains some applications and examples of permutation processing.

2. Brute force enumeration

3. Brute force
The process of enumeration is sometimes called "brute force".

The process of listing every possible alternative, object, thing, etc., is called enumeration.

4. Combination lock
Brute force enumeration requires looking at all possibilities.

In the case of a combination lock, this is all the possible combinations (permutations).

5. Combination lock
Combination LockHow many combinations are there on a typical combination lock?

6. Combination lock
Combination Lock

7. Combination lock
Combination LockThus, the number of combinations for a typical combination lock is 40*40*40 = 64,000.

How long would a brute force attack take? What happens if the last number is known? Note: Order matters, so a combination lock is really a permutation lock. But the generation of the "combinations" does not follow exactly the permutation algorithm (since there is replacement).

8. Finite state modeling

9. Simple combination lock
This page looks at a simple combination lock and brute-force processing.

To keep it simple, each setting has 3 choices instead of 40 choices.

That yields 27 possibilities instead of 64,000 but the concepts remain the same.

The goal of the program is to output all possible combinations (actually permutations).

10. Iterative program
An iterative program uses nested loops.

Here is the C code.

Here is the output of the C code.


11. Permutation module
Note that this way of handling a "permutation" is not quite what the rsPermute module handles. This is common in computer science. Algorithms have many variations on a theme. Here is the C code.

Here is the output of the C code.


12. Comparison
Compare the iterative and the recursive code.

The iterative code appears shorter, but if another setting is added, another loop needs to be added.

In the recursive code, the literal 3 needs to be changed to 4 to add another setting.

13. Module
Note that the code is very similar to the permute code, but just a little different.

If this functionality were useful in many places, it could be abstracted to a module.

14. Sorting: Slowsort

15. Sorting
To sort something is to arrange that something into order.

To sort a list is to arrange that list so it is in order.

16. Slowsort
Slowsort is a simple but slow exchange sorting algorithm based on the definition of sorting. That is, take all permutations of the items in the set or multiset to be sorted. At least one such permutation will be in sorted order. Pick one of those permutations to complete the sort.

Obviously, slowsort is not a very machine efficient sorting algorithm.

17. End of page

18. Multiple choice questions for this page