Conversation
sort/selection.py
Outdated
| """We make two loop. if an element is smaller than "index_min_number", | ||
| we change "index_min_number" we permut first element with element | ||
| at this index. We do it again for second element of the list | ||
| until end of the list """ |
There was a problem hiding this comment.
Ici devrait plutôt être un commentaire généraliste : les détails doivent être commentés au fur et à mesure pour faciliter la lecture
sort/selection.py
Outdated
| temp: int = array[increment] | ||
| array[increment] = array[index_min_number] | ||
| array[index_min_number] = temp |
There was a problem hiding this comment.
Trouver comment faire en une seule ligne, sans variable intermédiaire ;)
sort/selection.py
Outdated
|
|
||
| for increment in range(len(array)): | ||
| index_min_number: int = increment | ||
| for implementation in range(increment, len(array)): |
There was a problem hiding this comment.
implementation est un curieux nom de variable pour ce contexte
sort/insertion.py
Outdated
| or we find an element smaller. We do this the length of the list. | ||
| So We insert one element between other""" | ||
| for increment in range(len(array)): | ||
| for implementation in range(increment): |
There was a problem hiding this comment.
implementation est un curieux nom de variable pour ce contexte
sort/insertion.py
Outdated
| if array[increment] < array[implementation]: | ||
| temp: int = array[implementation] | ||
| array[implementation] = array[increment] | ||
| array[increment] = temp |
There was a problem hiding this comment.
L'algorithme ne correspond pas tout à fait à la version directe de l'insertion sort, trop d'opérations en réalité inutiles. Utilise des print pour bien voir toutes les étapes et comparer avec l'algo tel que tu le comprend à la mainn
sort/insertion.py
Outdated
| @@ -1,2 +1,42 @@ | |||
| """ | |||
| Selon moi, Le tri par insertion va regarder le deuxieme element de la liste | |||
| et le placer avant ou après le premier si il est plus petit ou non. Puis faire | |||
sort/fusion.py
Outdated
| return merge(sort(array[:len(array) // 2]), sort(array[len(array) // 2:])) | ||
|
|
||
|
|
||
| def merge(array_gauche: list[int], array_droite: list[int]) -> list[int]: |
sort/fusion.py
Outdated
| if (array_gauche == []): | ||
| new_array += array_droite | ||
| return new_array | ||
| elif (array_droite == []): | ||
| new_array += array_gauche | ||
| return new_array |
There was a problem hiding this comment.
Bien, faisable de façon plus courte, mais c'est du détail
|
Quelques imprécisions dans les réponses (par exemple le tri python ne peut pas être de complexité N même s'il est très efficace). |
No description provided.