Skip to content

Conversation

@Ramy-Badr-Ahmed
Copy link
Member

@Ramy-Badr-Ahmed Ramy-Badr-Ahmed commented Sep 10, 2024

Description:

This pull request introduces an implementation of the Radix Sort algorithm with support for different bases.

Definition:

  • Radix Sort is a non-comparison-based sorting algorithm that sorts numbers by processing individual digits.
  • The Algorithm is efficient for sorting integers and other values with a fixed number of digits or characters.
  • It sorts numbers by processing individual digits. It works by performing Counting Sort on each digit, starting from the least significant digit to the most significant digit.
  • Time Complexity: O(d * (n + k)), where n is the number of elements, d is the number of digits, and k is the range of digits.
  • Compared to the comparison-based sorting algorithms (Implemented Merge Sort Algorithm #7, Implemented Heap Sort Algorithm #8, Implemented Quick Sort Algorithm #10), Radix Sort is non-comparison-based; it can be more efficient for sorting integers with a fixed number of digits (when the number of digits is small compared to the number of elements).
  • Radix Sort is more efficient than Gnome Sort (O(n^2)) Implemented Gnome Sort Algorithm #9 for larger datasets.

Implementation Details:

radix_sort.f90: Contains the radix_sort_module with:

radix_sort: A subroutine that sorts the input array using the Radix Sort algorithm.
counting_sort: A subroutine that performs Counting Sort based on the digit represented by exp.

The module has been enhanced to support sorting based on different numeral systems (bases). The radix_sort subroutine can now be used with different bases, such as base 2, 10, and 16.

Example Usage:

example_usage_radix_sort.f90: Includes three test programs demonstrating the radix_sort subroutine from the radix_sort_module with different bases:

Base 10:
    Array: [170, 45, 75, 90, 802, 24, 2, 66, 15, 40]
    Output: Sorted array in base 10.

Base 2:
    Array: [1010, 1101, 1001, 1110, 0010, 0101, 1111, 0110, 1000, 0001]
    Output: Sorted binary array, represented in decimal.

Base 16:
    Array: [0xAB, 0x1F, 0x3D, 0xFF, 0x10, 0x05, 0xD3, 0x2A, 0xB4, 0x00]
    Output: Sorted hexadecimal array, represented in decimal.

The program sorts the sample arrays in their respective bases and prints the results.

Additional Test Cases:

tests_radix_sort.f90: A test program that includes a variety of test cases to validate the radix_sort implementation.


Reference

The Algorithm Design Manual, Latest edition

Copy link
Member Author

@Ramy-Badr-Ahmed Ramy-Badr-Ahmed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @SatinWukerORIG ,
Looking forward to your review 🙂

Ramy-Badr-Ahmed and others added 19 commits September 12, 2024 12:18
…rt_implementation

# Conflicts:
#	DIRECTORY.md
…ure/quick_sort_implementation

# Conflicts:
#	DIRECTORY.md
…rt_implementation

# Conflicts:
#	DIRECTORY.md
…ort_implementation

# Conflicts:
#	DIRECTORY.md
…ort_implementation

# Conflicts:
#	DIRECTORY.md
Copy link
Member Author

@Ramy-Badr-Ahmed Ramy-Badr-Ahmed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more test cases for the radix_sort module.

Copy link
Member

@SatinWukerORIG SatinWukerORIG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great implementation and test cases. The comments are also very detailed.
I can merge it and then refactor the directory structure. Then you can put examples, tests, and modules under different folders as mentioned in issue #13!

@SatinWukerORIG SatinWukerORIG merged commit ef37fe2 into TheAlgorithms:main Sep 16, 2024
@Ramy-Badr-Ahmed
Copy link
Member Author

Great implementation and test cases. The comments are also very detailed. I can merge it and then refactor the directory structure. Then you can put examples, tests, and modules under different folders as mentioned in issue #13!

Thanks, Satin!
Sure 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants