Swift Algorithm Club
The Swift Algorithm Club is a new site that described implementations of popular algorithms and data structures in Swift. However there is also an added bonus in that there are also detailed explanations of how they work. The list below gives an idea of what is available or under construction, and I’m sure they would be delighted to receive contributions.
- Linear Search. Find an element in an array.
- Binary Search. Quickly find elements in a sorted array.
- Count Occurrences. Count how often a value appears in an array.
- Select Minimum / Maximum. Find the minimum/maximum value in an array.
- k-th Largest Element. Find the k-th largest element in an array, such as the median.
- Selection Sampling. Randomly choose a bunch of items from a collection.
- Union-Find. Keeps track of disjoint sets and lets you quickly merge them.
- Brute-Force String Search. A naive method.
- Boyer-Moore. A fast method to search for substrings. It skips ahead based on a look-up table, to avoid looking at every character in the text.
- Longest Common Subsequence. Find the longest sequence of characters that appear in the same order in both strings.
It's fun to see how sorting algorithms work, but in practice you'll almost never have to provide your own sorting routines. Swift's own sort() is more than up to the job. But if you're curious, read on...
- Insertion Sort
- Selection Sort
- Shell Sort
- Merge Sort
- Heap Sort
- Counting Sort
- Radix Sort
- Topological Sort
Bad sorting algorithms (don't use these!):
- Bubble Sort
- Run-Length Encoding (RLE). Store repeated values as a single byte and a count.
- Huffman Coding. Store more common elements using a smaller number of bits.
- Shuffle. Randomly rearranges the contents of an array.
- Comb Sort. An improve upon the Bubble Sort algorithm.
- Greatest Common Divisor (GCD). Special bonus: the least common multiple.
- Permutations and Combinations. Get your combinatorics on!
- Shunting Yard Algorithm. Convert infix expressions to postfix.
- k-Means Clustering. Unsupervised classifier that partitions data into k clusters.
- k-Nearest Neighbors
- Linear Regression
- Logistic Regression
- Neural Networks