Algorithm Simulator — Tunisian Bac 2027

Algorithm workshop

Your bac algorithms, in motion

Syllabus algorithms

01

Selection sort

Assignment
i = 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 TriSelection
2Tableau T[n] : Entiers
3i, j, posmin, temp : Entiers
4Début
5 Pour i De 0 À n-2 Faire
6 posmin ← i
7 Pour j De i+1 À n-1 Faire
8 Si T[j] < T[posmin] Alors
9 posmin ← j
10 FinSi
11 FinPour
12 temp ← T[i]
13 T[i] ← T[posmin]
14 T[posmin] ← temp
15 FinPour
16Fin
Python
def tri_selection(T):
n = len(T)
for i in range(n - 1):
posmin = i
for j in range(i + 1, n):
if T[j] < T[posmin]:
posmin = j
temp = T[i]
T[i] = T[posmin]
T[posmin] = temp
# Exemple
T = [41, 12, 87, 3, 65]
tri_selection(T)
print(T)