Skip to content

Instantly share code, notes, and snippets.

View bmershon's full-sized avatar

Brooks Mershon bmershon

View GitHub Profile
@bmershon
bmershon / .block
Last active May 7, 2016 14:30 — forked from mbostock/.block
D2 Shape Distribution
license: gpl-3.0
@bmershon
bmershon / README.md
Last active January 15, 2016 00:22
Dutch Flag Problem II
@bmershon
bmershon / README.md
Last active January 15, 2016 04:24
Dutch Flag Problem

The Dutch national flag problem exposes an example of an input for which quicksort performs poorly. When there are many duplicates in the array to be sorted, it will often be the case that unecessary function calls to the recursive sort() method will be made on subarrays that already contain elements that are all equal.

The three bars of the Dutch National Flag hint towards another way of thinking about partitioning an unsorted array: move elements around such that elements we have all the elements less than pivot element, followed by all elements equal to the pivot element, and then all elements greater than the pivot element. In the case of an unsorted array of just three different values, say, red, white, and blue, we can imagine that sorting these shuffled values around would lead to a final structure much like the Dutch National Flag.

This implementation of quicksort uses Dijkstra's clever partitioning algorithm to expand regions of v

@bmershon
bmershon / README.md
Last active January 3, 2016 17:29
Shellsort II

An improvement upon a previous presentation of Shellsort. Here, each color indicates the elements which may be swapped during a given iteration of Shellsort.

The number of colors converges to 1 by following a sequence generated by the following code:

  while (h < N/3) h = 3*h + 1;

  ...
  
 //in the main loop
@bmershon
bmershon / README.md
Last active January 3, 2016 04:56
Shellsort

An implementation of shellsort with a visualization based off of Mike Bostock's Quicksort animation.

Red lines indicate every hth index as the algorithm performs insertion sort for h independent interleaved sorted subsequences.

@bmershon
bmershon / README.md
Last active October 24, 2016 17:11
Context Sensitive Label Visibility

This was developed at the Washington Post as a prototype for an illustration about the devastating effects of U.S. nuclear testing carried out around the Marshall Islands. The purpose of this prototype was to demonstrate a means for showing geographic information what would otherise require many "small multiples" in a more dense, interactive, and perhaps intuitive way.

The use of context-senstive label placement that attempts to avoid cluttering the view with unecessary details was one of the most valuable design exercises involved in creating this graphic prototype.

SVG rendering is not performant enough for smooth mouse interaction of the 3D globe. The author's 2011 Mac Book Air, for example, manages a mere 11 frames per second as it performs the main update loop. Performance could be improved with more thoughtful managment of D3 4.0 selections as well as canvas rendering using the new D3 4.0 semantics for drawing paths.

N.B. Hex binning was performed using longitude and latitude: this produces a distor

@bmershon
bmershon / README.md
Last active September 11, 2015 19:08
Convex Combination

A convex combination of three vectors in the plane allows us to represent any vector in the convex hull determined by those three vectors.

@bmershon
bmershon / .block
Last active September 18, 2016 17:57
Nevada Wilderness
border: no
@bmershon
bmershon / .block
Last active December 12, 2017 17:03
Drink Blueprints
height: 768
width: 1050
border: no
license: gpl-3.0
@bmershon
bmershon / README.md
Last active November 26, 2016 22:48
squares

I wanted to make a looping animation after checking out the sweet work of Florian de Looij (@FloriandeLooij).