{"id":18228,"date":"2020-08-22T16:08:31","date_gmt":"2020-08-22T10:38:31","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/"},"modified":"2024-09-03T11:24:40","modified_gmt":"2024-09-03T05:54:40","slug":"counting-sort","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/","title":{"rendered":"Counting Sort in C , C++, Java and Python"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-counting-sort\"><strong>What is Counting Sort<\/strong><strong>\t<\/strong><\/h2>\n\n\n\n<p>Counting sort is a sorting technique which is based on the range of input value. It is used to sort elements in linear time. In Counting sort, we maintain an auxiliary array which drastically increases space requirement for the algorithm implementation<\/p>\n\n\n\n<p>It works just like hashing, first, we calculate the max value in the input array, the array to be sorted. Then we count the number of occurrences of each array element from 0 to length-1 and assign it into the auxiliary array. This array is used again to retrieve the sorted version of the input array<\/p>\n\n\n\n<p>It actually has linear time complexity but we can\u2019t say that it\u2019s the best algorithm because the space complexity is quite high and it is only suitable to use in a scenario where input array element range is close to the size of the array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"counting-sort-pseudo-code\"><strong>Counting Sort Pseudo-code<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Iterate the input array and find the maximum value present in it.<\/li>\n\n\n\n<li>Declare a new array of size max+1 with value 0<\/li>\n\n\n\n<li>Count each and every element in the array and increment its value at the corresponding index in the auxiliary array created<\/li>\n\n\n\n<li>Find cumulative sum is the auxiliary array we adding curr and prev frequency<\/li>\n\n\n\n<li>Now the cumulative value actually signifies the actual location of the element in the sorted input array<\/li>\n\n\n\n<li>Start iterating auxiliary array from 0 to max<\/li>\n\n\n\n<li>Put 0 at the corresponding index and reduce the count by 1, which will signify the second position of the element if it exists in the input array<\/li>\n\n\n\n<li>Now transfer array received in the above step in the actual input array<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"counting-sort-algorithm\"><strong>Counting Sort Algorithm<\/strong><br><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>countingSort(arr, n)\n  maximum &lt;- find the largest element in arr\n  create a count array of size maximum+1\n  initialise count array with all 0's\n  for i &lt;- 0 to n\n    find the total frequency\/ occurrences of each element and \n    store the count at ith index in count arr\n  \n  for i &lt;- 1 to maximum\n    find the cumulative sum by adding current(i) and prev(i-1) count and store \n\tit in count arr itself\n  \n  for j &lt;- n down to 1\n    copy the element back into the input array\n    decrement count of each element copied by 1\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"counting-sort-algorithm-dry-run\"><strong>Counting Sort Algorithm Dry Run<\/strong><\/h2>\n\n\n\n<p>input:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>2<\/td><td>1<\/td><td>1<\/td><td>4<\/td><td>2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>First step - marking count array<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><td>0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>After calculating all the frequency of every element<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>0<\/td><td>2<\/td><td>2<\/td><td>0<\/td><td>1<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>do cumulative sum<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>0<\/td><td>2<\/td><td>4<\/td><td>4<\/td><td>5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Now start iterating input array and check frequency array to map it to the output array&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Iteration 1<\/pre>\n\n\n\n<p>input:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>2<\/td><td>1<\/td><td>1<\/td><td>4<\/td><td>2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>cumulative sum<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>0<\/td><td>2<\/td><td>3<\/td><td>4<\/td><td>5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>0<\/td><td>0<\/td><td>0<\/td><td>2<\/td><td>0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\">Iteration 2<\/pre>\n\n\n\n<p>input:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>2<\/td><td>1<\/td><td>1<\/td><td>4<\/td><td>2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>cumulative sum<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>0<\/td><td>1<\/td><td>3<\/td><td>4<\/td><td>5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>0<\/td><td>1<\/td><td>0<\/td><td>2<\/td><td>0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\">Iteration 3<\/pre>\n\n\n\n<p>input:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>2<\/td><td>1<\/td><td>1<\/td><td>4<\/td><td>2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>cumulative sum<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>0<\/td><td>0<\/td><td>3<\/td><td>4<\/td><td>5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>1<\/td><td>1<\/td><td>0<\/td><td>2<\/td><td>0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\">Iteration 4<\/pre>\n\n\n\n<p>input:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>2<\/td><td>1<\/td><td>1<\/td><td>4<\/td><td>2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>cumulative sum<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>0<\/td><td>0<\/td><td>3<\/td><td>3<\/td><td>4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>1<\/td><td>1<\/td><td>0<\/td><td>2<\/td><td>4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\">Iteration 5<\/pre>\n\n\n\n<p>input:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>2<\/td><td>1<\/td><td>1<\/td><td>4<\/td><td>2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>cumulative sum<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>0<\/td><td>0<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><\/tr><tr><td>1<\/td><td>1<\/td><td>2<\/td><td>2<\/td><td>4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Now transfer the output to the input array<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"counting-sort-time-complexity\"><strong>Counting Sort Time Complexity<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Time is taken to find max say k<\/li>\n\n\n\n<li>Count array initialization will take k time<\/li>\n\n\n\n<li>To maintain count array again k time<\/li>\n\n\n\n<li>Now linear iteration of the input array to do the actual sorting<\/li>\n\n\n\n<li>Since all the above steps are fixed for no matter what the input array is, therefore best, average and worst time complexity will remain the same<\/li>\n\n\n\n<li>Best Time Complexity : O(n+k)<\/li>\n\n\n\n<li>Average Time Complexity : O(n+k)<\/li>\n\n\n\n<li>Worst Time Complexity : O(n+k)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"counting-sort-space-complexity\"><strong>Counting Sort Space Complexity<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Auxiliary space is required in Counting sort implementation as we have to create a count array of size max+1<\/li>\n\n\n\n<li>Hence space complexity is: O(max)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"counting-sort-in-c\"><strong>Counting sort in C&nbsp;<\/strong><br><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;\n\nvoid countingSort(int arr&#091;], int n) {\n  int arr1&#091;10];\n\n  int x = arr&#091;0];\n  for (int i = 1; i &lt; n; i++) {\n    if (arr&#091;i] &gt; x)\n      x = arr&#091;i];\n  }\n\n  \n  int count_arr&#091;10];\n\n  for (int i = 0; i &lt;= x; ++i) {\n    count_arr&#091;i] = 0;\n  }\n\n  for (int i = 0; i &lt; n; i++) {\n    count_arr&#091;arr&#091;i]]++;\n  }\n\n  for (int i = 1; i &lt;= x; i++) {\n    count_arr&#091;i] += count_arr&#091;i - 1];\n  }\n\n \n  for (int i = n - 1; i &gt;= 0; i--) {\n    arr1&#091;count_arr&#091;arr&#091;i]] - 1] = arr&#091;i];\n    count_arr&#091;arr&#091;i]]--;\n  }\n\n  for (int i = 0; i &lt; n; i++) {\n    arr&#091;i] = arr1&#091;i];\n  }\n}\n\nvoid display(int arr&#091;], int n) {\n  for (int i = 0; i &lt; n; ++i) {\n    printf(\"%d  \", arr&#091;i]);\n  }\n  printf(\"n\");\n}\n\nint main() {\n  int arr&#091;] = {4, 2, 2, 8, 3, 3, 1};\n  int n = sizeof(arr) \/ sizeof(arr&#091;0]);\n  countingSort(arr, n);\n  display(arr, n);\n}\n\n\n\n\n\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">Output of the program:\n 1  2  2  3  3  4  8  <\/pre>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy PRO<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-from-scratch\" class=\"courses-cta-title-link\">C Programming Course: Master C with Hands-on Projects<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Join our C Programming Course and learn C syntax, operators, expressions, control flow, functions, pointers, structures, file handling, memory management, and modular programming. Build real-world skills through practical projects!<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>2 Projects<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>10 Hrs<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-from-scratch\" class=\"courses-cta-button\">\n                C Programming Course with Certificate\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/heap-sort\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\"><em><strong>Learn about heap sort<\/strong><\/em><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"counting-sort-in-java\"><strong>Counting sort in Java<\/strong><br><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Arrays;\n\nclass CountingSort {\n  void countSort(int arr&#091;], int n) {\n    int&#091;] arr1 = new int&#091;n + 1];\n\n    int x = arr&#091;0];\n    for (int i = 1; i &lt; n; i++) {\n      if (arr&#091;i] &gt; x)\n        x = arr&#091;i];\n    }\n    int&#091;] count_arr = new int&#091;x + 1];\n\n    for (int i = 0; i &lt; x; ++i) {\n      count_arr&#091;i] = 0;\n    }\n\n    for (int i = 0; i &lt; n; i++) {\n      count_arr&#091;arr&#091;i]]++;\n    }\n\n    for (int i = 1; i &lt;= x; i++) {\n      count_arr&#091;i] += count_arr&#091;i - 1];\n    }\n\n    for (int i = n - 1; i &gt;= 0; i--) {\n      arr1&#091;count_arr&#091;arr&#091;i]] - 1] = arr&#091;i];\n      count_arr&#091;arr&#091;i]]--;\n    }\n\n    for (int i = 0; i &lt; n; i++) {\n      arr&#091;i] = arr1&#091;i];\n    }\n  }\n\n  void display(int&#091;] arr){\n\tfor (int i = 0; i &lt; arr.length; i++) {\n\t\tSystem.out.print(arr&#091;i]+\" \");\n\t}\n  }\n  \n  public static void main(String args&#091;]) {\n    int&#091;] arr = { 4, 2, 2, 8, 3, 3, 1 };\n    int n = arr.length;\n    CountingSort cs = new CountingSort();\n    cs.countSort(arr, n);\n    cs.display(arr);\n  }\n}\n\n\n\n\n\n\n\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">Output of the program:\n 1 2 2 3 3 4 8 <\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"counting-sort-in-c\"><strong>Counting sort in C++ <\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\n#include &lt;iostream&gt;\nusing namespace std;\n\nvoid countSort(int arr&#091;], int n) {\n  \n  int arr1&#091;10];\n  int count_arr&#091;10];\n  int x = arr&#091;0];\n\n  for (int i = 1; i &lt; n; i++) {\n    if (arr&#091;i] &gt; x)\n      x = arr&#091;i];\n  }\n\n  for (int i = 0; i &lt;= x; ++i) {\n    count_arr&#091;i] = 0;\n  }\n\n  for (int i = 0; i &lt; n; i++) {\n    count_arr&#091;arr&#091;i]]++;\n  }\n\n  for (int i = 1; i &lt;= x; i++) {\n    count_arr&#091;i] += count_arr&#091;i - 1];\n  }\n\n\n  for (int i = n - 1; i &gt;= 0; i--) {\n    arr1&#091;count_arr&#091;arr&#091;i]] - 1] = arr&#091;i];\n    count_arr&#091;arr&#091;i]]--;\n  }\n\n  for (int i = 0; i &lt; n; i++) {\n    arr&#091;i] = arr1&#091;i];\n  }\n}\n\nvoid display(int arr&#091;], int n) {\n  for (int i = 0; i &lt; n; i++)\n    cout &lt;&lt; arr&#091;i] &lt;&lt; \" \";\n  cout &lt;&lt; endl;\n}\n\nint main() {\n  int arr&#091;] = {4, 2, 2, 8, 3, 3, 1};\n  int n = sizeof(arr) \/ sizeof(arr&#091;0]);\n  countSort(arr, n);\n  display(arr, n);\n}\n\n\n\n\n\n\n\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">Output of the program:\n 1 2 2 3 3 4 8 <\/pre>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-title-link\">C++ Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master key C++ programming concepts like variables, functions, OOP, and control structures. Build real-world projects such as a banking system and grade management tool.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>Beginner to Advanced Level<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>8.1 hrs<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"counting-sort-in-python\"><strong>Counting sort in Python<\/strong><br><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>def countingSort(arr):\n    n = len(arr)\n    arr1 = &#091;0] * n\n\n    x = &#091;0] * 10\n\n    for i in range(0, n):\n        x&#091;arr&#091;i]] += 1\n\n    for i in range(1, 10):\n        x&#091;i] += x&#091;i - 1]\n\n\n    i = n - 1\n    while i &gt;= 0:\n        arr1&#091;x&#091;arr&#091;i]] - 1] = arr&#091;i]\n        x&#091;arr&#091;i]] -= 1\n        i -= 1\n\n    for i in range(0, n):\n        arr&#091;i] = arr1&#091;i]\n\n\narr = &#091;4, 2, 2, 8, 3, 3, 1]\ncountingSort(arr)\nprint(arr)\n\n\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">Output of the program:\n [1, 2, 2, 3, 3, 4, 8]<\/pre>\n\n\n\n<p> This brings us to the end of this article where we learned about heap sort. To get a free course on data structures and algorithms, click on the banner below. Also, visit the<strong><em>&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.mygreatlearning.com\/academy\" target=\"_blank\">great learning academy<\/a><\/em><\/strong>&nbsp;to see all the free courses we are providing. <\/p>\n\n\n<figure class=\"wp-block-image size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/June-29-banner-for-GL-data-structures-1.png\"><a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/data-structures-and-algorithms-in-java\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1000\" height=\"242\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/June-29-banner-for-GL-data-structures-1.png\" alt=\"counting sort\" class=\"wp-image-16657\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/June-29-banner-for-GL-data-structures-1.png 1000w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/June-29-banner-for-GL-data-structures-1-300x73.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/June-29-banner-for-GL-data-structures-1-768x186.png 768w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/June-29-banner-for-GL-data-structures-1-696x168.png 696w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>What is Counting Sort Counting sort is a sorting technique which is based on the range of input value. It is used to sort elements in linear time. In Counting sort, we maintain an auxiliary array which drastically increases space requirement for the algorithm implementation It works just like hashing, first, we calculate the max [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":18235,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","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":"","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":"set","ast-page-background-enabled":"default","ast-page-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":"","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-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":"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":""},"mobile":{"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":""}},"footnotes":""},"categories":[25860],"tags":[36858],"content_type":[36252],"class_list":["post-18228","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-sorting-algorithm","content_type-tutorials"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Counting Sort in C , C++, Java and Python<\/title>\n<meta name=\"description\" content=\"Counting sort is a sorting technique which is based on the range of input value. It is used to sort elements in linear time.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Counting Sort in C , C++, Java and Python\" \/>\n<meta property=\"og:description\" content=\"Counting sort is a sorting technique which is based on the range of input value. It is used to sort elements in linear time.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-22T10:38:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-03T05:54:40+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"700\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/counting-sort\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/counting-sort\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Counting Sort in C , C++, Java and Python\",\"datePublished\":\"2020-08-22T10:38:31+00:00\",\"dateModified\":\"2024-09-03T05:54:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/counting-sort\\\/\"},\"wordCount\":534,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/counting-sort\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Blog-Algorithm-23-7-2020-04.jpg\",\"keywords\":[\"sorting algorithm\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/counting-sort\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/counting-sort\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/counting-sort\\\/\",\"name\":\"Counting Sort in C , C++, Java and Python\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/counting-sort\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/counting-sort\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Blog-Algorithm-23-7-2020-04.jpg\",\"datePublished\":\"2020-08-22T10:38:31+00:00\",\"dateModified\":\"2024-09-03T05:54:40+00:00\",\"description\":\"Counting sort is a sorting technique which is based on the range of input value. It is used to sort elements in linear time.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/counting-sort\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/counting-sort\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/counting-sort\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Blog-Algorithm-23-7-2020-04.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Blog-Algorithm-23-7-2020-04.jpg\",\"width\":1000,\"height\":700,\"caption\":\"CountingSort_GL\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/counting-sort\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Counting Sort in C , C++, Java and Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Counting Sort in C , C++, Java and Python","description":"Counting sort is a sorting technique which is based on the range of input value. It is used to sort elements in linear time.","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:\/\/www.mygreatlearning.com\/blog\/counting-sort\/","og_locale":"en_US","og_type":"article","og_title":"Counting Sort in C , C++, Java and Python","og_description":"Counting sort is a sorting technique which is based on the range of input value. It is used to sort elements in linear time.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2020-08-22T10:38:31+00:00","article_modified_time":"2024-09-03T05:54:40+00:00","og_image":[{"width":1000,"height":700,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Counting Sort in C , C++, Java and Python","datePublished":"2020-08-22T10:38:31+00:00","dateModified":"2024-09-03T05:54:40+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/"},"wordCount":534,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04.jpg","keywords":["sorting algorithm"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/","url":"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/","name":"Counting Sort in C , C++, Java and Python","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04.jpg","datePublished":"2020-08-22T10:38:31+00:00","dateModified":"2024-09-03T05:54:40+00:00","description":"Counting sort is a sorting technique which is based on the range of input value. It is used to sort elements in linear time.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04.jpg","width":1000,"height":700,"caption":"CountingSort_GL"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/counting-sort\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Counting Sort in C , C++, Java and Python"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04.jpg",1000,700,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04-300x210.jpg",300,210,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04-768x538.jpg",768,538,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04.jpg",1000,700,false],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04.jpg",1000,700,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04.jpg",1000,700,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04.jpg",640,448,false],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04.jpg",96,67,false],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Algorithm-23-7-2020-04.jpg",150,105,false]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"What is Counting Sort Counting sort is a sorting technique which is based on the range of input value. It is used to sort elements in linear time. In Counting sort, we maintain an auxiliary array which drastically increases space requirement for the algorithm implementation It works just like hashing, first, we calculate the max&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/18228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=18228"}],"version-history":[{"count":16,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/18228\/revisions"}],"predecessor-version":[{"id":111492,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/18228\/revisions\/111492"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/18235"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=18228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=18228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=18228"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=18228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}