update translation insertion-sort (#36554)

fix: images link
add: markdown identifier to code language
This commit is contained in:
Cleo Aguiar
2019-08-08 14:19:09 -03:00
committed by Randell Dawson
parent 5204933fca
commit bb4cb7a4d2

View File

@ -31,6 +31,7 @@ Passo 1 :
Passo 2 : Passo 2 :
![[3 8 5 1 4 2]](https://github.com/blulion/freecodecamp-resource/blob/master/insertion_sort/2.png?raw=true) ![[3 8 5 1 4 2]](https://github.com/blulion/freecodecamp-resource/blob/master/insertion_sort/2.png?raw=true)
``` ```
key = 5 //2nd index key = 5 //2nd index
@ -42,6 +43,7 @@ Passo 2 :
Etapa 3 : Etapa 3 :
![[3 5 8 1 4 2]](https://github.com/blulion/freecodecamp-resource/blob/master/insertion_sort/3.png?raw=true) ![[3 5 8 1 4 2]](https://github.com/blulion/freecodecamp-resource/blob/master/insertion_sort/3.png?raw=true)
``` ```
key = 1 //3rd index key = 1 //3rd index
@ -57,6 +59,7 @@ Etapa 3 :
Passo 4 : Passo 4 :
![[1 3 5 8 4 2]](https://github.com/blulion/freecodecamp-resource/blob/master/insertion_sort/4.png?raw=true) ![[1 3 5 8 4 2]](https://github.com/blulion/freecodecamp-resource/blob/master/insertion_sort/4.png?raw=true)
``` ```
key = 4 //4th index key = 4 //4th index
@ -72,6 +75,7 @@ Passo 4 :
Passo 5: Passo 5:
![[1 3 4 5 8 2]](https://github.com/blulion/freecodecamp-resource/blob/master/insertion_sort/5.png?raw=true) ![[1 3 4 5 8 2]](https://github.com/blulion/freecodecamp-resource/blob/master/insertion_sort/5.png?raw=true)
``` ```
key = 2 //5th index key = 2 //5th index
@ -103,8 +107,8 @@ O algoritmo abaixo é uma versão ligeiramente otimizada para evitar a troca do
arr[i+1] = key arr[i+1] = key
``` ```
Aqui está uma implementação detaied em Javascript: Aqui está uma implementação detalhada em JavaScript:
``` ```js
function insertion_sort(A) { function insertion_sort(A) {
var len = array_length(A); var len = array_length(A);
var i = 1; var i = 1;
@ -142,7 +146,7 @@ Uma implementação rápida no Swift é mostrada abaixo:
``` ```
O exemplo de Java é mostrado abaixo: O exemplo de Java é mostrado abaixo:
``` ```java
public int[] insertionSort(int[] arr) public int[] insertionSort(int[] arr)
for (j = 1; j < arr.length; j++) { for (j = 1; j < arr.length; j++) {
int key = arr[j] int key = arr[j]
@ -178,8 +182,11 @@ void insertionSort(int arr[], int n)
### Propriedades: ### Propriedades:
* Complexidade Espacial: O (1) * Complexidade Espacial: O(1)
* Complexidade do Tempo: O (n), O (n \* n), O (n \* n) para Melhor, Média, Piores Casos respectivamente * Complexidade do Tempo: O(n), O(n* n), O(n* n) para Melhor, Média, Piores Casos respectivamente
- Melhor Caso: array já está classificado
- Médio Caso: array é aleatoriamente classificado
- Pior Caso: matriz invertida é ordenada.
* Classificação no local: sim * Classificação no local: sim
* Estável: sim * Estável: sim
@ -191,3 +198,4 @@ void insertionSort(int arr[], int n)
* [Visualização de ordenação de inserção](https://www.hackerearth.com/practice/algorithms/sorting/insertion-sort/visualize/) * [Visualização de ordenação de inserção](https://www.hackerearth.com/practice/algorithms/sorting/insertion-sort/visualize/)
* [Ordenação de Inserção - MyCodeSchool](https://www.youtube.com/watch?v=i-SKeOcBwko) * [Ordenação de Inserção - MyCodeSchool](https://www.youtube.com/watch?v=i-SKeOcBwko)
* [Ordenação de Inserção - VisuAlgo](https://visualgo.net/en/sorting) * [Ordenação de Inserção - VisuAlgo](https://visualgo.net/en/sorting)