-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #343 from lcgabaldon/python_eng_translations
Translated Python algorithms and comments to English.
- Loading branch information
Showing
19 changed files
with
240 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
""" Implementação do algoritmo de busca binária com recursão """ | ||
""" Recursive Binary Search Algorithm in Python """ | ||
|
||
|
||
def busca_binaria(valor, vetor, esquerda, direita): | ||
def binary_search(value, vector, left, right): | ||
""" | ||
Implementação de um algoritmo de busca binária com recursão. | ||
Implementation of a binary search algorithm with recursion. | ||
Argumentos: | ||
valor: Any. Valor a ser buscado na lista | ||
vetor: list. lista ordenada na qual o valor será buscado | ||
esquerda: Any. Valor inicial da metade buscada | ||
direita: Any. Valor final da metade buscada | ||
Arguments: | ||
value: Any. Value to be searched for in the list | ||
vector: List. Ordered list in which value will be searched for | ||
left: Any. Leftmost index for binary search | ||
right: Any. Rightmost index for binary search | ||
Retorna o índice do valor em "vetor" ou -1 caso não exista nela. | ||
Returns the index of value in vector; returns -1 if value not found in vector | ||
""" | ||
meio = int((esquerda + direita) / 2) | ||
middle = int((left + right) / 2) | ||
|
||
if esquerda <= direita: | ||
if valor > vetor[meio]: | ||
esquerda = meio + 1 | ||
return busca_binaria(valor, vetor, esquerda, direita) | ||
elif valor < vetor[meio]: | ||
direita = meio - 1 | ||
return busca_binaria(valor, vetor, esquerda, direita) | ||
return meio | ||
if left <= right: | ||
if value > vector[middle]: | ||
left = middle + 1 | ||
return binary_search(value, vector, left, right) | ||
elif value < vector[middle]: | ||
right = middle - 1 | ||
return binary_search(value, vector, left, right) | ||
return middle | ||
return -1 | ||
|
||
|
||
lista = [0, 1, 3, 5, 6, 7, 8, 9, 10, 11, 12] | ||
print(busca_binaria(12, lista, 0, len(lista) - 1)) | ||
list = [0, 1, 3, 5, 6, 7, 8, 9, 10, 11, 12] | ||
print(binary_search(12, list, 0, len(list) - 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
""" | ||
Arvore Binaria de Busca em Python | ||
""" | ||
""" Binary Search Tree in Python """ | ||
|
||
|
||
class TreeNode: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
""" Implementação de uma árvore binária """ | ||
""" Binary Tree in Python """ | ||
|
||
|
||
class Node: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
# Algoritmo de ordenação Counting sort em Python | ||
""" Counting sort in Python """ | ||
|
||
import random | ||
|
||
|
||
def counting_sort(arr): | ||
# Encontra o maior elemento na lista | ||
"""Finding the max element in the list""" | ||
k = max(arr) + 1 | ||
|
||
# Inicializa o array de contagem com zeros | ||
""" Initialing count array of len k with 0's """ | ||
count = [0] * k | ||
|
||
# Conta a frequência de cada elemento | ||
""" Counts frequency of each element """ | ||
for i in arr: | ||
count[i] += 1 | ||
|
||
# Atualiza o array de contagem para refletir a posição correta de cada elemento na lista ordenada | ||
""" Updates count array to reflect the correct position of each element in the sorted list """ | ||
for i in range(1, k): | ||
count[i] += count[i - 1] | ||
|
||
# Inicializa o array de resultado com zeros | ||
""" Initializing result list with 0's """ | ||
result = [0] * len(arr) | ||
|
||
# Preenche o array de resultado com os elementos ordenados | ||
""" Fill result array with the sorted elements""" | ||
for i in reversed(arr): | ||
result[count[i] - 1] = i | ||
count[i] -= 1 | ||
|
||
return result | ||
|
||
|
||
# Gera uma lista de n números aleatórios | ||
""" Generate a list of n random integers """ | ||
n = 10 | ||
lista = [random.randint(0, 100) for _ in range(n)] | ||
list = [random.randint(0, 100) for _ in range(n)] | ||
|
||
# Imprime a lista original sem ordenação | ||
print(f"Lista Original: {lista}") | ||
""" Prints original, unsorted list""" | ||
print(f"List: {list}") | ||
|
||
# Ordena a lista utilizando o algoritmo de Counting Sort | ||
lista_ordenada = counting_sort(lista) | ||
""" Sorts list using counting sort algorithm """ | ||
sorted_list = counting_sort(list) | ||
|
||
# Imprime a lista ordenada | ||
print(f"Lista Ordenada: {lista_ordenada}") | ||
""" Prints sorted list """ | ||
print(f"Sorted list: {sorted_list}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.