Skip to content

Commit f77809c

Browse files
author
Divyendu Singh
committed
typo fix and claim commit
1 parent 2924e18 commit f77809c

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

Bucket Sort/README.markdown

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ Bucket Sort, also known as Bin Sort, is a distributed sorting algorithm, which s
99
See the algorithm in action [here](https://www.cs.usfca.edu/~galles/visualization/BucketSort.html) and [here](http://www.algostructure.com/sorting/bucketsort.php).
1010

1111
The performance for execution time is:
12-
12+
1313
| Case | Performance |
1414
|:-------------: |:---------------:|
1515
| Worst | O(n^2) |
1616
| Best | Omega(n + k) |
17-
| Average | Theta(n + k) |
18-
17+
| Average | Theta(n + k) |
18+
1919
Where **n** = the number of elements and **k** is the number of buckets.
2020

21-
In the *best case*, the algorithm distributes the elements uniformily between buckets, a few elements are placed on each bucket and sorting the buckets is **O(1)**. Rearranging the elements is one more run through the initial list.
21+
In the *best case*, the algorithm distributes the elements uniformly between buckets, a few elements are placed on each bucket and sorting the buckets is **O(1)**. Rearranging the elements is one more run through the initial list.
2222

2323
In the *worst case*, the elements are sent all to the same bucket, making the process take **O(n^2)**.
2424

@@ -63,11 +63,11 @@ So the buckets are:
6363
Now we need to choose a distribution function.
6464

6565
`bucketNumber = (elementValue / totalNumberOfBuckets) + 1`
66-
66+
6767
Such that by applying that function we distribute all the elements in the buckets.
6868

6969
In our example it is like the following:
70-
70+
7171
1. Apply the distribution function to `2`. `bucketNumber = (2 / 10) + 1 = 1`
7272
2. Apply the distribution function to `56`. `bucketNumber = (56 / 10) + 1 = 6`
7373
3. Apply the distribution function to `4`. `bucketNumber = (4 / 10) + 1 = 1`
@@ -91,12 +91,12 @@ Our buckets will be filled now:
9191

9292
We can choose to insert the elements in every bucket in order, or sort every bucket after distributing all the elements.
9393

94-
### Put the elements back in the list
94+
### Put the elements back in the list
9595

9696
Finally we go through all the buckets and put the elements back in the list:
97-
97+
9898
`[2, 4, 26, 55, 56, 77, 98]`
99-
99+
100100

101101
## Swift implementation
102102

@@ -109,9 +109,9 @@ Here is a diagram that shows the functions, data structures and protocols for ou
109109
`bucketSort()` is a generic function that can apply the algorithm to any element of type `T`, as long as `T` is `Sortable`.
110110

111111
```swift
112-
public func bucketSort<T:Sortable>(elements: [T],
113-
distributor: Distributor,
114-
sorter: Sorter,
112+
public func bucketSort<T:Sortable>(elements: [T],
113+
distributor: Distributor,
114+
sorter: Sorter,
115115
buckets: [Bucket<T>]) -> [T] {
116116
precondition(allPositiveNumbers(elements))
117117
precondition(enoughSpaceInBuckets(buckets, elements: elements))
@@ -201,11 +201,11 @@ public struct InsertionSorter: Sorter {
201201
for i in 0 ..< results.count {
202202
var j = i
203203
while ( j > 0 && results[j-1] > results[j]) {
204-
204+
205205
let auxiliar = results[j-1]
206206
results[j-1] = results[j]
207207
results[j] = auxiliar
208-
208+
209209
j -= 1
210210
}
211211
}
@@ -236,7 +236,7 @@ public struct RangeDistributor: Distributor {
236236
public func distribute<T:Sortable>(element: T, inout buckets: [Bucket<T>]) {
237237
let value = element.toInt()
238238
let bucketCapacity = buckets.first!.capacity
239-
239+
240240
let bucketIndex = value / bucketCapacity
241241
buckets[bucketIndex].add(element)
242242
}

0 commit comments

Comments
 (0)