Improved lower bounds of the time complexity of shellsort


Abstract

In this paper we develop the framework of using a parametrized mapping \([\sigma(1), \sigma(2), \cdots, \sigma(n)] \mapsto \sigma(1)z + \sigma(2)z^2 + \cdots \sigma(n)z^n\) to perform runtime analysis on Shellsort. In particular, we show that the worst-case time complexity of Shellsort using Tokuda’s sequence [1] is at least \(\Omega(N^{1.26})\) with a generalisation of this result to any strictly decreasing gap sequence where each term at most a fixed distance away from a rational geometric sequence, and we also show that strictly decreasing gap sequences giving worst-case Shellsort time complexities of \(O(N \log^c N)\) must have \(\Omega(\log N / \log \log N)\) terms of order \(\Omega(N / (\log \log N)^c)\).

1 Introduction↩︎

Since its introduction by Shell in [2], the time complexity of Shellsort has been a long standing problem in computer science. For the past few decades, many of the most important works on the runtime analysis of Shellsort have been done using combinatorial and number theoretic methods. In [3], Pratt showed that Shellsort using any gap sequence which approximates a geometric progression with integer coefficients has worst case time \(\Omega(N^{3/2})\) as well as constructing a famous gap sequence consisting of numbers of the form \(2^p3^q\) which gives both worst case and average time of \(\Theta(N (\log N)^2)\), yet this sequence is seldomly used in practical implementations due to its inefficiency to compute which comes from its high gap density. In [4], it is proven that Shellsort using any static gap sequence has worst case time at least \(\Omega(N(\log N /\log \log N)^2)\), a bound which has been later improved to \(\Omega(N(\log N )^2/\log \log N)\). For many years, studying the Frobenius coin problem or some variant of it have been the standard approach when it comes to runtime analysis of Shellsort.

However, research based on this seems to have reached a bottleneck in recent years due to the computational intractability of the solutions to the Frobenius problem when given large sets of arguments and also that it isn’t a good enough representation of Shellsort. Since then the focus of researches on Shellsort has shifted to empirically looking for gap sequences that perform well in practical scenarios, with sequences being proposed such as Tokuda’s sequence introduced in [1] which consists of numbers of the form \(\lfloor (9\cdot (9/4)^k-4)/5\rfloor\). However, no version of Shellsort using one of these emperically derived gap sequences has any known individually proven nontrivial lower/upper bound.

We now introduce a new mechanism to perform runtime analysis on Shellsort which uses a parameterized mapping that takes a permutation \(\sigma\) of the numbers \(1, 2, \cdots, N\) and returns an expression about a complex variable \(z\) (see definition 2, section 1.1). Our focus is the effects the swaps performed when running Shellsort have on the value of this potential function, by viewing each swap as an operation taking one permutation to another. This approach bypasses many of the issues faced by Frobenius-based approaches. We begin by making the following definitions.

1.1 Notations↩︎

In this paper, denote by \(N\) any positive integer greater than \(1\) and we assume that we perform Shellsort on an array of size \(N\) which contains each of \(1, 2, \cdots, N\) exactly once. When given \(N\), denote \(L\) a (strictly) decreasing gap sequence with the first term less than \(N\) and \(\sigma\) a permutation of \(1, 2, \cdots, N\), and let \(id\) be the identity permutation where \(id(i) = i\) for all \(1 \leq i \leq N\). Also for a real number \(r\), denote by \(||r||\) the distance from \(r\) to the nearest integer.

Definition 1. We define \(T(N, \sigma, L)\) as the number of swaps needed to sort the array \([\sigma(1), \sigma(2), \cdots, \sigma(N)]\) using shellsort with gap sequence \(L\).

Definition 2. For any complex number \(z\), we define the potential of the permutation \(\sigma\) with respect to \(z\) as the polynomial \[\begin{align} p(N, \sigma, z) = \sum_{i=1}^N \sigma(i)z^i \end{align}\]

