<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Algorithms on Adam Hacks</title><link>https://hackeradam.com/blog/algorithms/</link><description>Recent content in Algorithms on Adam Hacks</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 28 Feb 2021 00:00:00 +0000</lastBuildDate><atom:link href="https://hackeradam.com/blog/algorithms/index.xml" rel="self" type="application/rss+xml"/><item><title>CS Review: Merge Sort</title><link>https://hackeradam.com/blog/cs-review-merge-sort/</link><pubDate>Sun, 28 Feb 2021 00:00:00 +0000</pubDate><guid>https://hackeradam.com/blog/cs-review-merge-sort/</guid><description>&lt;p&gt;Merge sort is among the divide and conquer algorithms. That is to say, it divides the input array into half, calls itself on both halves. This process is done recursively over the entire array. When we’re done, all the individually sorted pieces are merged back together to form the fully sorted array.&lt;/p&gt;</description></item><item><title>CS Review: Quicksort</title><link>https://hackeradam.com/blog/cs-review-quicksort/</link><pubDate>Sun, 28 Feb 2021 00:00:00 +0000</pubDate><guid>https://hackeradam.com/blog/cs-review-quicksort/</guid><description>&lt;p&gt;Quicksort is another one of the divide and conquer sorting algorithms. It works by partitioning the array around some chosen pivot point, which there are a few different ways to choose.&lt;/p&gt;
&lt;p&gt;Quicksort is generally preferred over &lt;a href="https://hackeradam.com/blog/cs-review-merge-sort/"&gt;merge sort&lt;/a&gt; for sorting arrays due to the fact that the general form of the algorithm sorts in-place.&lt;/p&gt;</description></item><item><title>CS Review: Bubble Sort</title><link>https://hackeradam.com/blog/cs-review-bubble-sort/</link><pubDate>Sat, 27 Feb 2021 00:00:00 +0000</pubDate><guid>https://hackeradam.com/blog/cs-review-bubble-sort/</guid><description>&lt;p&gt;Bubble sort is the easiest possible sorting algorithm you could imagine. It works by simply iterating over an array of data and comparing adjacent items. If those items are in the wrong order, then they are swapped. In doing this, the largest items “bubble up” to the correct position in the array (assuming ascending order, anyway).&lt;/p&gt;
&lt;p&gt;While this is great from a simplicity standpoint, it’s a pretty awful solution in terms of efficiency. The worst-case performance of bubble sort is O(n2). The best-case turns out to be O(n).&lt;/p&gt;
&lt;p&gt;As you can see, this algorithm is not suitable for any sufficiently large datasets.&lt;/p&gt;</description></item><item><title>CS Review: Selection Sort</title><link>https://hackeradam.com/blog/cs-review-selection-sort/</link><pubDate>Sat, 27 Feb 2021 00:00:00 +0000</pubDate><guid>https://hackeradam.com/blog/cs-review-selection-sort/</guid><description>&lt;p&gt;The previous sorting algorithm we took a look at was &lt;a href="https://hackeradam.com/blog/cs-review-bubble-sort/"&gt;bubble sort&lt;/a&gt;. This time around we will be taking a look at selection sort, which is slightly more complex than bubble sort, but only by a tiny bit.&lt;/p&gt;
&lt;p&gt;The idea behind selection sort is that you keep iterating over your array of data, finding the minimum element each time and placing it at the start of the list. In this way, you can think of selection sort as managing two subarrays: the portion of the array that is sorted and the portion that still needs to be sorted.&lt;/p&gt;
&lt;p&gt;Like bubble sort, selection sort has a worst-case time complexity of O(n2), but it does have a tendency to outperform bubble sort. Selection sort also has a nice side-effect where it will never do more than O(n) swaps, which is nice if you’re operating in an environment in which memory writes are costly.&lt;/p&gt;</description></item><item><title>The Dining Philosophers Problem</title><link>https://hackeradam.com/blog/the-dining-philosophers-problem/</link><pubDate>Fri, 21 Aug 2020 00:00:00 +0000</pubDate><guid>https://hackeradam.com/blog/the-dining-philosophers-problem/</guid><description>&lt;p&gt;The dining philosophers problem is a classic problem in the realm of computer science. If you’ve had any formal CS education you’ve more than likely seen the problem when learning about concurrent programming.&lt;/p&gt;
&lt;p&gt;Today we will take a look at the problem and look at an example of how we can solve it.&lt;/p&gt;</description></item><item><title>Quickly Generating Primes Below n with the Sieve of Eratosthenes</title><link>https://hackeradam.com/blog/quickly-generating-primes-below-n-with-the-sieve-of-eratosthenes/</link><pubDate>Wed, 17 May 2017 00:00:00 +0000</pubDate><guid>https://hackeradam.com/blog/quickly-generating-primes-below-n-with-the-sieve-of-eratosthenes/</guid><description>&lt;p&gt;The uses for prime numbers in computer science are nearly endless. They are useful for everything from hashing, cryptology, factorization, and all sorts of applications in-between.&lt;/p&gt;
&lt;p&gt;There exists a great number of algorithms that allow us to quickly generate primes, but today we are going to take a look at a popular method known as a &lt;strong&gt;prime sieve&lt;/strong&gt;. There are a number of different implementations of prime sieves, but one of the simplest to implement is known as the &lt;a href="https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes"&gt;Sieve of Eratosthenes&lt;/a&gt;. This algorithm is great for quickly generating smaller prime numbers (but it may not be the best choice for generating very large primes).&lt;/p&gt;</description></item></channel></rss>