8000 Merge pull request #82 from vbrazo/add-merge-sort · BrentMat/Algorithms-Explanation@930f6d5 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 930f6d5

Browse files
authored
Merge pull request TheAlgorithms#82 from vbrazo/add-merge-sort
Add Merge Sort pt-br
2 parents 37888a6 + 926f6b2 commit 930f6d5

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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

Comments
 (0)
0