Definition 3. We call an operation defined on any permutation \(\sigma\) a swap if it returns another permutation \(\sigma'\) that is the same as \(\sigma\) except having \(\sigma'(i) = \sigma(j), \sigma'(j) = \sigma(i)\) for some \(1 \leq i < j \leq N\). Denote this operator as \(S_{i,j}\) and denote the distance of a swap as \(dist(S_{i,j}) = j - i\).

Definition 4. For any \(1 \leq x \leq N\), denote \(l(x,N)\) as the number of terms \(s\) in \(L\) satisfying \(x \leq s < N\).

2 Main Results↩︎

We begin with the following theorem which constitutes the core idea of this paper.

Theorem 1. For any \(N\), a strictly decreasing gap sequence \(L\) and any real numbers \(r, x_0 > 0, \alpha \geq 0\), which satisfies that for any \(s\) in \(L\) with \(s \geq x_0\) we have \(||sr|| \leq \alpha\) (Here we use \(||x||\) to denote the distance from \(x\) to its nearest integer), then for any permutation \(\sigma\) of \(1, 2, \cdots, N\) we have \[\begin{align} T(N, \sigma, L) \geq \frac{|p(N, \sigma, z) - p(N, id, z)|}{2(x_0 + \pi \alpha N)} \end{align}\] where \(z = \exp (2\pi ir)\).

Proof. In fact we will prove a stronger result: let \(S_{i_1, j_1}, S_{i_2, j_2}, \cdots, S_{i_t,j_t}\) be a sequence of swaps of minimum length such that \((S_{i_t, j_t} \circ \cdots \circ S_{i_2, j_2} \circ S_{i_1, j_1})(\sigma) = id\), where the distance of the swaps \(j_k - i_k\) is non-increasing and all these distances belong to the gap sequence \(L\), then denoting this \(t\) by \(t(N, \sigma, L)\) (we’ll from now on write \(t\) for short) the same bound in (1) holds with \(T(N, \sigma, L)\) replaced by \(t\). Note that since the sequence of swaps being carried out when running shellsort can be written as such a sequence (though of not necessarily the minimum length) we must have \(T(N, \sigma, L) \geq t\), so proving this result would directly imply the theorem above.

Let \(u\) be the largest number such that \(j_u - i_u > x_0\) and let \(\omega = (S_{i_u, j_u} \circ \cdots \circ S_{i_2, j_2} \circ S_{i_1, j_1})(\sigma)\). We begin by noting that for any complex number \(z\) we have \(|p(N, \sigma, z) - p(N, id, z)| \leq |p(N, \omega, z) - p(N, id, z)| + |p(N, \sigma, z) - p(N, \omega, z)|\).

Bounding the first difference is easy: just note that whenever \(|z| = 1\) (which is the case for the \(z\) we have defined): \[\begin{align} \begin{aligned} |p(N, \omega, z) - p(N, id, z)| & = |\sum_{i=1}^N \omega(i)z^i - \sum_{i=1}^N iz^i| \\ & = |\sum_{i=1}^N (\omega(i) - i)z^i| \\ & \leq \sum_{i=1}^N|\omega(i) - i| \\ & \leq 2tx_0 \end{aligned} \end{align}\] the last inequality holds since the sum of the changes in positions of each \(i\) going from \([1, 2, \cdots, N]\) to \([\omega(1), \omega(2), \cdots, \omega(N)]\) is at most \(2(t-u)x_0 \leq 2tx_0\).

Now note that for any \(|z| = 1\) we have \(|z - 1| = 2|\sin (\pi ||\arg (z)/(2\pi)||)|\). Now since the distance from any real number to its nearest integer is between \(0\) and \(1/2\) it can be verified that \(|z - 1|/||\arg (z)/(2\pi)|| =2|\sin (\pi ||\arg (z)/(2\pi)||)|/||\arg (z)/(2\pi)||\) lies bet en \(4\) and \(2\pi\). This therefore gives \(|z -1| \leq 2\pi||\arg (z)/(2\pi)||\) for all unit complex numbers \(z\). Now setting \(z = \exp (2\pi i r)\), since for any \(s\) in \(L\) with \(s \geq x_0\) we have \(|z^s - 1| \leq 2\pi ||sr|| \leq 2\pi \alpha\).

Using this \(z\) we can now bound \(|p(N, \sigma, z) - p(N, \omega, z)|\). Note that for any permutation \(\sigma'\) and a swap \(S_{k,k+s}\) of distance \(s\) where \(s \in L, x_0 \leq s < N\) we have \[\begin{align} \begin{aligned} |p(N, S_{k,k+s}(\sigma'), z) - p(N, \sigma', z)| & = |\sum_{i=1}^N (S_{k,k+s}(\sigma')(i) - \sigma'(i))z^i| \\ &= |\sigma'(k)z^{k+s}+\sigma'(k+s)z^k - \sigma'(k)z^k - \sigma'(k+s)z^{k+s}| \\ &= |\sigma'(k) - \sigma'(k+s)||z^s - 1| \\ &< 2\pi \alpha N \end{aligned} \end{align}\]

