{"id":34150,"date":"2024-11-01T09:24:49","date_gmt":"2024-11-01T09:24:49","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34150"},"modified":"2024-11-01T10:58:25","modified_gmt":"2024-11-01T10:58:25","slug":"c-coding-test-course-radix-sort-2","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34150\/","title":{"rendered":"C++ Coding Test Course, Radix Sort"},"content":{"rendered":"<article>\n<header>\n<p>In this article, we will discuss the concept and implementation of Radix Sort, as well as detail the process through practical problems.<\/p>\n<\/header>\n<section>\n<h2>1. Overview of Radix Sort<\/h2>\n<p>Radix Sort is a special type of sorting algorithm that is effective when the data to be sorted consists of integers or strings within a specific range. Unlike typical sorting algorithms, Radix Sort sorts based on &#8220;digits.&#8221; Through this, Radix Sort has a time complexity of O(d(n + k)), where d is the number of digits, n is the number of data to be sorted, and k is the range of values.<\/p>\n<\/section>\n<section>\n<h2>2. Principle of Radix Sort<\/h2>\n<p>Radix Sort is performed through the following process:<\/p>\n<ol>\n<li>Starting from the least significant digit, numbers are sorted based on each digit.<\/li>\n<li>Sorting is repeated for each digit.<\/li>\n<li>Once sorting is completed for all digits, a fully sorted array is obtained.<\/li>\n<\/ol>\n<p>Radix Sort is typically implemented as a stable sorting algorithm, meaning that the order of elements with the same value retains their relative positions.<\/p>\n<\/section>\n<section>\n<h2>3. Implementation of Radix Sort<\/h2>\n<p>Let&#8217;s implement Radix Sort in C++. Here is the basic implementation of Radix Sort:<\/p>\n<pre><code class=\"cpp\">\n#include &lt;iostream&gt;\n#include &lt;vector&gt;\n\nusing namespace std;\n\n\/\/ Function for sorting based on a specific digit\nvoid countingSort(vector&lt;int&gt; &amp;arr, int exp) {\n    int n = arr.size();\n    vector&lt;int&gt; output(n);\n    int count[10] = {0}; \/\/ Range of numbers is 0~9\n\n    \/\/ Count occurrences of each digit\n    for (int i = 0; i &lt; n; i++) {\n        count[(arr[i] \/ exp) % 10]++;\n    }\n\n    \/\/ Calculate cumulative sum\n    for (int i = 1; i &lt; 10; i++) {\n        count[i] += count[i - 1];\n    }\n\n    \/\/ Build the output array\n    for (int i = n - 1; i &gt;= 0; i--) {\n        output[count[(arr[i] \/ exp) % 10] - 1] = arr[i];\n        count[(arr[i] \/ exp) % 10]--;\n    }\n\n    \/\/ Store the result in the original array\n    for (int i = 0; i &lt; n; i++) {\n        arr[i] = output[i];\n    }\n}\n\n\/\/ Radix Sort function\nvoid radixSort(vector&lt;int&gt; &amp;arr) {\n    \/\/ Find the maximum value\n    int maxVal = *max_element(arr.begin(), arr.end());\n\n    \/\/ Sort by each digit\n    for (int exp = 1; maxVal \/ exp &gt; 0; exp *= 10) {\n        countingSort(arr, exp);\n    }\n}\n\n\/\/ Main function\nint main() {\n    vector&lt;int&gt; arr = {170, 45, 75, 90, 802, 24, 2, 66};\n    radixSort(arr);\n    \n    cout &lt;&lt; \"Sorted array: \";\n    for (int i : arr) {\n        cout &lt;&lt; i &lt;&lt; \" \";\n    }\n    \n    return 0;\n}\n        <\/code><\/pre>\n<p>This code demonstrates the basic flow of Radix Sort. The <strong>countingSort<\/strong> function counts the occurrences for each digit and sorts the elements based on that. The <strong>radixSort<\/strong> function calls <strong>countingSort<\/strong> for each digit and returns the final sorted array.<\/p>\n<\/section>\n<section>\n<h2>4. Example Problem Solved with Radix Sort<\/h2>\n<p>Now, let\u2019s present an algorithm problem that can be solved using Radix Sort.<\/p>\n<h3>Problem: Sort the given list of integers using Radix Sort.<\/h3>\n<p>Input: [170, 45, 75, 90, 802, 24, 2, 66]<\/p>\n<p>Output: [2, 24, 45, 66, 75, 90, 170, 802]<\/p>\n<h4>Problem-solving process<\/h4>\n<ol>\n<li>Find the maximum value, which is confirmed to be 802. This value determines the highest digit.<\/li>\n<li>Start with the least significant digit and call countingSort for each digit in the order of 1&#8217;s place, 10&#8217;s place, and 100&#8217;s place.<\/li>\n<li>After sorting each digit, the final array will be sorted.<\/li>\n<\/ol>\n<p>Try solving the problem using Radix Sort!<\/p>\n<\/section>\n<footer>\n<h2>5. Conclusion<\/h2>\n<p>Radix Sort is a highly efficient algorithm for specific cases. It is particularly pronounced in performance when dealing with integers or strings. I hope this tutorial has helped you understand the principles and implementation of Radix Sort. In the next tutorial, we will cover another sorting algorithm, Merge Sort.<\/p>\n<\/footer>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will discuss the concept and implementation of Radix Sort, as well as detail the process through practical problems. 1. Overview of Radix Sort Radix Sort is a special type of sorting algorithm that is effective when the data to be sorted consists of integers or strings within a specific range. Unlike &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34150\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;C++ Coding Test Course, Radix Sort&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[111],"tags":[],"class_list":["post-34150","post","type-post","status-publish","format-standard","hentry","category-c-coding-test-tutorials-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++ Coding Test Course, Radix Sort - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/34150\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ Coding Test Course, Radix Sort - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In this article, we will discuss the concept and implementation of Radix Sort, as well as detail the process through practical problems. 1. Overview of Radix Sort Radix Sort is a special type of sorting algorithm that is effective when the data to be sorted consists of integers or strings within a specific range. Unlike &hellip; \ub354 \ubcf4\uae30 &quot;C++ Coding Test Course, Radix Sort&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34150\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:24:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T10:58:25+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/34150\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34150\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"C++ Coding Test Course, Radix Sort\",\"datePublished\":\"2024-11-01T09:24:49+00:00\",\"dateModified\":\"2024-11-01T10:58:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34150\/\"},\"wordCount\":370,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"C++ Coding Test Tutorials\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34150\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34150\/\",\"name\":\"C++ Coding Test Course, Radix Sort - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:24:49+00:00\",\"dateModified\":\"2024-11-01T10:58:25+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34150\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34150\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34150\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ Coding Test Course, Radix Sort\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++ Coding Test Course, Radix Sort - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","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:\/\/atmokpo.com\/w\/34150\/","og_locale":"ko_KR","og_type":"article","og_title":"C++ Coding Test Course, Radix Sort - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In this article, we will discuss the concept and implementation of Radix Sort, as well as detail the process through practical problems. 1. Overview of Radix Sort Radix Sort is a special type of sorting algorithm that is effective when the data to be sorted consists of integers or strings within a specific range. Unlike &hellip; \ub354 \ubcf4\uae30 \"C++ Coding Test Course, Radix Sort\"","og_url":"https:\/\/atmokpo.com\/w\/34150\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:24:49+00:00","article_modified_time":"2024-11-01T10:58:25+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/34150\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34150\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"C++ Coding Test Course, Radix Sort","datePublished":"2024-11-01T09:24:49+00:00","dateModified":"2024-11-01T10:58:25+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34150\/"},"wordCount":370,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["C++ Coding Test Tutorials"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34150\/","url":"https:\/\/atmokpo.com\/w\/34150\/","name":"C++ Coding Test Course, Radix Sort - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:24:49+00:00","dateModified":"2024-11-01T10:58:25+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34150\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34150\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34150\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"C++ Coding Test Course, Radix Sort"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=34150"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34150\/revisions"}],"predecessor-version":[{"id":34151,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34150\/revisions\/34151"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}