48 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 | 
						|
<html>
 | 
						|
<head>
 | 
						|
<link rel="Stylesheet" type="text/css" href="style.css">
 | 
						|
<title>Shell Sort</title>
 | 
						|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 | 
						|
</head>
 | 
						|
<body>
 | 
						|
 | 
						|
<h2 id="toc_0.1">Shell Sort</h2>
 | 
						|
<dl>
 | 
						|
<dt>Stats</dt>
 | 
						|
<dd>Worst Case Performance: O(n<sup><small>2</small></sup>)</dd>
 | 
						|
<dd>Best Case Performance: O(n log n)</dd>
 | 
						|
<dd>Created in 1959 by Donald <strong>Shell</strong></dd>
 | 
						|
</dl>
 | 
						|
 | 
						|
<h3 id="toc_0.1.1">Psuedocode</h3>
 | 
						|
<pre>
 | 
						|
// This is the array to be sorted
 | 
						|
gaps = [701, 301, 132, 57, 23, 10, 4, 1]
 | 
						|
// Start with the largest gap and work down to a gap of 1
 | 
						|
foreach(gap in gaps) {
 | 
						|
  // Do a gapped insertion sort for this gap size.
 | 
						|
  // The first gap elements a[0..gap-1] are already in gapped order
 | 
						|
  // keep adding one more element until the entire array is gap sorted
 | 
						|
  for(i = gap; i < n; i += 1) {
 | 
						|
    // Add gaps[i] to the elements that have been gap sorted
 | 
						|
    // save gaps[i] in temp and make a hole at position i
 | 
						|
    temp = gaps[i]
 | 
						|
    // Shift earlier gap-sorted elements up until the correct location for gaps[i] is found
 | 
						|
    for(j = i; j >= gap and gaps[j - gap] > temp; j -= gap) {
 | 
						|
      gaps[j] = gaps[j - gap]
 | 
						|
    }
 | 
						|
    // Put temp (the original gaps[i]) in its correct location
 | 
						|
    gaps[j] = temp
 | 
						|
  }
 | 
						|
}
 | 
						|
</pre>
 | 
						|
 | 
						|
<h3 id="toc_0.1.2">Additional Info</h3>
 | 
						|
<p>
 | 
						|
Wikipedia Article: [<a href="http://en.wikipedia.org/wiki/Shell_sort]">http://en.wikipedia.org/wiki/Shell_sort]</a>
 | 
						|
</p>
 | 
						|
 | 
						|
</body>
 | 
						|
</html>
 |