{"id":140,"date":"2026-07-14T08:27:24","date_gmt":"2026-07-14T08:27:24","guid":{"rendered":"https:\/\/blog.csfree.org\/?p=140"},"modified":"2026-07-15T15:07:04","modified_gmt":"2026-07-15T15:07:04","slug":"selection-sort-a-step-by-step-guide","status":"publish","type":"post","link":"https:\/\/blog.csfree.org\/index.php\/2026\/07\/14\/selection-sort-a-step-by-step-guide\/","title":{"rendered":"Selection Sorting &#8211; How does it work internally?"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Selection Sorting &#8211; How does it work internally?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If we HAVE to speak about <strong>Sorting Techniques<\/strong>, <strong>Selection Sorting <\/strong>is another important <strong>sorting<\/strong>&#8211;<strong>algorithm<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But first things first-<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is Sorting?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">At its core,&nbsp;<strong>sorting<\/strong>&nbsp;is just the process of&nbsp;<strong>arranging&nbsp;<\/strong>a messy collection of items into a specific, meaningful order.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are two examples of sorting, we go through every day life:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Numerical Order:<\/strong>&nbsp;Arranging numbers from smallest to largest (1, 2, 3\u2026) or largest to smallest (99, 98, 97\u2026).<\/li>\n\n\n\n<li><strong>Alphabetical Order:<\/strong>&nbsp;Arranging words or strings from A to Z (like a phonebook contact list) or Z to A.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is Selection Sorting?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Imagine you are holding a handful of unsorted playing cards, and you want to arrange them from smallest to largest. What\u2019s your natural instinct? You scan through all the cards, find the absolute lowest one, and pull it to the very front. Then, you look at the remaining cards, find the next lowest one, and place it right behind the first.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That is exactly how <strong>Selection Sort<\/strong> works. In computer science, <strong>Selection Sort<\/strong> is a fundamental, comparison-based sorting algorithm that operates on a direct, scanning principle. Instead of continuously swapping adjacent elements, it repeatedly steps through the unorganized portion of a data structure, scans the remaining elements to identify the absolute minimum (or maximum) value, and performs a single swap to place it into its final, correct position.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By maintaining a growing, sorted subarray at the beginning of the structure and shrinking the unsorted boundary with each pass, it systematically organizes data with a highly predictable, deterministic execution pattern.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why it\u2019s better than Bubble Sort:<\/strong> While <strong>Bubble Sort <\/strong>frantically swaps elements constantly as it walks through the array, <strong>Selection Sort <\/strong>stays calm. It only makes <strong>one swap per pass<\/strong>, drastically reducing unnecessary memory writes!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Its characters include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>In-Place Memory Execution<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Selection Sort requires an auxiliary (extra) space complexity of <strong>O(1)<\/strong>. It performs all its element swapping directly within the original array without needing to replicate or spawn temporary storage arrays.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Predictable, Deterministic Performance<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Unlike <strong>Bubble Sort <\/strong>or <strong>Insertion Sort<\/strong>, <strong>Selection Sort <\/strong>does not care if your data is already perfectly sorted, completely reversed, or totally random. Because it is forced to scan the entire remaining unsorted section every single time just to ensure it has found the true minimum, its time complexity is always fixed:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Best Case:<\/strong> O(<math data-latex=\"n^2\"><semantics><msup><mi>n<\/mi><mn>2<\/mn><\/msup><annotation encoding=\"application\/x-tex\">n^2<\/annotation><\/semantics><\/math>)<\/li>\n\n\n\n<li><strong>Average Case:<\/strong> O(<math data-latex=\"n^2\"><semantics><msup><mi>n<\/mi><mn>2<\/mn><\/msup><annotation encoding=\"application\/x-tex\">n^2<\/annotation><\/semantics><\/math>)<\/li>\n\n\n\n<li><strong>Worst Case:<\/strong> O(<math data-latex=\"n^2\"><semantics><msup><mi>n<\/mi><mn>2<\/mn><\/msup><annotation encoding=\"application\/x-tex\">n^2<\/annotation><\/semantics><\/math>)<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong> Highly Efficient for Memory Writes<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">While its comparison count is high O(<math data-latex=\"n^2\"><semantics><msup><mi>n<\/mi><mn>2<\/mn><\/msup><annotation encoding=\"application\/x-tex\">n^2<\/annotation><\/semantics><\/math>), its swap count is exceptionally low. It performs a maximum of <strong>(n &#8211; 1) swaps<\/strong> in total. It only swaps data once per full pass, making it structurally superior to Bubble Sort if you are working on old flash memory hardware where writing to memory is drastically more expensive than reading from it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step-By-Step Example<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s see how <strong>Selection Sort algorithm <\/strong>works on using a array: <strong><code>[7, 3, 9, 2, 6, 4]<\/code><\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <strong><code>|<\/code><\/strong> bar separates the <strong>sorted section<\/strong> (left) from the <strong>unsorted section<\/strong> (right).<\/li>\n\n\n\n<li>In each pass, we scan the unsorted section to find the <strong>minimum<\/strong>, then swap it to the front of that section.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Step 1: The First Big Scan<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Starting array:<\/strong> <code>[7, 3, 9, 2, 6, 4]<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We assume the first element (<code>7<\/code>) is our temporary minimum. Now we scan the rest to find something smaller:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Compare current min (7) with 3 : Is 3 &lt; 7? <strong>Yes<\/strong> -&gt; New tracked min = <strong>3<\/strong><\/li>\n\n\n\n<li>Compare current min (3) with 9 : Is 9 &lt; 3? <strong>No<\/strong> -&gt; Keep tracked min = <strong>3<\/strong><\/li>\n\n\n\n<li>Compare current min (3) with 2 : Is 2 &lt; 3? <strong>Yes<\/strong> -&gt; New tracked min = <strong>2<\/strong><\/li>\n\n\n\n<li>Compare current min (2) with 6 : Is 6 &lt; 2? <strong>No<\/strong> -&gt; Keep tracked min = <strong>2<\/strong><\/li>\n\n\n\n<li>Compare current min (2) with 4 : Is 4 &lt; 2? <strong>No<\/strong> -&gt; Keep tracked min = <strong>2<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>End of Pass 1:<\/strong> The scan is complete. The absolute minimum found is <strong>2<\/strong>. We make our <strong>one single swap<\/strong> for this pass, exchanging <strong>2<\/strong> with the first element (<code>7<\/code>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Array State :<\/em> <code>[2 | 3, 9, 7, 6, 4]<\/code> <em>(The 2 is now locked in place).<\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Step 2: Finding the Next Smallest<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Active boundary:<\/strong> <code>[3, 9, 7, 6, 4]<\/code> <em>(We ignore index 0 where 2 is)<\/em> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>We assume the first element of this section (<code>3<\/code>) is our temporary minimum:<\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Compare current min (3) with 9 : Is 9 &lt; 3? <strong>No<\/strong> -&gt; Keep tracked min = <strong>3<\/strong><\/li>\n\n\n\n<li>Compare current min (3) with 7 : Is 7 &lt; 3? <strong>No<\/strong> -&gt; Keep tracked min = <strong>3<\/strong><\/li>\n\n\n\n<li>Compare current min (3) with 6 : Is 6 &lt; 3? <strong>No<\/strong> -&gt; Keep tracked min = <strong>3<\/strong><\/li>\n\n\n\n<li>Compare current min (3) with 4 : Is 4 &lt; 3? <strong>No<\/strong> -&gt; Keep tracked min = <strong>3<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>End of Pass 2:<\/strong> The scan is complete. The absolute minimum in this section is <strong>3<\/strong>. Since it&#8217;s already at the front of the active boundary, no actual swap changes its position.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Array State:<\/em> <code>[2, 3 | 9, 7, 6, 4]<\/code> <em>(The 3 is now locked in place).<\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Step 3: Shrinking the Window<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Active boundary:<\/strong> <code>[9, 7, 6, 4]<\/code> <em>(We now ignore 2 and 3)<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>We assume the first element of this section (<code>9<\/code>) is our temporary minimum:<\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Compare current min (9) with 7 : Is 7 &lt; 9? <strong>Yes<\/strong> -&gt; New tracked min = <strong>7<\/strong><\/li>\n\n\n\n<li>Compare current min (7) with 6 : Is 6 &lt; 7? <strong>Yes<\/strong> -&gt; New tracked min = <strong>6<\/strong><\/li>\n\n\n\n<li>Compare current min (6) with 4 : Is 4 &lt; 6? <strong>Yes<\/strong> -&gt; New tracked min = <strong>4<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>End of Pass 3:<\/strong> The scan is complete. The absolute minimum found is <strong>4<\/strong>. Swap <strong>4<\/strong> with the first element of this section (<code>9<\/code>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Array State:<\/em> <code>[2, 3, 4 | 7, 6, 9]<\/code> <em>(The 4 is now locked in place).<\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Step 4: Getting Closer<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Active boundary:<\/strong> <code>[7, 6, 9]<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We assume the first element of this section (<code>7<\/code>) is our temporary minimum:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Compare current min (7) with 6 : Is 6 &lt; 7? <strong>Yes<\/strong> -&gt; New tracked min = <strong>6<\/strong><\/li>\n\n\n\n<li>Compare current min (6) with 9 : Is 9 &lt; 6? <strong>No<\/strong> -&gt; Keep tracked min = <strong>6<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>End of Pass 4:<\/strong> The scan is complete. The absolute minimum found is <strong>6<\/strong>. Swap <strong>6<\/strong> with the first element of this section (<code>7<\/code>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Array State:<\/em> <code>[2, 3, 4, 6 | 7, 9]<\/code> <em>(The 6 is now locked in place).<\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Step 5: The Final Matchup<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Active boundary:<\/strong> <code>[7, 9]<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>We assume the first element of this section (<code>7<\/code>) is our temporary minimum:<\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Compare current min (7) with 9 : Is 9 &lt; 7? <strong>No<\/strong> -&gt; Keep tracked min = <strong>7<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>End of Pass 5:<\/strong> The scan is complete. The absolute minimum is <strong>7<\/strong>. It is already in place.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>Array State:<\/em> <code>[2, 3, 4, 6, 7 | 9]<\/code> <em>(The 7 is now locked in place).<\/em><\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Step 6: The Last Element standing<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Active boundary:<\/strong> <code>[9]<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The algorithm looks at the final remaining element. Because an array of size n only requires (n-1) passes to fully organize, the final item (<code>9<\/code>) is automatically in its correct position by default.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Final Sorted Array:<\/strong> <code>[2, 3, 4, 6, 7, 9]<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Following is a program of the general&nbsp;<strong>Selection Sorting<\/strong>. (in C++)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>#include &lt;iostream&gt;<br>#include &lt;vector&gt;<br>#include &lt;utility&gt; \/\/ Required for std::swap<br><br>void selectionSort(std::vector&lt;int&gt;&amp; arr) {<br>    int n = arr.size();<br>    <br>    \/\/ Outer loop: shifts the boundary of the sorted section<br>    for (int i = 0; i &lt; n - 1; i++) {<br>        \/\/ Assume the current first element of the unsorted section is the minimum<br>        int minIndex = i;<br>        <br>        \/\/ Inner loop: scans the remaining unsorted elements to find the true minimum<br>        for (int j = i + 1; j &lt; n; j++) {<br>            if (arr[j] &lt; arr[minIndex]) {<br>                minIndex = j; \/\/ Update index of the smallest element found<br>            }<br>        }<br>        <br>        \/\/ Optimization: Only swap if a smaller element was actually found<br>        if (minIndex != i) {<br>            std::swap(arr[i], arr[minIndex]);<br>        }<br>    }<br>}<br><br>\/\/ Helper function to print the vector layout<br>void printVector(const std::vector&lt;int&gt;&amp; arr) {<br>    for (int num : arr) {<br>        std::cout &lt;&lt; num &lt;&lt; \" \";<br>    }<br>    std::cout &lt;&lt; \"\\n\";<br>}<br><br>int main() {<br>    \/\/ Using the 6-digit array from our walkthrough example<br>    std::vector&lt;int&gt; numbers = {7, 3, 9, 2, 6, 4 };<br>    <br>    std::cout &lt;&lt; \"Original Array: \";<br>    printVector(numbers);<br>    <br>    selectionSort(numbers);<br>    <br>    std::cout &lt;&lt; \"Sorted Array:   \";<br>    printVector(numbers);<br>    <br>    return 0;<br>}<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Just like with <strong>Bubble Sort<\/strong>, switching your <strong>Selection Sort <\/strong>from ascending (smallest to largest) to <strong>descending order<\/strong> (largest to smallest) requires changing <strong>one single character<\/strong> in your code logic.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The updated code in Descending order will be:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>void selectionSortDescending(std::vector&lt;int&gt;&amp; arr) {\n    int n = arr.size();\n    \n    \/\/ Outer loop: shifts the boundary of the sorted section\n    for (int i = 0; i &lt; n - 1; i++) {\n        \/\/ Assume the current first element is the largest (maximum)\n        int maxIndex = i;\n        \n        \/\/ Inner loop: scans the remaining elements to find the true maximum\n        for (int j = i + 1; j &lt; n; j++) {\n            \/\/ FLIPPED: Change '&lt;' to '&gt;' to find the largest remaining number\n            if (arr&#91;j] &gt; arr&#91;maxIndex]) {\n                maxIndex = j; \/\/ Update index of the largest element found\n            }\n        }\n        \n        \/\/ Only swap if a larger element was actually found down the line\n        if (maxIndex != i) {\n            std::swap(arr&#91;i], arr&#91;maxIndex]);\n        }\n    }\n}<\/strong><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How is it different from <strong>Bubble Sort<\/strong>?<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-center\" data-align=\"center\">Feature\/Trait<\/th><th class=\"has-text-align-center\" data-align=\"center\">Bubble Sort<\/th><th class=\"has-text-align-center\" data-align=\"center\">Selection Sort<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Core Concept<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\">Consistently compares and <strong>swaps adjacent elements<\/strong> if they are out of order, forcing values to drift to the end.<\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Scans the entire remaining array<\/strong> to find the absolute minimum value, then drops it into place with a single swap.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Number of Swaps<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>High (O(<\/strong><math data-latex=\"n^2\"><semantics><msup><mi>n<\/mi><mn>2<\/mn><\/msup><annotation encoding=\"application\/x-tex\">n^2<\/annotation><\/semantics><\/math><strong>)):<\/strong> Continuous swapping throughout every pass. Memory-heavy on writes.<\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Low (O(n)):<\/strong> Performs at most <strong>(n &#8211; 1)<\/strong> total swaps (maximum 1 swap per pass). Excellent for low-write memory.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Algorithm Stability<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Stable:<\/strong> Identical elements retain their original relative positioning because adjacent elements are only swapped if one is strictly greater\/less than the other.<\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Unstable:<\/strong> Long-distance swaps can easily bypass identical elements, destroying their original order.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Adaptive Optimization<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Highly Adaptive:<\/strong> Can be optimized with a <code>swapped<\/code> flag to exit early if the array becomes sorted mid-execution, giving it a <strong>Best-Case Time Complexity of O(n)<\/strong>.<\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Non-Adaptive:<\/strong> Cannot look ahead or stop early. It is blindly forced to run all passes and comparisons regardless of whether the array is already sorted, keeping its <strong>Best Case at O(<\/strong><math data-latex=\"n^2\"><semantics><msup><mi>n<\/mi><mn>2<\/mn><\/msup><annotation encoding=\"application\/x-tex\">n^2<\/annotation><\/semantics><\/math><strong>)<\/strong><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Time Complexity<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\">Best: <strong>O<\/strong>(n) (Optimized)<br><br>Avg: <strong>O(<\/strong><math data-latex=\"n^2\"><semantics><msup><mi>n<\/mi><mn>2<\/mn><\/msup><annotation encoding=\"application\/x-tex\">n^2<\/annotation><\/semantics><\/math><strong>)<\/strong><br><br>Worst: <strong>O(<\/strong><math data-latex=\"n^2\"><semantics><msup><mi>n<\/mi><mn>2<\/mn><\/msup><annotation encoding=\"application\/x-tex\">n^2<\/annotation><\/semantics><\/math><strong>)<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\">Best: <strong>O(<\/strong><math data-latex=\"n^2\"><semantics><msup><mi>n<\/mi><mn>2<\/mn><\/msup><annotation encoding=\"application\/x-tex\">n^2<\/annotation><\/semantics><\/math><strong>)<\/strong><br><br>Avg: <strong>O(<\/strong><math data-latex=\"n^2\"><semantics><msup><mi>n<\/mi><mn>2<\/mn><\/msup><annotation encoding=\"application\/x-tex\">n^2<\/annotation><\/semantics><\/math><strong>)<\/strong><br><br>Worst: <strong>O(<\/strong><math data-latex=\"n^2\"><semantics><msup><mi>n<\/mi><mn>2<\/mn><\/msup><annotation encoding=\"application\/x-tex\">n^2<\/annotation><\/semantics><\/math><strong>)<\/strong><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Space Complexity<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>O(1)<\/strong> (In-place)<\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>O(1) <\/strong>(In-place)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Selection Sort <\/strong>introduces a completely different philosophy to basic sorting. While it shares the exact same <strong>O(<\/strong><math data-latex=\"n^2\"><semantics><msup><mi>n<\/mi><mn>2<\/mn><\/msup><annotation encoding=\"application\/x-tex\">n^2<\/annotation><\/semantics><\/math><strong>)<\/strong> time complexity as Bubble Sort, it replaces chaotic, adjacent swapping with a patient, scanning approach\u2014making only one decisive move per pass.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Although it isn&#8217;t designed for massive datasets, its strict constraint of a maximum of (n-1) swaps makes it highly efficient for specialized hardware where reducing memory writes is critical.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Selection Sorting &#8211; How does it work internally? If we HAVE to speak about Sorting Techniques, Selection Sorting is another [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[66,49,50],"tags":[59,65,60,53,64,35,62,56],"class_list":["post-140","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-data-structures","category-sorting","tag-big-o-notation","tag-c","tag-data-structures","tag-dsa","tag-learning-to-code","tag-programming","tag-selection-sorting","tag-sorting-algorithms"],"_links":{"self":[{"href":"https:\/\/blog.csfree.org\/index.php\/wp-json\/wp\/v2\/posts\/140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.csfree.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.csfree.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.csfree.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.csfree.org\/index.php\/wp-json\/wp\/v2\/comments?post=140"}],"version-history":[{"count":6,"href":"https:\/\/blog.csfree.org\/index.php\/wp-json\/wp\/v2\/posts\/140\/revisions"}],"predecessor-version":[{"id":178,"href":"https:\/\/blog.csfree.org\/index.php\/wp-json\/wp\/v2\/posts\/140\/revisions\/178"}],"wp:attachment":[{"href":"https:\/\/blog.csfree.org\/index.php\/wp-json\/wp\/v2\/media?parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.csfree.org\/index.php\/wp-json\/wp\/v2\/categories?post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.csfree.org\/index.php\/wp-json\/wp\/v2\/tags?post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}