0% found this document useful (0 votes)
192 views3 pages

Addres Calculation Sort

The document discusses address calculation sort, an early sorting algorithm that uses an auxiliary array to sort elements by placing them in buckets based on their value. It works by calculating the address of each element in the auxiliary array, incrementing the value at that address, and then copying elements back from the auxiliary array to the original array in sorted order. The time complexity is O(n+k) where n is the number of elements and k is the range, and it uses O(n+k) space for the auxiliary array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
192 views3 pages

Addres Calculation Sort

The document discusses address calculation sort, an early sorting algorithm that uses an auxiliary array to sort elements by placing them in buckets based on their value. It works by calculating the address of each element in the auxiliary array, incrementing the value at that address, and then copying elements back from the auxiliary array to the original array in sorted order. The time complexity is O(n+k) where n is the number of elements and k is the range, and it uses O(n+k) space for the auxiliary array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

GUMATAY, GEOFFREY VIN N MAY 08, 2023

BSCS II-H ALGORITHMS & COMPLEXITY

ADDRESS CALCULATION SORT

Overview:
History
Address Calculation Sort is a sorting algorithm that was developed by Harold H.
Seward in 1951. It was one of the earliest sorting algorithms developed for computers and
was used extensively in the early days of computing.

Algorithm
Address Calculation Sort is a non-comparison based sorting algorithm that uses an
auxiliary array, also known as a bucket array, to sort the input elements. The algorithm
works by calculating the address of each element in the auxiliary array based on the value
of the element, and then placing the element in the corresponding bucket in the auxiliary
array. Finally, the algorithm traverses the auxiliary array in order and copies the sorted
elements back to the original array.

Here is the step-by-step algorithm for Address Calculation Sort:


 Find the maximum element in the input array.
 Create an auxiliary array of size (max_element + 1) and initialize all elements to
0.
 Traverse the input array, and for each element:
a. Calculate the address of the element in the auxiliary array using the formula:
‘address = element_value’.
b. Increment the value at the calculated address in the auxiliary array by 1.
 Traverse the auxiliary array, and for each non-zero element:
a. Copy the element back to the original array.
b. Decrement the value at the corresponding address in the auxiliary array by 1.

Time Complexity
The time complexity of Address Calculation Sort is O(n+k), where n is the number
of elements in the input array, and k is the range of the input elements. The space
complexity of the algorithm is also O(n+k) due to the use of an auxiliary array. Address
Calculation Sort is particularly useful when the range of the input elements is small
compared to the number of elements, as it can achieve linear time complexity. However,
if the range of the input elements is too large, the algorithm may not be practical due to
the memory requirements of the auxiliary array.

Simulation:
To simulate the Address Calculation Sort algorithm, we need to perform the following
steps:
1. Determine the maximum value in the array x and use it to calculate the number of
digits needed to represent the largest element. In this case, the largest element is
990, so we need three digits to represent it.
2. Initialize an array of empty lists, with one list for each possible digit (0-9).
3. For each element in the array x, determine its digit in the specified place value
(starting from the rightmost digit) and append the element to the list corresponding to
that digit.
4. Concatenate the lists in order, from the list corresponding to the smallest digit to the
list corresponding to the largest digit.
5. Repeat steps 3-4 for each successive digit position, from right to left.

Here's a step-by-step simulation of the Address Calculation Sort algorithm using the
provided input:
x 360 289 589 467 699 075 201 408 390 194 510 220 172 990 034
f(x) 3 2 5 4 6 0 2 4 3 1 5 2 1 9 0

1. The maximum value in x is 990, so we need three digits to represent it.

2. Initialize an array of empty lists:


[[], [], [], [], [], [], [], [], [], []]

3. For each element in x, determine its digit in the ones place and append it to the list
corresponding to that digit:
[[0, 360], [289], [], [467], [508, 075], [201], [], [390, 220], [], [194, 510, 172, 034]]
4. Concatenate the lists in order:
[360, 075, 201, 034, 510, 172, 194, 289, 467, 220, 390, 990]

5. Repeat steps 3-4 for the tens and hundreds places:


[[360, 034], [201, 194], [0, 075, 289, 220], [], [510], [172], [390], [], [467], [], [990], []]
[0, 075, 194, 172, 289, 201, 220, 034, 360, 390, 467, 510, 990]
[[], [0, 034, 075], [172, 194, 201, 220], [], [289], [360, 390], [], [], [], [], [467, 510, 990]]
[0, 034, 075, 172, 194, 201, 220, 289, 360, 390, 467, 510, 990]

Therefore, the sorted array is:


[0, 34, 75, 172, 194, 201, 220, 289, 360, 390, 467, 510, 990]

You might also like