From 1fdee612433d5e9c30e2efc9c0b8ab2560a46e8b Mon Sep 17 00:00:00 2001
From: ben-burlingham
Date: Sun, 15 Nov 2015 12:48:08 -0800
Subject: [PATCH] Finalizing discussion points.
---
css/style.css | 11 +++
index.html | 228 ++++++++++++++++++++++++++++++++-----------
js/itemgroup.js | 6 --
js/sorter.js | 1 -
js/visualizer-dom.js | 6 +-
js/visualizer.js | 10 +-
6 files changed, 186 insertions(+), 76 deletions(-)
diff --git a/css/style.css b/css/style.css
index a56d359..163548d 100644
--- a/css/style.css
+++ b/css/style.css
@@ -1,3 +1,13 @@
+.src {
+ display:block;
+ font-size:14px;
+ margin:10px 0;
+}
+
+.title {
+ font-weight:bold;
+}
+
.sorter {
background:#f4f4f4;
border:1px solid #bbb;
@@ -38,6 +48,7 @@
.sorter-properties {
height:40px;
left:10px;
+ line-height:normal;
position:absolute;
top:210px;
width:570px;
diff --git a/index.html b/index.html
index e63c829..891870d 100644
--- a/index.html
+++ b/index.html
@@ -14,109 +14,220 @@
Here are visualizations of common sorting algorithms. Use the comparisons counter
and number of items to observe the performance of each randomized case.
- [Source repository]
-
+
+
+ All source data is shuffled using the Fisher-Yates algorithm.
+
+
+
+ There's a fun clip about the sounds of sorting here.
+
+
+
+ Quick sort discussion
+
+ Source Code
+
+
+ Implementation
+
+ - Select a pivot element anywhere in the list
+ - Uses "left" and "right" markers that approach each other from opposite ends of the list
+ - Left marker halts if its current value is greater than pivot
+ - Right marker halts if its current value is less than pivot
+ - Swap after both markers are halted, then continue moving inwards
+ - Once markers pass eachother, recurse for sublists on each side of pivot
+
+
- Quicksort discussion
- used by chrome.
- source code link
+ Notes
+
+ - "Conquer and divide" algorithm
+ - Performance depends heavily on pivot selection
+ - O(n) time possible with partitioning
+
- Mergesort discussion
+ Merge sort discussion
+
+ Source Code
+
+
+ Implementation
+
+ - Recursively split array until only single element slices remain.
+ - Consider two slices. Compare their heads and unshift minimum into a result array.
+ - Continue comparing heads and unshifting until the two slices are empty.
+ - Build result arrays from all the slices.
+ - Recurse the comparison process on the result arrays.
+
+
+
- used by firefox and safari.
- helpful: http://stackoverflow.com/questions/2967153/space-requirements-of-a-merge-sort
- source code link
+ Notes
+
+ - Top down variant: Recursively split into halves, sort halves depth first, ending with original two halves. Tree-like. Implemented here.
+ - Bottom up variant: Split fixed intervals, sort each interval, join into full array, split larger interval, repeat.
+ - Natural variant: Bottom up, but with adaptive interval selection over existing ordering.
+ - Discussion of variants
+
Selection sort discussion
+
+ Source Code
+
+
+ Implementation
+
+ - Consider [0]. Compare it to the rest of the elements to find the minimum value.
+ - Swap [0] with the index of the minimum. [0] is now finished.
+ - Proceed to [1]. Repeat.
+
+
+
- http://stackoverflow.com/questions/15799034/insertion-sort-vs-selection-sort
- finds upstram minimum and swaps with current.
- source code link
+ Notes
+
+ - To remember: selection sort selects the minimum.
+ - Be aware of the unstable version, where a swap is greedy.
+ - No other sorting algorithm has less data movement (Rosetta Code)
+ - Good for cases where writes are expensive.
+
+ data-stable='Yes'
+ data-adaptive='No'
+ data-worst-perf='O (n^2)'
+ data-avg-perf='O (n^2)'
+ data-best-perf='O (n^2)'
+ data-worst-memory='0'>
Insertion sort discussion
+
+ Source Code
+
- how is this different from bubble and selection.
- swap. highlight. fade.
- source code link
+ Implementation
+
+ - Compare [1] and [0]. Swap if [0] > [1].
+ - Compare [2] and [1]. Swap if needed. Continue swapping downward one by one until no swap is needed.
+ - Repeat with [3], [4], etc. until end of the array.
+
+
+
+
+ Notes
+
+ - Simplicity can make insertion sort a good choice for small arrays.
+ - Similar to selection sort, but uses bubbling rather than minimums.
+
Shellsort discussion
+
+ Source Code
+
+
+ Implementation
+
+ - Decide on a gap width. 3 is used here.
+ - Start at [3]. Compare to [0]. Swap if [0] > [3].
+ - Move to [4]. Compare to [1]. Swap if necessary.
+ - Move to [5]. Compare to [2]. Swap if necessary.
+ - Continue the pattern and bubble downstream, exactly like insertion sort but with a gap of 3, not 1.
+ - After the end of the list is reached, it is weakly sorted. Perform a final insertion sort.
+ - Note: Insertion sort is a shell sort with a gap of 1.
+
+
+
+
- several ways to pick gap width, but dependence on input data makes gap selection trivial.
- Insertion sort with gap of 1.
- source code link
+ Notes
+
+ - Weakly sorts elements to prepare for final pass using different sort algorithm
+ - Average performance depends on gap selection, but...
+ - Dependence on input data makes gap selection highly subjective
+
-
Bubble sort discussion
+
+ Source Code
+
+
+ Implementation
+
+ - Order [1] and [0].
+ - Order [2] and [1].
+ - Continue to the end. Note that there is at most one swap per index.
+ - Repeat the process until fully ordered. Keep a boolean that shows if swaps have been made.
+ - Once there is a pass without swaps, all elements have bubbled down to their proper positions.
+
+
+
- how is this different from insertion and selection sorts.
- talk about turtles and rabbits, because search loops from beginning each time. Every number out of place means a new pass must be done.
- source code link
+ Notes
+
+ - If even one number is out of place means a new pass must be done.
+ - "Turtles" are small values that crawl slowly toward their position near the front.
+ - "Rabbits" are large values that hop quickly to their position near the end.
+ - Variations on bubble sort (cocktail sort, comb sort) try to address the turtle problem.
+