Therefore as \(\omega = (S_{i_u, j_u} \circ \cdots \circ S_{i_2, j_2} \circ S_{i_1, j_1})(\sigma)\), since for every \(1 \leq v \leq u\) we have \(j_v - i_v \in L, x_0 \leq j_v-i_v \leq N\), this means that \[\begin{align} \begin{aligned} |p(N, \sigma, z) - p(N, \omega, z)| &= |\sum_{v=1}^u (p(N, (S_{i_v, j_v}\circ \cdots \circ S_{i_1, j_1}) (\sigma), z) - p(N, (S_{i_{v-1}, j_{v-1}}\circ \cdots \circ S_{i_1, j_1}) (\sigma), z))| \\ &\leq \sum_{v=1}^u |p(N, (S_{i_v, j_v}\circ \cdots \circ S_{i_1, j_1}) (\sigma), z) - p(N, (S_{i_{v-1}, j_{v-1}}\circ \cdots \circ S_{i_1, j_1}) (\sigma), z)| \\ &\leq 2u\pi \alpha N \\ & \leq 2t \pi \alpha N \end{aligned} \end{align}\]

Combining the bounds we’ve obtained so far gives \[\begin{align} \begin{aligned} |p(N, \sigma, z) - p(N, id, z)| &\leq |p(N, \omega, z) - p(N, id, z)| + |p(N, \sigma, z) - p(N, \omega, z)| \\ &\leq 2tx_0 + 2t \pi \alpha N \\ &= 2t(x_0 + \pi \alpha N) \end{aligned} \end{align}\]

So for any permutation \(\sigma\) of \(1, 2, \cdots, N\), \[\begin{align} t(N, \sigma, L) \geq \frac{|p(N, \sigma, z) - p(N, id, z)|}{2(x_0 + \pi \alpha N)} \end{align}\] and the theorem follows. (Note: equality of (1) may be achieved iff \(\sigma = id\).) ◻

Note that the above result can be viewed as in a sense a generalisation of theorem 2.11 in Pratt’s paper [3]. To see this we’ll first prove a following lemma.

Lemma 1. There exists an absolute constant \(c_0 > 0\) such that for any \(n\) unit complex numbers \(z_1, z_2, \cdots, z_n\), there exists a permutation \(\omega\) of \(1, 2, \cdots, n\) such that \(|\omega(1)z_1+\omega(2)z_2+\cdots +\omega(n)z_n| \geq c_0n^2\).

(Note: in fact only a much weaker and far more obvious version of this lemma is required for all later works in this paper, that is the special case of having \(z_i = z_0^i\) for some unit complex number \(z_0\) for \(i = 1, 2, \cdots, n\))

