{"id":80,"date":"2020-05-11T23:34:25","date_gmt":"2020-05-11T23:34:25","guid":{"rendered":"http:\/\/sites.tntech.edu\/acrockett\/?p=80"},"modified":"2020-05-11T23:34:26","modified_gmt":"2020-05-11T23:34:26","slug":"selection-sort","status":"publish","type":"post","link":"https:\/\/sites.tntech.edu\/acrockett\/2020\/05\/11\/selection-sort\/","title":{"rendered":"Selection Sort"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Problem Description<\/h2>\n\n\n\n<p>Place elements organized in an array or list in either ascending or descending order.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Algorithm Description<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"214\" src=\"https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/selectionSort-1024x214.png\" alt=\"\" class=\"wp-image-81\" srcset=\"https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/selectionSort-1024x214.png 1024w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/selectionSort-300x63.png 300w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/selectionSort-768x161.png 768w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/selectionSort-1536x322.png 1536w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/selectionSort.png 1776w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Selection sort is a sort algorithm that repeatedly searches remaining items to select the lest one and move it to its final location<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Videos<\/h2>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Selection Sort\" width=\"1140\" height=\"641\" src=\"https:\/\/www.youtube.com\/embed\/3hH8kTHFw2A?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Select-sort with Gypsy folk dance\" width=\"1140\" height=\"641\" src=\"https:\/\/www.youtube.com\/embed\/Ns4TPTC8whw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Selection Sort\" width=\"1140\" height=\"641\" src=\"https:\/\/www.youtube.com\/embed\/92BfuxHn2XE?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Going through Selection Sort <br>with Actual Input<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"689\" height=\"1024\" src=\"https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/selectionSort2-689x1024.png\" alt=\"\" class=\"wp-image-82\" srcset=\"https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/selectionSort2-689x1024.png 689w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/selectionSort2-202x300.png 202w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/selectionSort2-768x1142.png 768w, https:\/\/sites.tntech.edu\/acrockett\/wp-content\/uploads\/sites\/108\/2020\/05\/selectionSort2.png 1006w\" sizes=\"auto, (max-width: 689px) 100vw, 689px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">C++ Code<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*\n     Author:  April Crockett\n     Date:  5\/11\/2020\n*\/\n#include &lt;iostream&gt;\nusing namespace std;\nvoid displayArray(int*, int);\nvoid selectionSort(int*, int);\n\nint main()\n{\n\tint myArr&#091;5] = {85, 42, 7, 186, 18};\n\t\/\/display the array\n\tdisplayArray(myArr, 5);\n\t\/\/sort the array\n\tselectionSort(myArr, 5);\n\t\/\/display the array\n\tdisplayArray(myArr, 5);\n\treturn 0;\n}\n\nvoid selectionSort(int *arr, int size)\n{\n\tint minIndex, minValue;\n\tint temp;  \/\/temporary variable for swap\n\tcout &lt;&lt; \"\\nSorting the array with the Selection Sort algorithm.\\n\\n\";\n\t\n\tfor(int start = 0; start &lt; (size-1); start++)\n\t{\n\t\tminIndex = start;\n\t\tminValue = arr&#091;start];\n\t\t\n\t\t\/\/find the minimum value in the array starting from \n                \/\/start and going through the end of the array\n\t\tfor(int i=start+1; i&lt;size; i++) \/\/using i for \"index\"\n\t\t{\n\t\t\tif(arr&#091;i] &lt; minValue) \n\t\t\t{\n\t\t\t\tminValue = arr&#091;i];\n\t\t\t\tminIndex = i;\n\t\t\t}\n\t\t}\n\n\t\t\/\/now we have the index of the smallest value so swap\n\t\ttemp = arr&#091;minIndex];\n\t\tarr&#091;minIndex] = arr&#091;start];\n\t\tarr&#091;start] = temp;\n\t}\n}\nvoid displayArray(int *arr, int size)\n{\n\tcout &lt;&lt; \"\\n--------------------The array:  \";\n\tfor(int i=0; i&lt;size; i++)\n\t{\n\t\tcout &lt;&lt; arr&#091;i] &lt;&lt; \" \";\n\t}\n\tcout &lt;&lt; \"--------------------\\n\";\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Other Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>VisuAlgo &#8211; Selection Sort Visualization: <a href=\"https:\/\/visualgo.net\/bn\/sorting?slide=7\">https:\/\/visualgo.net\/bn\/sorting?slide=7<\/a><\/li><li>GeeksforGeeks: <a href=\"https:\/\/www.geeksforgeeks.org\/selection-sort\/\">https:\/\/www.geeksforgeeks.org\/selection-sort\/<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Problem Description Place elements organized in an array or list in either ascending or descending order. Algorithm Description Selection sort is a sort algorithm that repeatedly searches remaining items to select the lest one and move it to its final location Videos Going through Selection Sort with Actual Input C++ Code Other Resources VisuAlgo &#8211; [&hellip;]<\/p>\n","protected":false},"author":119,"featured_media":82,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[9,8,10],"class_list":{"0":"post-80","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-algorithms","8":"tag-algorithm","9":"tag-selection-sort","10":"tag-sort-algorithm","11":"czr-hentry"},"_links":{"self":[{"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/posts\/80","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/comments?post=80"}],"version-history":[{"count":1,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/posts\/80\/revisions"}],"predecessor-version":[{"id":83,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/posts\/80\/revisions\/83"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/media\/82"}],"wp:attachment":[{"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/media?parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/categories?post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.tntech.edu\/acrockett\/wp-json\/wp\/v2\/tags?post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}