# Least to Greatest Calculator

Welcome to Omni's **least to greatest calculator**, where we'll help you **put your numbers in order**. In general, the task shouldn't be too tricky, but it can get messy if there are many entries or, even worse, if they are not yet calculated, i.e., they are some arithmetic expressions. Don't worry; with our tool, even **ordering fractions and decimals from least to greatest will be super simple**! Even better - when needed, our calculator can be turned to a number sorter from greatest to least (i.e., you can **switch between ascending order and descending order**).

Let's jump straight into the article and **begin the lesson**!

## How to order numbers from least to greatest

When we get a sequence of numbers `x₁`

, `x₂`

, `x₃`

,..., `xₙ`

, there are **several ways to order them**. For instance, we could compare each of the numbers with all the others and, one by one, write them down in ascending order. However, if the list is very long, **the process may take ages**. And time is money.

Therefore, the real problem here is **efficiency**. Even though we know a brute-force way to order numbers from least to greatest, it may be important **how fast we do it**, especially in computer studies. As a consequence, several so-called **sorting algorithms** have been invented. We will now present one number sorter, which is easy and very popular.

The idea behind **bubble sort** is simple: you compare pairs of numbers one after the other and swap their places if they're in the wrong order. In fact, we'll see that it's enough to check **two consecutive elements at a time** and repeat as long as needed.

**The steps of the algorithm are**:

- Set
`k = 1`

. - If the
`k`

-th entry**is larger**than the`(k+1)`

-th, make them swap places and remember that something changed. If not, don't change anything. - If
`k < n - 1`

, increase`k`

by`1`

, and repeat from point 2. Otherwise, recall if something changed in this run of the algorithm. If yes, repeat from point 1. If not,**end the algorithm**.

The above number sorter **puts the entries in ascending order**. Computer scientists say that, on average, **the time it takes is equal to** `nlog(n)`

, where `log(n)`

denotes the logarithm.

Before we finish the section, let us mention that the least to greatest calculator also **admits entries in a not-yet-calculated form**. In essence, if you need to compare, say, `3 + 12 * 3`

, `(2 + 6) / 4`

, and `(-1) * (13 - 5)`

, then you can input these expressions without calculating them. The tool will give you the ordered list **in both forms**: the calculated one and the *raw*.

We'll see **an example of bubble sort** in action in the dedicated section. First, however, let's go through a few tips and tricks about sorting numbers. In particular, we focus on **ordering fractions and decimals from least to greatest**.

## Ordering decimals from least to greatest

When dealing with decimals or fractions, the basic rules are the same as with any other values: **you have to compare the entries and put the numbers in order**. However, while it's easy to see that `13`

is larger than `9`

, it's not straightforward with `2/5`

and `3/8`

. This section is here to **help you with such problems**.

We begin by **ordering decimals from least to greatest** since they're the simpler fractions. In fact, the story here is not too different from that of integers: we simply **analyze the digits that appear in the numbers one by one**, starting from the left side.

For instance, if you want to compare `23.1457`

and `23.1349`

, then **we begin with the left-most digits** in the two numbers. Both of them are `2`

, so we move on to the next. Then we have `3`

-s, so again we go one further to the left, and the same for `1`

-s. Finally, we arrive at two different digits: `4`

and `3`

. Since `4 > 3`