Proof. Consider a quarter sector of the unit complex circle which contains the maximum amount of points among \(z_1, \cdots, z_n\). Assume without loss of generality that this is the sector which can be bisected by the zero radian line and say that it contains \(\lambda n\) of the points where \(\lambda \geq 1/4\). So if we consider the sector which can be bisected by the \(\pi\)-radian line which corresponds to the angle \(2\theta\) then we get that this sector contains at most \((4\theta/\pi)\lambda n\) of the points (where \(\theta \geq \pi/4\)). So assuming that \(z_1, ... z_n\) are already ordered in terms of increasing real parts then for every \(i > \lambda n\) we’d have \(\mathfrak{R}(z_i) \geq -\cos (i\pi/(4\lambda n))\). If \(\lambda \leq 1/2\) we therefore have: \[\begin{align} &\mathfrak{R}(z_1+2z_2+\cdots+nz_n)\\ &\geq -(1+2+\cdots+\lambda n) - \sum_{i = \lambda n+1}^{(1-\lambda )n} i \cos (i\pi/(4\lambda n)) + (\sqrt2/2)((1-\lambda)n+1 + \cdots + n) \\ & = \frac{2\sqrt{2}\lambda - (2+\sqrt{2})\lambda^2}{4}n^2- \int_{\lambda n}^{(1-\lambda)n}x \cos (x\pi/(4\lambda n))dx + O(n) \\ & = \frac{2\sqrt{2}\lambda - (2+\sqrt{2})\lambda^2}{4}n^2- (4\lambda n/\pi)((1-\lambda)n \cos ((1-\lambda)\pi/(4\lambda)) - \lambda n (\sqrt{2}/2)) + O(n)\\ & = (\frac{2\sqrt{2}\lambda - (2+\sqrt{2})\lambda^2}{4} - 4\lambda (1-\lambda)\cos ((1-\lambda)\pi/(4\lambda))/\pi + 2\sqrt{2} \lambda^2/\pi)n^2 + O(n) > 0.1n^2 \end{align}\]

and if \(\lambda > 1/2\): \[\begin{align} \mathfrak{R}(z_1+2z_2 + \cdots + nz_n) \geq -(1 + 2 + \cdots + n/2) + (\sqrt{2}/2)(n/2 + 1 + \cdots + n) = (3\sqrt{2}/16-1/8)n^2 + O(n) \end{align}\] and the lemma follows. ◻

Note what this implies is that as long as \(||\arg (z)/(2\pi)|| \geq 1/N\) then there is a permutation \(\sigma\) of \(1, \cdots, N\) such that \(|p(N, \sigma, z) - p(N, id, z)| \geq C_0N^2\) for some universal constant \(C_0\) that is independent of \(N\). To see this, if \(|p(N, id, z)| > c_0N^2/2\) (where \(c_0\) same as defined in lemma 1) then as for such a \(|z|\) there must exist a number \(1 \leq M \leq N\) with \(|z^M - z| \geq 1/2\), just letting \(\sigma\) be a cyclic shift by \(M\) positions gives \(|p(N, \sigma, z) - p(N, id, z)| > c_0N^2/4\). And if \(|p(N, \sigma, z)| \leq c_0N^2/2\) then letting \(\sigma = \omega\) where \(\omega\) is the same as defined in lemma 1 gives \(|p(N, \sigma, z) - p(N, id, z)| \geq c_0N^2/4\). So letting \(C_0 = c_0/4\) works.

Combining this with theorem 1 and lemma 1 gives:

Corollary 1. There’s an universal constant \(C_0 > 0\) such that for any \(N > 1\), a strictly decreasing gap sequence \(L\) and any real numbers \(r, ||r|| \geq 1/N, x_0 > 0, \alpha \geq 0\), which satisfies that for any \(s\) in \(L\) with \(l \geq x_0\) we have \(||sr|| \leq \alpha\), then there exists a permutation \(\sigma\) of \(1, 2, \cdots, N\) where \[\begin{align} T(N, \sigma, L) \geq \frac{C_0N^2}{2(x_0 + \pi \alpha N)} \end{align}\]

From this corollary we obtain that:

Theorem 2. For any reals \(0 < \lambda_1 < \lambda_2, \mu > 0,0 < \nu, \eta < 1\) there exists a positive constant \(C(\lambda_1, \lambda_2, \mu) > 0\) depending only on \(\lambda_1, \lambda_2\) and \(\mu\) such that for any large enough \(N\) and a strictly decreasing gap sequence \(L\), if there exists a real number \(\lambda_1N^\nu \leq r' \leq \lambda_2N^\nu\) and a non-negative \(d \geq 0\) such that for any \(s \geq \mu N^{1-\eta}\) in \(L\) there exists an integer \(s'\) such that \(|s - s'r'| \leq d\), then there is a permutation \(\sigma\) of \(1, 2, \cdots, N\) such that \[\begin{align} T(N, \sigma, L) > \frac{C(\lambda_1, \lambda_2, \mu)}{d}N^{1+\min (\nu, \eta)} \end{align}\] In particular, when \(\nu = \eta = 1/2\) we have \[\begin{align} T(N, \sigma, L) > \frac{C(\lambda_1, \lambda_2, \mu)}{d}N^{3/2} \end{align}\]

