{"id":"7edc7c52-7480-490a-b7a2-8ffef0c3c479","name":"Radix Sort","description":"1. You are given an array(arr) of integers.\r\n2. You have to sort the given array in increasing order using radix sort.","inputFormat":"An Integer n \r\narr1\r\narr2..\r\nn integers","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= N &lt;= 10000\r\n0 &lt;= arr[i] &lt;= 10^8","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<vector>\n#include<climits>\n#include<algorithm>\n\nusing namespace std;\n\nvoid Display(vector<int>& arr){\n for(int ele : arr){\n cout<< ele << \" \";\n }\n}\n\nvoid countsort(vector<int> &arr, int d){\n // write your code here\n\n cout<< \"After sorting on \" << d << \" place -> \";\n Display(arr);\n cout << endl;\n}\n\nvoid radixSort(vector<int> &arr){\n // write your code here\n\n}\n\n\nint main(){\n int n;\n cin >> n;\n vector<int> arr(n, 0);\n \n for(int i = 0; i < n; i++){ \n cin >> arr[i];\n }\n \n radixSort(arr);\n Display(arr);\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void radixSort(int[] arr) {\r\n // write code here \r\n }\r\n\r\n public static void countSort(int[] arr, int exp) {\r\n // write code here\r\n System.out.print(\"After sorting on \" + exp + \" place -> \");\r\n print(arr);\r\n }\r\n\r\n public static void print(int[] arr) {\r\n for (int i = 0; i < arr.length; i++) {\r\n System.out.print(arr[i] + \" \");\r\n }\r\n System.out.println();\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n radixSort(arr);\r\n print(arr);\r\n }\r\n\r\n}"},"python":{"code":"import math;\n\ndef Display(arr):\n for i in arr:\n print(i,end = \" \");\n\ndef countsort(arr, d):\n # write your code here\n \n print(\"After sorting on\" , d , \"place ->\", end = \" \");\n Display(arr);\n print();\n\n\ndef radixSort(arr):\n # write your code here\n\n\ndef main():\n n = int(input());\n arr = []\n for i in range(0, n):\n ele = int(input());\n arr.append(ele);\n\n \n radixSort(arr);\n Display(arr);\n \n\nif __name__ == \"__main__\":\n main()"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n7 \r\n2 \r\n4 \r\n1 \r\n3","sampleOutput":"After sorting on 1 place -> 1 2 3 4 7 \r\n1 2 3 4 7","questionVideo":"https://www.youtube.com/embed/a5e7RgCdel0?end=390","hints":[],"associated":[{"id":"1727b59c-2be8-421c-97e8-96fd668bba3c","name":"Suppose you have given an input array of large numbers say 174835 to 863561. Which algorithm will you use in order to sort these numbers in linear time.","slug":"suppose-you-have-given-an-input-array-of-large-numbers-say-174835-to-863561-which-algorithm-will-you-use-in-order-to-sort-these-numbers-in-linear-time","type":4},{"id":"74d5c67e-09f4-4f69-80a6-647e83e47753","name":"Which of the following algorithm sort numbers digit by digit strating from least significant digit to most significant digit?","slug":"which-of-the-following-algorithm-sort-numbers-digit-by-digit-strating-from-least-significant-digit-to-most-significant-digit","type":4},{"id":"772a6c28-6f51-4ac2-b9fd-560dce56b6f7","name":"Which of the following algorithm is best to sort numbers on the basis of time if given in a range?","slug":"which-of-the-following-algorithm-is-best-to-sort-numbers-on-the-basis-of-time-if-given-in-a-range","type":4},{"id":"ddae504a-d7ce-45aa-91fc-86e62aabde35","name":"What is the time complexity of count sort ?","slug":"what-is-the-time-complexity-of-count-sort","type":4},{"id":"df4a9b55-c75c-4396-a010-224646b6e3f5","name":"What will be the space complexity of count sort?","slug":"what-will-be-the-space-complexity-of-count-sort","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8e3abac7-a5ab-4090-abd1-b26ef8b53d70","name":"Time and Space Complexity","slug":"time-and-space-complexity","type":0},{"id":"92c5313f-49d8-4a37-95e7-0a41306a739c","name":"Radix Sort","slug":"radix-sort","type":1}],"next":{"id":"21fd35d2-af8e-49c2-ae20-bf92620e9bd1","name":"Radix Sort","type":3,"slug":"radix-sort"},"prev":{"id":"576f4697-e7f1-4ce7-9014-e570ffe3f603","name":"Count Sort","type":3,"slug":"count-sort"}}}

Radix Sort

1. You are given an array(arr) of integers. 2. You have to sort the given array in increasing order using radix sort.

{"id":"7edc7c52-7480-490a-b7a2-8ffef0c3c479","name":"Radix Sort","description":"1. You are given an array(arr) of integers.\r\n2. You have to sort the given array in increasing order using radix sort.","inputFormat":"An Integer n \r\narr1\r\narr2..\r\nn integers","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= N &lt;= 10000\r\n0 &lt;= arr[i] &lt;= 10^8","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<vector>\n#include<climits>\n#include<algorithm>\n\nusing namespace std;\n\nvoid Display(vector<int>& arr){\n for(int ele : arr){\n cout<< ele << \" \";\n }\n}\n\nvoid countsort(vector<int> &arr, int d){\n // write your code here\n\n cout<< \"After sorting on \" << d << \" place -> \";\n Display(arr);\n cout << endl;\n}\n\nvoid radixSort(vector<int> &arr){\n // write your code here\n\n}\n\n\nint main(){\n int n;\n cin >> n;\n vector<int> arr(n, 0);\n \n for(int i = 0; i < n; i++){ \n cin >> arr[i];\n }\n \n radixSort(arr);\n Display(arr);\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void radixSort(int[] arr) {\r\n // write code here \r\n }\r\n\r\n public static void countSort(int[] arr, int exp) {\r\n // write code here\r\n System.out.print(\"After sorting on \" + exp + \" place -> \");\r\n print(arr);\r\n }\r\n\r\n public static void print(int[] arr) {\r\n for (int i = 0; i < arr.length; i++) {\r\n System.out.print(arr[i] + \" \");\r\n }\r\n System.out.println();\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n radixSort(arr);\r\n print(arr);\r\n }\r\n\r\n}"},"python":{"code":"import math;\n\ndef Display(arr):\n for i in arr:\n print(i,end = \" \");\n\ndef countsort(arr, d):\n # write your code here\n \n print(\"After sorting on\" , d , \"place ->\", end = \" \");\n Display(arr);\n print();\n\n\ndef radixSort(arr):\n # write your code here\n\n\ndef main():\n n = int(input());\n arr = []\n for i in range(0, n):\n ele = int(input());\n arr.append(ele);\n\n \n radixSort(arr);\n Display(arr);\n \n\nif __name__ == \"__main__\":\n main()"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n7 \r\n2 \r\n4 \r\n1 \r\n3","sampleOutput":"After sorting on 1 place -> 1 2 3 4 7 \r\n1 2 3 4 7","questionVideo":"https://www.youtube.com/embed/a5e7RgCdel0?end=390","hints":[],"associated":[{"id":"1727b59c-2be8-421c-97e8-96fd668bba3c","name":"Suppose you have given an input array of large numbers say 174835 to 863561. Which algorithm will you use in order to sort these numbers in linear time.","slug":"suppose-you-have-given-an-input-array-of-large-numbers-say-174835-to-863561-which-algorithm-will-you-use-in-order-to-sort-these-numbers-in-linear-time","type":4},{"id":"74d5c67e-09f4-4f69-80a6-647e83e47753","name":"Which of the following algorithm sort numbers digit by digit strating from least significant digit to most significant digit?","slug":"which-of-the-following-algorithm-sort-numbers-digit-by-digit-strating-from-least-significant-digit-to-most-significant-digit","type":4},{"id":"772a6c28-6f51-4ac2-b9fd-560dce56b6f7","name":"Which of the following algorithm is best to sort numbers on the basis of time if given in a range?","slug":"which-of-the-following-algorithm-is-best-to-sort-numbers-on-the-basis-of-time-if-given-in-a-range","type":4},{"id":"ddae504a-d7ce-45aa-91fc-86e62aabde35","name":"What is the time complexity of count sort ?","slug":"what-is-the-time-complexity-of-count-sort","type":4},{"id":"df4a9b55-c75c-4396-a010-224646b6e3f5","name":"What will be the space complexity of count sort?","slug":"what-will-be-the-space-complexity-of-count-sort","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8e3abac7-a5ab-4090-abd1-b26ef8b53d70","name":"Time and Space Complexity","slug":"time-and-space-complexity","type":0},{"id":"92c5313f-49d8-4a37-95e7-0a41306a739c","name":"Radix Sort","slug":"radix-sort","type":1}],"next":{"id":"21fd35d2-af8e-49c2-ae20-bf92620e9bd1","name":"Radix Sort","type":3,"slug":"radix-sort"},"prev":{"id":"576f4697-e7f1-4ce7-9014-e570ffe3f603","name":"Count Sort","type":3,"slug":"count-sort"}}}
plane

Editor


Loading...

Radix Sort

easy

1. You are given an array(arr) of integers. 2. You have to sort the given array in increasing order using radix sort.

Constraints

1 <= N <= 10000 0 <= arr[i] <= 10^8

Format

Input

An Integer n arr1 arr2.. n integers

Output

Check the sample ouput and question video.

Example

Sample Input

5 7 2 4 1 3

Sample Output

After sorting on 1 place -> 1 2 3 4 7 1 2 3 4 7

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode