|
| 1 | +# Merge Sort (Algoritmo de divisão e conquista) |
| 2 | + |
| 3 | +#### Declaração do problema |
| 4 | + |
| 5 | +Dado um array de n elementos, escreva uma função para classificar o array |
| 6 | + |
| 7 | +#### Abordagem |
| 8 | + |
| 9 | +- Encontre um ponto médio e divida a matriz em metades com base no ponto médio |
| 10 | +- Chame recursivamente a função de classificação de mesclagem para ambas as metades |
| 11 | +- Junte as duas metades classificadas para obter a matriz classificada |
| 12 | + |
| 13 | +#### Complexidade de tempo |
| 14 | + |
| 15 | +`O(n log n)` |
| 16 | + |
| 17 | +#### Complexidade do Espaço |
| 18 | + |
| 19 | +`O(n)` |
| 20 | + |
| 21 | +#### Exemplo |
| 22 | + |
| 23 | +``` |
| 24 | +arr = [1, 3, 9, 5, 0, 2] |
| 25 | +
|
| 26 | +Divida a matriz em duas metades [1, 3, 9] e [5, 0, 2] |
| 27 | +
|
| 28 | +Chame recursivamente a função merge sort para ambas as metades, o que fornecerá metades ordenadas |
| 29 | +=> [1, 3, 9] e [0, 2, 5] |
| 30 | +
|
| 31 | +Agora mescle as duas metades para obter a matriz classificada [0, 1, 2, 3, 5, 9] |
| 32 | +``` |
| 33 | + |
| 34 | +#### Links de implementação de código |
| 35 | + |
| 36 | +- [Java](https://github.com/TheAlgorithms/Java/blob/master/Sorts/MergeSort.java) |
| 37 | +- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/merge_sort.cpp) |
| 38 | +- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/merge_sort.py) |
| 39 | +- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/MergeSorter.cs) |
| 40 | +- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/merge_sort.c) |
| 41 | +- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/merge_sort.rb) |
| 42 | + |
| 43 | +#### Explicação em vídeo |
| 44 | + |
| 45 | +[Um vídeo CS50 explicando o algoritmo de classificação de mesclagem](https://www.youtube.com/watch?v=EeQ8pwjQxTM) |
0 commit comments