Proof. This is trivial by corollary 1: just set \(x_0 = \mu N^{1 - \eta}, r = 1/r', \alpha = d/r'\) in (2) and that’s it. ◻

Note that (4) is in a certain sense stronger than theorem 2.11 of [3] in that the conditions don’t actually require the existence of a term in \(L\) of order \(\sqrt{N}\), nor does it assert any preconditions on the terms in \(L\) less than \(r\). On the other hand for \(T(N, \sigma, L)\) to be of order of at least \(N^{3/2}\) we require \(d\) to be bounded by some constants, while in theorem 2.11 in [3] this is more lenient. In particular, (4) shows that any gap sequence whose terms are of at most a fixed constant away from some geometric progression with integer common ratio must be a worst case time of order at least \(N^{3/2}\).

With corollary 1 we may in fact also deal with gap sequences which approximate a geometric progression with a noninteger rational common ratio such as Tokuda’s gap sequence [1]. In particular:

Theorem 3. Suppose that \(a>b>1\) are coprime integers and \(q,d > 0\) be any fixed rationals. For each \(N\) let \(L_N\) be a decreasing gap sequence such that for any \(s\) in \(L_N\), there exists an integer \(n\) such that \(|s - q(a/b)^n| < d\), then \[\begin{align} \max_{\sigma} T(N,\sigma, L_N) = \Omega(N^{1+\frac{\log_ba-1}{2\log_ba-1}}) \end{align}\]

Proof. Let \(q = q_1/q_2\) where \(q_1, q_2\) are coprime. Let \(n_0\) be the largest integer such that \(q(a/b)^{n_0} - d < N\). Consider \(r = b^{n_0}q_2/a^m\) where \(m\) is an integer to be determined. Now if \(q(a/b)^n - d < s < q(a/b)^n + d\), then \(q_1a^{n-m}b^{n_0-n} - dr < sr < q_1a^{n-m}b^{n_0-n} + dr\). So whenever \(n_0 \geq n \geq m\) (meaning that \(s \geq q(a/b)^m + d\)) we’d have \(||sr|| < dr < dq_2b^{n_0}/a^m = \alpha\) and let \(x_0 = q(a/b)^m+d\). Now just note that \(x_0 + 2\pi\alpha N < 2\pi(x_0+\alpha N) = O_{q,d}((a/b)^m+N(b^{n_0}/a^m))\). To make this small consider when \(a^{m_0}/b^{m_0} = Nb^{n_0}/a^{m_0}\). Letting \(a = b^{\gamma}\), then this rearranges to \(b^{m_0(2\gamma - 1) - n_0} = N\), or \(m_0 = (\log _bN + n_0)/(2\gamma -1)\). Setting \(m = \lfloor m_0 \rfloor\) gives \((a/b)^m+N(b^{n_0}/a^m) = O_{a,b,q}(N^{\gamma/(2\gamma -1)})\). Now note that \(1/N < r\) but also \(r = \Theta(N^{(1-\gamma)/(2\gamma-1)})\) when \(N\) is large. So by corollary 1 we have for the worst case time, \(\max_{\sigma} T(N,\sigma, L_N) = \Omega(N^{2 - \gamma/(2\gamma -1)}) = \Omega(N^{(3\gamma - 2)/(2\gamma-1)})\), and we’re done. ◻

If we apply this to Tokuda’s sequence, we see that it has a worst case time of at least \(\Omega(N^{1.2695...})\). Also note an interesting phenomenon: if we set \(b = 1\), then \(\log_ba = +\infty\) and that gives \(\max T = \Omega (N^{3/2})\) which matches what we got in theorem 2.

Now, we want to bound the sizes of \(x_0, \alpha\) in theorem 1 such that a corresponding \(r\) that’s not too close to an integer is guaranteed to exist.