, **the first number is larger than the second** (we don't have to look at the last digits).

Note that if both numbers are negative, then the process is the same, but **the final conclusion is the opposite**: if a digit of the first number is larger, the second number is the greater one. Also, remember that if one of the compared values has fewer digits after the decimal dot `.`

, then it **has zeros in the consecutive places**.

Next, let's take a look at **ordering fractions from least to greatest**. Unfortunately, this task is slightly more complicated.

## Ordering fractions from least to greatest

Let's take the example from the beginning of the above section: `2/5`

and `3/8`

. One way to compare them is to convert both to decimals. This would give:

`2/5 = 0.4`

, `3/8 = 0.375`

.

This way, we're back to the problem of ordering decimals from least to greatest, which **is relatively simple**.

However, not all fractions have a *nice* decimal representation. Some of them are given by **infinitely many digits** after the dot! It seems like we need to find another way to compare them.

We will use the so-called equivalent fractions. This method may take a little time with larger numbers, but in comparison to converting to decimals, **it's a flawless algorithm** for ordering fractions from least to greatest.

We turn both entries into values **with the same denominator**. In fact, we can always multiply a fraction's nominator and denominator by an arbitrary number (but the same one, mind you!), and the value of the expression **will stay the same**. However, it's not so easy to find something which we can obtain in this way for both fractions.

The brute-force method would be to multiply the two denominators. However, if you'd like to be a bit more subtle, you can choose their least common multiple. In fact, in our case, since the denominators are coprime (i.e., have no common factors), those two methods **give the same result**: `40`

.

We know that `40 = 5 * 8`

, so to turn `2/5`

into an equivalent fraction with denominator `40`

, **we multiply its top and bottom by** `8`

:

`2/5 = (2 * 8) / (5 * 8) = 16/40`

.For `3/8`

, **we multiply by** `5`

instead:

`3/8 = (3 * 5) / (8 * 5) = 15/40`

.Now, we see that our initial task boiled down to **comparing** `16/40`

**and** `15/40`

. Thanks to our method, we can safely say that **the first one is larger** since `16 > 15`

. (Note that if the two fractions were negative, to begin with, the whole reasoning would be the same but **give the opposite result**, i.e., we'd get `-2/5 < -3/8`

because `-16/40 < -15/40`

.)

Hopefully, ordering decimals and fractions from least to greatest should be no biggie after reading the two sections. But what if we want to **reverse the sorting**? What if we want to put the numbers in order but **from greatest to least**? How do we do that? And does the least to greatest calculator have such an option?

**Good news**, my dear padawan: the answers are, respectively, "*It's easy*" and "*Of course!*" All we need is in the next section.

## Ascending order vs. descending order

So far, we've shown **how to order numbers from least to greatest**, i.e., in so-called **ascending order**. However, it so happens that we sometimes need to have the values sorted **from greatest to least**. We say then that we list the numbers in **descending order** (since the entries get lower with every step, just like descending a staircase).

Fortunately, **switching from ascending to descending order is super easy**: we simply invert the inequality signs in our calculations (or in algorithms, if we use them). For instance, we can change our **bubble sort** from the first section to make it **a number sorter working from greatest to least**. If we, again, have a list of entries `x₁`

, `x₂`

, `x₃`

,..., `xₙ`

, then, in this case, the algorithm steps are (the **bolded part** is the only thing that changed):

- Set
`k = 1`

. - If the
`k`

-th entry**is smaller**than the`(k+1)`

-th, make them swap places and remember that something changed. If not, don't change anything. - If
`k < n - 1`

, increase`k`

by`1`

, and repeat from point 2. Otherwise, recall if something changed in this run of the algorithm. If yes, repeat from point 1. If not, end the algorithm.

**A piece of cake**, isn't it?

To finish the section, let us mention that **our least to greatest calculator works, by default, in ascending order**. However, we can easily convert it to a descending one: simply go to **the advanced mode** and choose the correct option under "*Order*."

**This concludes the theoretical part** of the article. We hope you enjoyed it as much as we did and are ready to face **a nice example** that we've prepared especially for you!

## Example: using the least to greatest calculator

There are not too many days left before Christmas, which can only mean one thing - **it's time to look for presents** for your family. With the pandemic raging on and a discussion about a lockdown reappearing, you decide to choose the safest way: **you go online shopping**.

You know what the first gift will be: **a book**. After all, these crazy times are quite good to catch up with your reading. You go to the website of your choice and type in the genre you know will agree with the person's taste. You see **over a hundred results**, so you decide to limit yourself to **the top 10**. Their prices are:

`$8.25`

, `$7.00`

, `$16.85`

, `$13.99`

, `$10.50`

, `$7.00`

, `$14.50`

, `$11.00`

, `$11.99`

, `$8.99`

.

The titles don't tell you much, so you choose **pragmatism over randomness** and focus on the price. To help you decide, you'd like to **put the numbers in order**. Unfortunately, the site insists on listing the products according to how many copies the site sold recently. Good thing we have **Omni's least to greatest calculator** to take care of the problem!

In our tool, we see variable fields marking consecutive entries of our dataset. We input the prices from the list above one by one. Note how initially we can only see eight boxes, but **new ones appear** the moment we seem to reach the limit (in fact, you can input **up to fifty values**). Also, observe how the least to greatest calculator shows the numbers in ascending order already for two entries and adjusts the results with every new value. Once we give the last one, **we can read off the sorted list underneath**.

Before we finish for today, let's take the opportunity to see **how to order the numbers from least to greatest by hand**. We'll use the bubble number sorter introduced in the first section.

We've already learned about ordering decimals from least to greatest in the dedicated section, so we jump straight to the algorithm. We begin by **taking the first entry and comparing it to the second**. Since `$8.25 > $7.00`

, we swap the two values. Our new list is:

`$7.00`

, `$8.25`

, `$16.85`

, `$13.99`

, `$10.50`

, `$7.00`

, `$14.50`

, `$11.00`

, `$11.99`

, `$8.99`

.

Next, **we move to the second number** (which is now `$8.25`

) and compare it to the third. This time, we have `$8.25 < $16.85`

, so **we change nothing**. Then, we have `$16.85 > $13.99`

for the third and fourth values, so they swap places.

All in all, the first run through the dataset returns

`$7.00`

, `$8.25`

, `$13.99`

, `$10.50`

, `$7.00`

, `$14.50`

, `$11.00`

, `$11.99`

, `$8.99`

, `$16.85`

.

We have made some (i.e., **not zero**) swaps, so **we repeat the algorithm** starting from the first entry. Just so that you don't fall asleep with descriptions of this repetitive procedure, we present below a table with **the list at consecutive runs of the algorithm**.

Run\Entry |
x₁ |
x₂ |
x₃ |
x₄ |
x₅ |
x₆ |
x₇ |
x₈ |
x₉ |
x₁₀ |
---|---|---|---|---|---|---|---|---|---|---|

0th |
$8.25 | $7.00 | $16.85 | $13.99 | $10.50 | $7.00 | $14.50 | $11.00 | $11.99 | $8.99 |

1st |
$7.00 | $8.25 | $13.99 | $10.50 | $7.00 | $14.50 | $11.00 | $11.99 | $8.99 | $16.85 |

2nd |
$7.00 | $8.25 | $10.50 | $7.00 | $13.99 | $11.00 | $11.99 | $8.99 | $14.50 | $16.85 |

3rd |
$7.00 | $8.25 | $7.00 | $10.50 | $11.00 | $11.99 | $8.99 | $13.99 | $14.50 | $16.85 |

4th |
$7.00 | $7.00 | $8.25 | $10.50 | $11.00 | $8.99 | $11.99 | $13.99 | $14.50 | $16.85 |

5th |
$7.00 | $7.00 | $8.25 | $10.50 | $8.99 | $11.00 | $11.99 | $13.99 | $14.50 | $16.85 |

6th |
$7.00 | $7.00 | $8.25 | $8.99 | $10.50 | $11.00 | $11.99 | $13.99 | $14.50 | $16.85 |

7th |
$7.00 | $7.00 | $8.25 | $8.99 | $10.50 | $11.00 | $11.99 | $13.99 | $14.50 | $16.85 |

Observe how **the 6th and 7th run return the same result**. That is because, in the end, the algorithm needs one last iteration to be sure that we've indeed put the numbers in order.

All in all, we see that once we sort **the prices in ascending order**, we get

`$7.00`

, `$7.00`

, `$8.25`

, `$8.99`

, `$10.50`

, `$11.00`

, `$11.99`

, `$13.99`

, `$14.50`

, `$16.85`

.

Now we just need to make sure the sales tax is included, and then it's just a matter of deciding **how much you want to spend**. Does more expensive mean better?