0% found this document useful (0 votes)
5 views11 pages

Radix Sort

Radix Sort is a non-comparative sorting algorithm that sorts integers by processing individual digits from the least significant to the most significant. It is efficient for large datasets and operates in linear time for fixed digit lengths. The algorithm involves multiple passes using a stable sorting method, such as Counting Sort, to sort based on each digit place.

Uploaded by

cakomi4037
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views11 pages

Radix Sort

Radix Sort is a non-comparative sorting algorithm that sorts integers by processing individual digits from the least significant to the most significant. It is efficient for large datasets and operates in linear time for fixed digit lengths. The algorithm involves multiple passes using a stable sorting method, such as Counting Sort, to sort based on each digit place.

Uploaded by

cakomi4037
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Introduction to Radix Sort

•What is Radix Sort?

. Radix Sort is a non-comparative integer sorting algorithm.


• It sorts numbers by processing individual digits.
• It processes digits from the least significant digit (LSD) to the most significant digit (MSD) or vice versa.

•Key Advantage:

• Efficient for sorting large numbers of integers or strings.


How Radix Sort Works

1.Determine the maximum number of digits (d) in the largest number.

2.Iterate through each digit place:

1. Starting from the least significant digit to the most significant digit.
2. Use a stable sorting algorithm (e.g., Counting Sort) to sort numbers based on the current
digit.
Example Overview

•Example Array: [329, 457, 657, 839, 436, 720, 355]

•Maximum Digits: 3 (since 839 has 3 digits)

•Passes Needed: 3 (units, tens, hundreds)


Pass 1 (Sorting by Units Place and starting from LSD)

•Initial Array: [329, 457, 657, 839, 436, 720, 355]

•Extract Units Digit:


• [9, 7, 7, 9, 6, 0, 5]

•Counting Sort on Units Digit:


• Count digits: [0, 0, 0, 0, 1, 1, 1, 2, 0, 2]
• Cumulative count: [0, 0, 0, 0, 1, 2, 3, 5, 5, 7]
• Place elements: [720, 355, 436, 657, 457, 329, 839]

•Result After Pass 1: [720, 355, 436, 657, 457, 329, 839]
Pass 2 (Sorting by applying count sort on next higher digits)

•Array After Pass 1: [720, 355, 436, 657, 457, 329, 839]

•Extract Tens Digit:


• [2, 5, 3, 5, 5, 2, 3]

•Counting Sort on Tens Digit:


• Count digits: [0, 0, 2, 2, 0, 3, 0, 0, 0, 0]
• Cumulative count: [0, 0, 2, 4, 4, 7, 7, 7, 7, 7]
• Place elements: [720, 329, 436, 839, 355, 657, 457]

•Result After Pass 2: [720, 329, 436, 839, 355, 657, 457]
Pass 3 (Sorting by Hundreds Place)

•Array After Pass 2: [720, 329, 436, 839, 355, 657, 457]

•Extract Hundreds Digit:


• [7, 3, 4, 8, 3, 6, 4]

•Counting Sort on Hundreds Digit:


• Count digits: [0, 0, 0, 2, 2, 0, 1, 1, 1, 0]
• Cumulative count: [0, 0, 0, 2, 4, 4, 5, 6, 7, 7]
• Place elements: [329, 355, 436, 457, 657, 720, 839]

•Result After Pass 3: [329, 355, 436, 457, 657, 720, 839]
Final Sorted Array

•Final Sorted Array: [329, 355, 436, 457, 657, 720, 839]

•Steps Recap:
• Sorted by units place.
• Sorted by tens place.
• Sorted by hundreds place.

•Outcome: Array is sorted in ascending order.


Radix Sort Implementation In C
Conclusion
•Advantages of Radix Sort:
• Linear time complexity for fixed digit length.
• Efficient for large datasets of integers.

•When to Use:
• Suitable for sorting integers, strings, and other data with a fixed size.
• Not suitable for floating-point numbers or data with a large range of values.

You might also like