title: shell sort sequence implementation in C++
body: <p>I am reading about shell sort in Algorithms in C++ by Robert Sedwick.</p>
  
  <p>Here outer loop to change the increments leads to this compact shellsort implementation, which uses the increment sequence 1 4 13 40 121 364 1093 3280 9841 . . . .</p>
  
  <pre><code>template &lt;class Item&gt;
  void shellsort(Item a[], int l, int r)
  {
      int h;
      for (h = 1; h &lt;= (r - l) / 9; h = 3 * h + 1);
      for (; h &gt; 0; h = h / 3)
      {
          for (int i = l + h; i &lt;= r; i++)
          {
              int j = i; Item v = a[i];
              while (j &gt;= l + h &amp;&amp; v &lt; a[j - h])
              {
                  a[j] = a[j - h]; j -= h;
              }
              a[j] = v;
          }
      }
  }
  </code></pre>
  
  <p>My question under what basis author is checking for condition h &lt;= (r-l)/9, and why author is dividing by 9.</p>