Theorem 4. There exist some constants \(c > 0\) such that, for any given \(N > 4\), strictly decreasing gap sequence \(L\), and for any \(1 \leq x < N\) where \(l(x, N) \geq 1\), there exists a complex number \(z\) satisfying \(z^N = 1\) and \(|1 - z| \geq cN^{-1/2}\) for some universal positive constant \(c\) such that \[\begin{align} T(N, \sigma, L) \geq \frac{1}{4\pi} \cdot \frac{|p(N, \sigma, z) - p(N, id, z)|}{x + N^{1-\frac{1}{2l(x,N)}}} \end{align}\] for any permutation \(\sigma\) of \(1, 2, \cdots, N\).

Proof. We first need a stronger version of Dirichlet’s theorem on Diophantine approximation.

Lemma 2. Let \(a_1, \cdots, a_m\) be integers satisfying \(1 \leq a_i \leq N\). For any positive integers \(Q\), \(M\), if \(2MQ^m \leq N\), then there exists some real number \(r\) satisfying \(||r|| \geq M/N\) such that \(Nr\) is an integer, \(||a_ir||\leq 1/Q\) for all \(1 \leq i \leq m\).

Proof. We work in \(m\) dimensions. Consider the points \[\begin{align} v_k = \Big(\Big\{\frac{ka_1}{N}\Big\}, \cdots, \Big\{\frac{ka_m}{N}\Big\} \Big) \end{align}\] where \(k = 0, 1, \cdots, MQ^m\). Here \(\{\cdot \}\) represents the fractional part.

