Trabalho FIO
Trabalho FIO
Trabalho FIO
1
Index
1. Introduction to Sorting Algorithms………………………………………
3
2. Comparison-based Algorithms………………………………………..…3
2.1. Bubble Sort…….…………………………………………………….4
2.2. Insertion Sort…………………………………………………………
5
2.3. Selection
Sort………………………………………………………...6
2.4. Merge Sort…………………………………………………………...7
2.5. Quick Sort……………………………………………………………7
2.6. Heap Sort…………………………………………………………….8
3. Non-Comparison-based Algorithms……………………………………..9
3.1. Counting
Sort………………………………………………………...9
3.2. Radix Sort…………………………………………………………..10
4. Real World Applications………………………………………………..11
4.1. Databases…………………………………………………………...11
4.2. E-commerce………………………………………………………...11
4.3. Telecommunications…………………………………………….….11
4.4. GPS and Mapping Services…………………………………….…..12
5. Future Developments……………………………………………….….12
6.Conclusion………………………………………………………….…..12
7.Bibliography……………………………………………………………13
Illustration Index
Figure 1. Bubble Sort Illustration…………………………………………..4
Figure 2. Insertion Sort
Illustration………………………………………....5
Figure 3. Selection Sort Illustration…………………………………………
6
2
Figure 4. Merge Sort Illustration……………………………………...
…….7
Figure 5. Quick Sort Illustration……………………………………..……..8
Figure 6. Counting Sort Illustration………………………………...………
9
Figure7.Radix Sort Illustration……………………………………………10
Some common sorting algorithms are Bubble Sort, Insertion Sort, Selection
Sort, Merge Sort, etc. and all of them will be explored throughout the
presentation, with the mention of best-case and worst-case scenarios and
practical considerations that influence the selection of a particular
algorithm for a given task.
2. Comparison-based Algorithms
3
Comparison-based algorithms are a class of sorting algorithms that rely on
pairwise comparisons between elements to determine their relative order.
This type of algorithm is not very efficient and is mainly used for
educational purposes or for small datasets.
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range (0, n - i - 1):
4
if arr[j] > arr [j + 1]:
arr[j], arr [j + 1] = arr[j + 1], arr[j]
This is an efficient method if the datasets are small or partially sorted and
has the advantage that it does not require additional memory for the sorting.
def insertion_sort(arr):
for i in range(1, len(arr)):
key = arr[i]
j=i-1
5
while j >= 0 and key < arr[j]:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
6
Figure 3. Selection sort Illustration
def selection_sort(arr):
n = len(arr)
for i in range(n - 1):
min_index = i
for j in range(i + 1, n):
if arr[j] < arr[min_index]:
min_index = j
arr[i], arr[min_index] = arr[min_index], arr[i]
7
From all of the algorithms presented up until now, it is the most efficient
one because it is used in large datasets. It does, however, require additional
space for the merging process, so it is not an in-place sorting method.
With good pivot selection strategies and optimizations, Quick sort is often
faster in practice than others, making it a popular choice for sorting.
8
Figure 5. Quick sort Illustration
It does not need additional memory for sorting, although it is not very used
in practical performance on modern computers.
3. Non-comparison-based Algorithm
Non-comparison-based algorithms are sorting algorithms that do not rely
on comparing individual elements to determine their order. Instead, these
9
algorithms exploit other characteristics of data, such as counting
occurrences or considering the structure of the elements.
This algorithm works well when the range of input values is reasonably
small, and it preserves the relative order of equal elements. It’s not suitable
for large input values because it requires additional space proportional to
the range.
10
positions. It processes the input from the least significant digit (LSD) to the
most significant or vice-versa, placing the elements into buckets based on
the value of the current digit.
11
Each field in which we apply these algorithms can find advantages and
disadvantages, therefore it is hard to precisely mention which algorithm is
ideal for a certain application.
4.1. Databases
Sorting is crucial for database systems to efficiently organize records based
on different preferred fields.
4.2. E-commerce
Online shopping platforms use sorting algorithms to display products in a
user-friendly manner, for example when we filter our search according to
price, popularity, customer satisfaction, between many others.
4.3. Telecommunications
Call routing systems use sorting to manage and prioritize incoming calls
based on factors such as caller priority, locations, urgency, etc.
12
Many other aspects of our lives are ruled by sorting algorithms and without
these the world would not function the way that it does.
5. Future Developments
Discussing future developments in this area involves considering
advancements in technology, computing architectures, and the evolving
nature of data. However, there are some points to be mentioned about the
future of sorting algorithms.
6. Conclusion
This work has described a vast variety of sorting algorithms, both
traditional comparison-based and non-comparison, giving insights about
each method and its purposes.
13
paradigm. These algorithms go beyond mere comparisons, demonstrating
efficiency in scenarios where traditional methods may prove less effective.
These methods have ended up being powerful engineering tools and the
journey through the exploration of soring algorithms must not come to an
end, because the more we dive and discover their intricacies , the more our
world will evolve in unimaginable manners.
7. Bibliography
1.https://www.freecodecamp.org/news/sorting-algorithms-explained-with-
2.examples-in-python-java-and-c/
3.https://en.wikipedia.org/wiki/Sorting_algorithm
4.https://www.geeksforgeeks.org/sorting-algorithms/
5.https://m.youtube.com/watch?v=l7-
f9gS8VOs&pp=ygUWI3NvcnRhbGdvcml0aG1zc29ydGluZw%3D%3D
14
15