Skip to content

Joffrey-Fouche-tp-python-algo-tri #31

Open
joffrey3 wants to merge 8 commits intobcalou:mainfrom
joffrey3:main
Open

Joffrey-Fouche-tp-python-algo-tri #31
joffrey3 wants to merge 8 commits intobcalou:mainfrom
joffrey3:main

Conversation

@joffrey3
Copy link
Copy Markdown

No description provided.

@joffrey3 joffrey3 marked this pull request as ready for review November 24, 2023 08:34
@joffrey3 joffrey3 closed this Nov 24, 2023
@joffrey3 joffrey3 reopened this Nov 24, 2023
@joffrey3 joffrey3 closed this Nov 24, 2023
@joffrey3 joffrey3 reopened this Nov 24, 2023
@joffrey3 joffrey3 marked this pull request as draft November 24, 2023 13:47
@joffrey3 joffrey3 marked this pull request as ready for review November 24, 2023 15:29
Comment on lines +9 to +12
"""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 """
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +19 to +21
temp: int = array[increment]
array[increment] = array[index_min_number]
array[index_min_number] = temp
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trouver comment faire en une seule ligne, sans variable intermédiaire ;)


for increment in range(len(array)):
index_min_number: int = increment
for implementation in range(increment, len(array)):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implementation est un curieux nom de variable pour ce contexte

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):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implementation est un curieux nom de variable pour ce contexte

Comment on lines +17 to +20
if array[increment] < array[implementation]:
temp: int = array[implementation]
array[implementation] = array[increment]
array[increment] = temp
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -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
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas tout à fait, à revoir

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]:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

éviter le franglais :)

sort/fusion.py Outdated
Comment on lines +26 to +31
if (array_gauche == []):
new_array += array_droite
return new_array
elif (array_droite == []):
new_array += array_gauche
return new_array
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bien, faisable de façon plus courte, mais c'est du détail

@bcalou
Copy link
Copy Markdown
Owner

bcalou commented Dec 5, 2023

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).
Mais code clair, commenté et bien structuré. Très bien.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants