Sorting numbers in ascending or descending order is a useful skill that has a lot of applications in computer science and many other branches of science in different situations. Let’s see an example.
123, 145, 156, 178, 198, 199, 201, 302, 1024
The above list of numbers has been sorted in an ascending order. You can see that the first number on the list is the smallest one, the last one, the greatest one and every number is smaller than the next number on the list. You can use these properties of the sorted list in order to have a computer do different things with the numbers. If the numbers had not been sorted, every time you had to do something with any number on this list, you’d have to compare it to something and decide based on that, what to do with that number. But when you sort the whole list once and for all, you have practically compared all the items on the list against every other item. Now you can do almost anything reasonable with the numbers.
There are two ways to sort numbers: ascending and descending order.
When you sort your numbers in an ascending order, you start with the smallest number on the list and work your way through the greatest one. In order not to get confused by the two terms ascending and descending, think of them as “ascending a mountain” and “descending a mountain.”
When you ascending a mountain, you’re moving towards the mountaintop, towards higher and higher heights. You starts with very low altitudes and end up with the highest altitude possible.
When you descend a mountain, you’re moving towards the foot of a mountain. You starts with the highest altitude possible, namely the mountaintop, and end up at the lowest altitude possible.
Let us do an example to learn how to sort numbers in either an ascending or descending order. Let sort the following list of number in an ascending order.
879, 579, 878, 1256, 1389, 1597, 10568, 11987
Alright, on this list you have eight numbers. The first three numbers have three digits as opposed to four and five digits (the last five numbers). As we discussed before, the numbers with a lower number of digits are always smaller. So in the first round, you can consider just the first three numbers. Since they have the same number of digits, you should compare the largest place values in them in order to sort the three numbers out. Since I want to sort those numbers in an ascending order, I have to start with the smallest number and work my way through the largest one. By comparing the 100’s digits among the three numbers 879, 579 and 878, the last and first numbers have the same 100’s place digit but the middle one has a 5 there which is by the way smaller than the common digit, 8, between the other two numbers. So among the three numbers, 579 is the smallest numbers. Next, since the two numbers left have the common 100’s place digits, 8, I have to compare the digits before the 100’s place, i.e., the 10’s place digits. The two digits in the 10’s place values among the two numbers 879 and 878 are 7 and 7. Again I have the same digits, so I have to move to smaller place value, i.e., the 1’s place value. In the 1’s place values, you have a 9 and an eight. Since 8 is smaller than 9, the number with the 8 is smaller. To sum it up, the smallest number among the three numbers was 579. Among 879 and 878, the smaller number was 878. So to write the three number in an ascending order, I’d write,
579, 878, 879
Next I’d go for the two numbers 1389 and 1597 which have four digits. Going through the same logical reasoning we used above, the two numbers in an ascending order would be,
The next two numbers to look at would be 10568 and 11987. Again going through the same reasoning we used above, we’d have the two numbers in an ascending order as follows:
Now you can combine the three lists together to come up with the following list, sorted in an ascending order:
579, 878, 879, 1389, 1597, 10568, 11987
Please not that the number have been sorted in an ascending order. We have started from the smallest number and ended with the greatest number. If you were to sort the same list in a descending order, you’d have the exact opposite of the current list, as follows,
11987, 10568, 1597, 1389, 879, 878, 579
These articles are used by the author in a series of mathematics courses that will teach you mathematics from the sixth standard all the way up to 12th standard. The purpose of these courses are to help us understand mathematics so that you can use them professionally well. There is a road map that we have put together about the all the courses included, where to starts, etc. To know more about that and have access to those courses, please visit mathematics page on Great IT Courses. Thank you.