{"id":10971,"date":"2022-12-08T11:13:30","date_gmt":"2022-12-08T11:13:30","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=10971"},"modified":"2023-08-21T07:04:15","modified_gmt":"2023-08-21T07:04:15","slug":"selection-sort-implementation-program-in-c","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/","title":{"rendered":"How to Implement Selection Sort in C?"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497117917-Selection%20Sort%20in%20C.jpg\" alt=\"\" \/><\/p>\n<p>Sorting, the process of arranging elements in a specific order, lies at the heart of computer science and is a fundamental building block for a wide range of applications. From organizing data for efficient searching to enabling smoother user experiences in applications, sorting algorithms play a crucial role. One such elementary yet instructive sorting algorithm is &quot;Selection Sort.&quot;<br \/>\nThis article embarks on a journey to demystify Selection Sort in C programming language. We&#8217;ll explore the step-by-step process of how Selection Sort operates, dissect its time and space complexities, and discuss its advantages and limitations. By the end of this article, readers will have gained a clear grasp of Selection Sort&#8217;s inner workings, equipping them with essential knowledge to make informed decisions about when and how to use this algorithm effectively.<\/p>\n<h2>What is Selection Sort in C?<\/h2>\n<p>Selection Sort is a comparison-based and in-place sorting algorithm which takes an element and compares it to all other elements before placing it at its correct position in the set of elements.<\/p>\n<p>Before hopping on to the implementation of selection sort in c, let&#8217;s take a real-world example, we can assume students standing in a school assembly in an unordered manner and they must stand from shortest to tallest to make everyone see the podium without any difficulties. We will pick the first one and compare it with anyone who is shorter than the student at the front, we will keep replacing it till we keep getting a student with a shorter height.<\/p>\n<p>Once we are done finding the student who is going to stand in the first place, we move to check for the student who is going to be placed in the second position with the second shortest height.<\/p>\n<p>Till we end up with the student with the second last position, we will not be done with the selection. Similar to this, we apply logic and conditions to execute the selection sort algorithm in c.<\/p>\n<h2>Algorithm for Selection Sort in C Programming Language<\/h2>\n<p>The Selection Sort program in C to sort the array in ascending order can be implemented in a few easy steps as mentioned:<\/p>\n<ol>\n<li>Declare an array of size, n.<\/li>\n<li>Provide the n inputs such that the array is unsorted.<\/li>\n<li>Loop i, from 0 to n-2<\/li>\n<li>Inner loop j runs from i+1 to n-1<\/li>\n<li>On each iteration of j:\n<ul>\n<li>If arr[i] &gt; arr[i] then we swap the number in order to sort the array in ascending order.<\/li>\n<li>Else continue<\/li>\n<\/ul>\n<\/li>\n<li>Print the sorted array<\/li>\n<\/ol>\n<p>In this manner, the array will be sorted in ascending order will the lowest element at the start and the largest at the end position. Looking at the algorithm, its gives an idea to do the selection sort program in c.<\/p>\n<h2>Dry Run for Selection Sort in C Programming Language<\/h2>\n<p>To understand selection sort in c with more clarity, let us look at the dry run of the program.<\/p>\n<p>We have an array sorted in descending order as 20,10,8,5,1. Our task is to sort this array in ascending order using the selection sort algorithm in c. The approach to solving is as follows explained using various passes.<\/p>\n<p><strong>First Pass:<\/strong> We will compare 20 with 10 and the position will be swapped, we will still be at index i, where 10 is lying and now we will compare 10 (at index 0) with the element at index 2 i.e. 8 and swapping will be performed. Similarly, 5 and 1 will switch the position with index 3 and index 4<br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497118659-Selection%20Sort%20in%20C%201.png\" alt=\"\" \/><\/p>\n<p><strong>Second Pass:<\/strong> The first index is having the smallest element and we will start to find the number for 1st index or second smallest with 20 switching places with 10, 10 with 8 and lastly 8 with 5.<br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497118659-Selection%20Sort%20in%20C%202.png\" alt=\"\" \/><\/p>\n<p><strong>Third Pass:<\/strong> First two elements are already sorted and we will start checking from index 2, 20 will switch its places with 10 and 10 will be swapped with 8.<br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497118670-Selection%20Sort%20in%20C%203.png\" alt=\"\" \/><\/p>\n<p><strong>Fourth Pass:<\/strong> We will be standing at the second last position and also the last comparison that needs to be made between the last element and the second last, where 20 will be replaced with 10 and further winding up the selection sort program in C.<br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497118670-Selection%20Sort%20in%20C%204.png\" alt=\"\" \/><\/p>\n<p>The sorted array obtained is going to be 1,5,8,10 and 20.<\/p>\n<h2>Code for Selection Sort in C<\/h2>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_10865 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_10865 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_10865 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_10865 .wpsm_nav-tabs > li.active > a, #tab_container_10865 .wpsm_nav-tabs > li.active > a:hover, #tab_container_10865 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_10865 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_10865 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_10865 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_10865 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_10865 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_10865 .wpsm_nav-tabs > li > a:hover , #tab_container_10865 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_10865 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_10865 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_10865 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_10865 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_10865 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_10865 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_10865 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_10865 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_10865 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_10865 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_10865 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_10865\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_10865\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_10865_1\" aria-controls=\"tabs_desc_10865_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_10865\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_10865_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include&lt;stdio.h&gt;\r\nint main(){\r\n\tint a[10],i;\r\n\tint j,temp,num;\r\n\t\r\n\tprintf(&quot;Enter the number to give&#92;n&quot;);\r\n\tscanf(&quot;%d&quot;,&amp;num);\r\n\t\r\n\tfor(i=0; i&lt;num; i++){\r\n\t\tprintf(&quot;a[%d]=&#92;t&quot;,i);\r\n\t\tscanf(&quot;%d&quot;,&amp;a[i]);\r\n\t}\r\n\t\r\n\tfor(i=0; i&lt;num-1; i++){  \r\n\t\tfor(j=i+1;j&lt;num; j++){\r\n\t\t\tif(a[i]&gt;a[j]){\r\n\t\t\t\ttemp=a[i];\r\n\t\t\t\ta[i]=a[j];\r\n\t\t\t\ta[j]=temp;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\nprintf(&quot;Selection Sort in C&#92;n&quot;);\r\nfor(i=0; i&lt;num; i++){\r\n\t\tprintf(&quot;a[%d]=&#92;t%d&#92;n&quot;,i,a[i]);\r\n\t}\r\n\t\r\n\treturn 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_10865 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_10865 a\"),jQuery(\"#tab-content_10865\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<pre><code>Input:\n5\n20\n10\n8\n5\n1\n\nOutput:\n1\n5\n8\n10\n20<\/code><\/pre>\n<p><strong>Complexity of Selection Sort<\/strong><br \/>\nSelection sort algorithm in c ( or in general any language ) has a space complexity of O(1) as there is no extra space used being a comparison-based and in-place sorting algorithm.<\/p>\n<p>Talking about time complexity, it is going to be O(n*n) as there are two loops and each iteration in the outer loop is going to make n comparisons. Assuming there are five elements in the array then 25 comparisons are made to sort the array using Selection Sort algorithm in C.<\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>In this article, we started with the practical working of selection sort and later got to know the mechanism of the selection sort algorithm in c along with its dry run. We studied how to solve the selection sort program in c and analyzed the space and time complexity of this sorting algorithm. We hope that you have understood everything in detail from this article on Selection Sort Program in C. <\/p>\n<h2>FAQs Related to Selection Sort Algorithm in C<\/h2>\n<p><strong>1. What is in-place sorting?<\/strong><br \/>\nIn-place means that all the operations which be made without using any additional data structure for their execution. Selection Sort in C or any specific language uses in-place sorting.<\/p>\n<p><strong>2. What is the time complexity of the Selection Sort Program in C?<\/strong><br \/>\nSelection Sort Program in C takes O(n^2) as two loops are going to run N-1 time where one decides the value at index and inner loops check for all the succeeding indexes element.<\/p>\n<p>Even the best-case time complexity of the selection sort algorithm in C ( or other languages in general ) is going to be O(n^2).<\/p>\n<p><strong>Other C Programs<\/strong><\/p>\n<p><a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/binary-search-program-in-c\/\" title=\"C Program for Binary Search\">C Program for Binary Search<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-add-two-numbers\/\" title=\"C Program to Add Two Numbers\">C Program to Add Two Numbers<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-calculate-percentage-of-5-subjects\/\" title=\"C Program to Calculate Percentage of 5 Subjects\">C Program to Calculate Percentage of 5 Subjects<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-convert-binary-number-to-decimal-number\/\" title=\"C Program to Convert Binary Number to Decimal Number\">C Program to Convert Binary Number to Decimal Number<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-convert-celsius-to-fahrenheit\/\" title=\"C Program to Convert Celsius to Fahrenheit\">C Program to Convert Celsius to Fahrenheit<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-convert-infix-to-postfix\/\" title=\"C Program to Convert Infix to Postfix\">C Program to Convert Infix to Postfix<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-find-area-of-circle\/\" title=\"C Program to Find Area of Circle\">C Program to Find Area of Circle<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-find-roots-of-quadratic-equation\/\" title=\"C Program to Find Roots of Quadratic Equation\">C Program to Find Roots of Quadratic Equation<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-reverse-a-linked-list\/\" title=\"C program to Reverse a Linked List\">C program to Reverse a Linked List<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-reverse-a-number\/\" title=\"C program to reverse a number\">C program to reverse a number<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/c-program-to-sort-an-array-in-ascending-order\/\" title=\"Ascending Order Program in C\">Ascending Order Program in C<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/menu-driven-program-for-all-operations-on-doubly-linked-list-in-c\/\" title=\"Menu Driven Program For All Operations On Doubly Linked List in C\">Menu Driven Program For All Operations On Doubly Linked List in C<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/what-is-the-program-of-armstrong-number-in-c\/\" title=\"C Program for Armstrong Number\">C Program for Armstrong Number<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/c-program-for-merge-sort-for-linked-lists\/\" title=\"C Program For Merge Sort For Linked Lists\">C Program For Merge Sort For Linked Lists<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/c-program-for-performing-bubble-sort-on-linked-list\/\" title=\"C program for performing Bubble sort on Linked List\">C program for performing Bubble sort on Linked List<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/hello-world-program-in-c\/\" title=\"Hello World Program in C\">Hello World Program in C<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/perfect-number-program-in-c\/\" title=\"Perfect Number Program in C\">Perfect Number Program in C<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/leap-year-program-in-c\/\" title=\"Leap Year Program in C\">Leap Year Program in C<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/odd-even-program-in-c\/\" title=\"Odd Even Program in C\">Odd Even Program in C<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/c-programming\/selection-sort-program-in-c\/\" title=\"Selection Sort Program in C\">Selection Sort Program in C<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sorting, the process of arranging elements in a specific order, lies at the heart of computer science and is a fundamental building block for a wide range of applications. From organizing data for efficient searching to enabling smoother user experiences in applications, sorting algorithms play a crucial role. One such elementary yet instructive sorting algorithm [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-10971","post","type-post","status-publish","format-standard","hentry","category-c-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Selection Sort: Algorithm, Program and Dry Run<\/title>\n<meta name=\"description\" content=\"Learn how to implement Selection Sort in C Language. We will be looking at the intuition and approach before coding up the selection sort program in C.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Selection Sort: Algorithm, Program and Dry Run\" \/>\n<meta property=\"og:description\" content=\"Learn how to implement Selection Sort in C Language. We will be looking at the intuition and approach before coding up the selection sort program in C.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-08T11:13:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-21T07:04:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497117917-Selection%20Sort%20in%20C.jpg\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"How to Implement Selection Sort in C?\",\"datePublished\":\"2022-12-08T11:13:30+00:00\",\"dateModified\":\"2023-08-21T07:04:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/\"},\"wordCount\":1106,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497117917-Selection%20Sort%20in%20C.jpg\",\"articleSection\":[\"C Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/\",\"name\":\"Selection Sort: Algorithm, Program and Dry Run\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497117917-Selection%20Sort%20in%20C.jpg\",\"datePublished\":\"2022-12-08T11:13:30+00:00\",\"dateModified\":\"2023-08-21T07:04:15+00:00\",\"description\":\"Learn how to implement Selection Sort in C Language. We will be looking at the intuition and approach before coding up the selection sort program in C.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497117917-Selection%20Sort%20in%20C.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497117917-Selection%20Sort%20in%20C.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C Programming\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/c-programming\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Implement Selection Sort in C?\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Selection Sort: Algorithm, Program and Dry Run","description":"Learn how to implement Selection Sort in C Language. We will be looking at the intuition and approach before coding up the selection sort program in C.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/","og_locale":"en_US","og_type":"article","og_title":"Selection Sort: Algorithm, Program and Dry Run","og_description":"Learn how to implement Selection Sort in C Language. We will be looking at the intuition and approach before coding up the selection sort program in C.","og_url":"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2022-12-08T11:13:30+00:00","article_modified_time":"2023-08-21T07:04:15+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497117917-Selection%20Sort%20in%20C.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"How to Implement Selection Sort in C?","datePublished":"2022-12-08T11:13:30+00:00","dateModified":"2023-08-21T07:04:15+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/"},"wordCount":1106,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497117917-Selection%20Sort%20in%20C.jpg","articleSection":["C Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/","url":"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/","name":"Selection Sort: Algorithm, Program and Dry Run","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497117917-Selection%20Sort%20in%20C.jpg","datePublished":"2022-12-08T11:13:30+00:00","dateModified":"2023-08-21T07:04:15+00:00","description":"Learn how to implement Selection Sort in C Language. We will be looking at the intuition and approach before coding up the selection sort program in C.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497117917-Selection%20Sort%20in%20C.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1670497117917-Selection%20Sort%20in%20C.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/selection-sort-implementation-program-in-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"C Programming","item":"https:\/\/prepbytes.com\/blog\/category\/c-programming\/"},{"@type":"ListItem","position":3,"name":"How to Implement Selection Sort in C?"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/10971","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=10971"}],"version-history":[{"count":2,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/10971\/revisions"}],"predecessor-version":[{"id":17682,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/10971\/revisions\/17682"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=10971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=10971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=10971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}