Algorithm Simulator — Tunisian Bac 2027
Algorithm workshop
Your bac algorithms, in motion
Syllabus algorithms
№ 01
Selection sort
Assignmenti = 0posmin = 0
001 / 107
Speed
12
#
Computer science
Science sections
The simplest sort: at each pass, find the minimum of the unsorted part and place it at its position.
Pseudo-code (Bac)
1Algorithme TriSelection2Tableau T[n] : Entiers3i, j, posmin, temp : Entiers4Début5 Pour i De 0 À n-2 Faire6 posmin ← i7 Pour j De i+1 À n-1 Faire8 Si T[j] < T[posmin] Alors9 posmin ← j10 FinSi11 FinPour12 temp ← T[i]13 T[i] ← T[posmin]14 T[posmin] ← temp15 FinPour16Fin
Python
def tri_selection(T):n = len(T)for i in range(n - 1):posmin = ifor j in range(i + 1, n):if T[j] < T[posmin]:posmin = jtemp = T[i]T[i] = T[posmin]T[posmin] = temp# ExempleT = [41, 12, 87, 3, 65]tri_selection(T)print(T)