Split \([0, 1)^m\) into \(Q^m\) identical small \(m\)-dimensional hypercubes, each of side length \(1/Q\). Since there are \(MQ^m+1\) such points \(v_k\), by the pigeonhole principle, there must be some small hypercube of side length \(1/Q\) which contains at least \(M+1\) of the \(v_k\)’s. We may therefore pick numbers \(k, k'\), where \(k > k'\), \(v_k, v_{k'}\) lie in the same small hypercube and \(q = k - k' \geq M\). This means that for every \(i\) we’d have \[\begin{align} \Big|\Big|\frac{qa_i}{N}\Big|\Big| \leq \Big|\Big\{\frac{ka_i}{N}\Big\} - \Big\{\frac{k'a_i}{N}\Big\} \Big| \leq \frac{1}{Q} \end{align}\]

Let \(r = q/N\). We then have that \(Nr = q \in \mathbb{Z}, ||a_ir|| = ||qa_i/N|| \leq 1/Q\) for all \(1 \leq i \leq m\). Now as \(q \geq M\) we have \(r = q/N \geq M/N\). Since \(q \leq MQ^m \leq N/2\), so \(r \in [0, 1/2]\), and therefore \(||r|| = r \geq M/N\). ◻

Now fix a random \(1 \leq x < N\) where \(l(x, N) \geq 1\). In the above lemma, we let \(m = l(x, N), Q=\lfloor N^{\frac{1}{2l(x,N)}} \rfloor > \frac{N^{\frac{1}{2l(x,N)}}}{2}, M = \lfloor \frac{N}{2Q^m} \rfloor \geq \lfloor \sqrt{N}/2 \rfloor > \frac{\sqrt{N}}{4}\) since \(N > 4\). This therefore gives that there is a real number \(r\) with \(Nr \in \mathbb{Z}\) such that for any \(s \in L\) where \(x \leq s < N\) we have \(||sr|| < 2N^{-\frac{1}{2l(x,N)}}\), while \(||r|| > N^{-1/2}/4\). Now let \(z = \exp({2\pi ir})\). This gives \(z^N = 1, |z - 1| > cN^{-1/2}\) for some fixed universal constant \(c >0\).

So letting \(x_0 = x, \alpha = 2N^{-\frac{1}{2l(x,N)}}\), by theorem 1 we have for our chosen \(z\), that \(|z| = 1, |z - 1| > cN^{-1/2}\), and for any permutation \(\sigma\) of \(1, 2, \cdots, N\), \[\begin{align} t(N, \sigma, L) \geq C \cdot \frac{|p(N, \sigma, z) - p(N, id, z)|}{x + N^{1-\frac{1}{2l(x,N)}}} \end{align}\] and the theorem follows. ◻

We may reformulate the theorem in the following manner:

Corollary 2. There exists some constants \(c > 0\) such that, for any given \(N > 4\), a strictly decreasing gap sequence \(L = (l_1, l_2, \cdots, l_k)\) with \(l_1 < N, l_k = 1\), there exists a complex number \(z\) satisfying \(z^N = 1\) and \(|z - 1| > cN^{-1/2}\) such that for any permutation \(\sigma\) of \(1, 2, \cdots, N\) we have \[\begin{align} T(N, \sigma, L) \geq \frac{1}{4\pi} \cdot \frac{|p(N, \sigma, z) - p(N, id, z)|}{\min_{1 \leq s \leq k-1}(l_{s+1} + N^{1-\frac{1}{2s}})} \end{align}\]

The proof of this follows directly from theorem 4. Combining this with corollary 1 gives:

Theorem 5. There exists some universal constant \(C_1 > 0\) such that, for any given large \(N\), a strictly decreasing gap sequence \(L = (l_1, l_2, \cdots, l_k)\) with \(l_1 < N, l_k = 1\), there exists a permutation \(\sigma\) of \(1, 2, \cdots, N\), such that \[\begin{align} T(N, \sigma, L) > \frac{C_1N^2}{\min_{1 \leq s \leq k-1}(l_{s+1} + N^{1-\frac{1}{2s}})} \end{align}\]

Finally, we give a requirement for a gap sequence to be able to achieve a worst-case time of \(N\) times a polynomial of \(\log N\):

Theorem 6. Let \(L_1, L_2, \cdots, L_n, \cdots\) be a sequence of strictly decreasing gap sequences where \(L_i\) begins with at most \(i\) for every \(i \geq 1\). Denote the \(j\)th term of \(L_i\) as \(l_{i, j}\). If the worst case time of running shellsort on any array of length \(N\) using \(L_N\) is \(O(N(\log N)^\mu)\) (where \(\mu \geq 1\) is any fixed positive real number) as \(N\) goes to infinity, then for any fixed \(\epsilon > 0\) and letting \(s_N = \lfloor \log N/((2\mu+\epsilon)\log \log N) \rfloor\) we must have \(l_{N, s_N} = \Omega(N/(\log \log N)^\mu)\) as \(N\) goes to infinity, where the implied constant is independent of the choice of \(\epsilon\) (i.e. only depending on the choice of the \(L_n\)’s).

Proof. Consider the denominator in (8) with \(L = L_N\) given by \(\min_{1 \leq s \leq k-1}(l_{N, s+1} + N^{1-\frac{1}{2s}})\) where \(k\) is the length of \(L_N\). We want this number to be at least \(DN/(\log N)^\mu\) for some constants \(D,\mu > 0\). Fix \(\epsilon > 0\), take \(s = s_N - 1\). This gives \(l_{N,s_N} + N/(\log N)^{\mu + \epsilon/2} \geq DN/(\log N)^\mu\), so \(l_{N, S_N} \geq (D - o(1))N/(\log N)^\mu\), and we’re done. ◻

3 Acknowledgments↩︎

The author would like to thank OpenAI’s ChatGPT for providing the initial frameworks of the proof to lemma 2, which has been subsequently verified, refined and written by the author.

The author would also like to thank Professor Stefan Kiefer at St John’s College, the University of Oxford for his insightful feedbacks and advices on an earlier draft of this paper.

References↩︎

[1]
Tokuda, Naoyuki. “An Improved Shellsort.” IFIP Congress (1992).
[2]
Shell D L. A high-speed sorting procedure. Communications of the ACM, 1959, 2(7): 30-32.
[3]
Pratt V R. Shellsort and sorting networks. 1972.
[4]
C.Greg Plaxton, Torsten Suel, Lower Bounds for Shellsort, Journal of Algorithms, Volume 23, Issue 2, 1997, Pages 221-240, ISSN 0196-6774, https://doi.org/10.1006/jagm.1996.0825.