Course Programming Logic
Sorting
In many programming challenges, we are given a set of data, usually numbers, that we need to process in order to calculate what is required by the challenge.
Sometimes sorting this data set will help you when processing the solution. Other times the data set is already given sorted. In the second case, it is important that you take this information into account when thinking about the solution.
Let's take a look at a practical case. In the exercise Triple Product you are asked:
Your task in this problem is quite simple: given a vector with
elements, ordered in ascending order, name the largest product between 3 of its elements.
Note that since the elements are ordered in ascending order it is guaranteed that the largest elements will be in the last 3 positions of the array. After realizing this fact, your task will be:
Given a vector with
elements, ordered in ascending order, print the multiplication of the last 3 elements of that vector.
Complexity
Since we already have the knowledge of computational complexity learned in the last course, we can dig a little deeper here.
You should remember that sorting a list of numbers will add to your algorithm
Although sorting the data brings you an additional cost, the fact that the data is sorted can make your implementation much easier and even reduce an algorithm that would be