Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
21 views

Linear Time Sorting

Uploaded by

MS.KIRUTHIKA V
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Linear Time Sorting

Uploaded by

MS.KIRUTHIKA V
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Linear Time Sorting

Linear time sorting is a subset of sorting algorithms with a


significant advantage: they can sort a given set of elements in
linear time, the runtime increases linearly with the input size.

Linear time sorting algorithm is descending sort. Using input-


domain knowledge, computational sorting achieves linear time
complexity. A numeric sort first scans the input array to
determine the count of each element. It then uses these numbers
to calculate the correct positions of the elements in the ordered
result table. The algorithm consists of the following steps:
1. To determine the range, identify the minimum and maximum
values of the input array.
2. Create a worksheet initialised with the range size and zeros.
3. Iterate over the input array and increment each element found.
4. Modify the worksheet by calculating the cumulative total to
obtain the correct positions for each element.
5. Create an output array the same size as the input array.
6. Move the input array again, placing each element in the correct
position in the output array based on the worksheet.
7. The result table now contains sorted elements.
The main advantage of descending sort is that it achieves a linear
time complexity of O(n), which makes it very efficient for large
input sizes.

It is important to note that other sorting algorithms, such as


quicksort or merge, typically have a time complexity of O(n log n),
which is considered efficient for many practical applications.
History
One of the earliest linear time sorting algorithms is the bucket
sort, proposed by Harold H. Seward in 1954. A bucket sort divides
the input elements into a finite number of buckets and then sorts
each bucket separately. This algorithm has linear time complexity
if the distribution of input elements is relatively uniform.

In 1959, Kenneth E. Iverson introduced a radix algorithm that


achieves linear time complexity. Radix sorts elements by their
numbers or signs from least significant to most significant. It uses
robust sorting algorithms, such as numeric or bucket sort, to sort
the elements at each digit location.

Types of Linear Time Sorting


● There are several different linear time sorting algorithms.
● The two main types are count-based algorithms and radix-
based algorithms.

Here are the most common linear time sorting algorithms,


classified based on the following types:

Counting-Based Algorithms
1. Counting-Based Sort:Counting-Based is a non-comparative
sorting algorithm. It counts the occurrence of each particular
element in the input array and uses this information to determine
the correct position of each element in the sorted output array.
Counting-Based sort assumes that the input elements are
integers or can be added to integers.

Radix-Based Algorithms
1. Radix Sort: Radix Sort is a non-comparison-basedsorting
algorithm that sorts elements by their numbers or characters. It
counts each number or sign in the elements from the least
significant number to the most significant Radical sorting
assumes that the input elements are integers or strings.
2. Bucket Sort:Bucket Sort is a variant of Radix Sort that divides
elements into fixed groups based on their range or distribution.
Each segment is sorted separately using a different sorting
algorithm or recursively bin-sort.
3. MSD (Most Significant Digit) Radix Sort: MSD Radix Sort is a
variant of radix sort that starts sorting elements based on their
most significant It recursively divides the elements into
subgroups based on the value of the current number and applies
MSD Radix Sort to each subgroup until all the numbers have been
counted.
4. LSD (Least Significant Digit) Radix Sort: LSD Radix Sort is
another variant that starts sorting elements based on their least
significant. It recursively sorts the elements based on each
number from rightmost to leftmost, producing a sorted result.
Both count-based and root-based sorting algorithms achieve
linear time complexity by exploiting specific properties of the
input elements, such as their range or representational structure
(e.g., numbers or characters). However, their applicability may
vary depending on the characteristics of the input data.

Advantages of linear time sorting


Linear time sorting algorithms, such as numerical sorting, offer
several advantages in specific scenarios.
1. Efficient for large input sizes:The time complexity of linear
time sorting algorithms is O(n), which means that the running
time increases linearly with the input size.
2. No comparison operations:Linear-time sorting algorithms,
such as enumeration sort, do not rely on elementary comparison
Instead, they use specific attributes or information about the
input elements, such as their extent or distribution.
3. Suitability to specific input properties: Linear-time sorting
algorithms often have specific requirements or assumptions
about the input elements.
4. Stable sort:Many linear-time sorting algorithms, including
numerical and radix sort, are inherently stable.
5. Ease of use: Linear-time sorting algorithms such as enumeration
sorting are often relatively easy to implement compared to more
complex comparison-based sorting algorithms.

Disadvantages of linear time sorting


1. Constraining input requirements: Linear time sorting
algorithms often have specific requirements or assumptions
about the input elements. For example, to calculate a sort order,
you need to know the range of input elements in advance. This
restriction limits their applicability to situations where these
conditions are met. Memory requirements may become
impractical or exceed available resources if the range is
extensive or unknown.
2. Additional space requirements: Some linear time sorting
algorithms, such as numerical sort, require additional space to
store other arrays or data structures.
3. Lack of Versatility:Linear time sorting algorithms are
specialized algorithms designed for specific scenarios or
constraints.
4. Inefficient for small ranges or sparse data:Linear-time
sorting algorithms such as enumeration are most efficient when
the range of input elements is small and densely distributed. I
5. Limited to specificdata types: Linear-time sorting algorithms,
such as enumeration sort, are primarily designed to sort non-
negative integers or key-value objects.

Applications of Linear time sorting algorithms


Linear time sorting algorithms are efficient and have many
applications in various fields. Here are some typical applications
of linear time order:
1. Sorting Small Range Integers:Linear time sorting algorithms
such as count sort and radix sort are ideal for sorting arrays of
integers when the range of values These algorithms achieve
linear time complexity by making assumptions about the input
data, allowing them to bypass comparison-based sorting.
2. String sorting:Linear time sorting algorithms can also be
applied to sort strings efficiently.
3. Database Functions:Sorting is an essential function of Linear
time sorting algorithms can efficiently sort large data sets based
on specific columns or fields.
4. Creating Histograms:Histograms are essential for various
statistical and data analysis tasks. Linear time sorting algorithms,
such as numerical sorting, can generate histograms by efficiently
counting the occurrences of elements in a dataset.
5. External sorting: The external sorting technique is used in
scenarios where the data cannot fit entirely in memory.
6. Event Scheduling:Linear time sorting algorithms can schedule
events based on their start or end times.
7. Analyzing log files:Analyzing log files is a common task in
system administration and debugging.
8. Data Compression:Sorting plays an essential role in various
data compression techniques.

Implementation of Linear Time Sorting

You might also like