For a given unordered list of three numbers, how many different ways of sorting it are there?
I am working on a data structures project, and I am trying to come up with a particular algorithm. That being the case, I ran into having to figure out how many different ways there are to sort a list of numbers (for now, let's say three). The numbers do NOT have to be adjacent to each other. For example, if the list is (1, 7 , 5), the simplest solution is to switch the 5 and the 7, resulting in (1, 5, 7). But you could also switch the 7 and the 1 resulting in (7, 1, 5) then the 5 and the one: (7, 5, 1) and finally the 7 and the 1 again (1, 5, 7). I'd like some help on knowing how many different possibilities there are. Thanks in advance for any help.
Public Comments
- 3x2x1=6 different ways to arrange the numbers. This can be applied to any group of numbers. If you have four numbers then you have 4x3x2x1= 24 ways. etc.
- For small numbers of elements like this, it is easiest to go through in a structured way: 1 7 5 1 5 7 These are the only ways to combine with 1 in the first position. 5 1 7 7 1 5 These are the only ways to combine with 1 in the second position. 5 7 1 7 5 1 These are the only ways to combine with 1 in the third position. Now you have convered all the positions, so there are six variants.
- If you have 3 numbers, say the ones you've presented..then 1 can go in any of 3 different locations. The next number can go in any of 2 different locations since one location is already taken. The last number can only go in 1 location. So the answer is 3*2*1 or 3! (factorial) = 6. This works for n numbers.
Powered by Yahoo! Answers