From f2205cf799e10cf5329788b05a2d3f99dd117616 Mon Sep 17 00:00:00 2001 From: Aditya Date: Tue, 28 May 2024 11:06:18 +0530 Subject: [PATCH] update selection sort algorithm --- content/docs/dsa/sorting/selection-sort.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/content/docs/dsa/sorting/selection-sort.md b/content/docs/dsa/sorting/selection-sort.md index 8499b87..f274e43 100644 --- a/content/docs/dsa/sorting/selection-sort.md +++ b/content/docs/dsa/sorting/selection-sort.md @@ -28,6 +28,15 @@ Here's how Selection Sort works step by step: 5. Repeat steps 2-4 until the entire list is sorted. +``` +for i := 1 to n do +{ + Examine a[i] to a[n] and suppose + the smallest element is at a[j]; + Interchange a[i] and a[j]; +} +``` + The algorithm's time complexity is O(n2) for all cases (worst, average, and best), making it inefficient on large lists compared to more advanced algorithms like quicksort, mergesort or heapsort. However, Selection Sort has its advantages such as simplicity and performing only a