Yet another sorting algorithm

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def floor(n):
    """Compute the floor function of n"""
    return int(n)


def stoogy(A, i, j):
    """Sort A[i...j]"""
    if A[i] > A[j]:
        A[i] , A[j] = A[j] , A[i] #Swap A[i] and A[j]
    if i + 1 >= j:
        return
    m = floor( (j - i + 1) / 3)
    stoogy(A, i, j - m)
    stoogy(A, i+m, j)
    stoogy(A, i, j - m)


def sort(A):
    """Sort the list A[0..n]"""
    stoogy(A, 0, len(A) - 1)

The tight asymptotic bound of ( Θ \Theta - notation) of the sorting algorithm above( sort(A) ) can be expressed as Θ ( n α ) \Theta(n^{\alpha}) ( α R \alpha \in \mathbb{R} ). Find α \alpha .

Details and Assumptions

  • n n is the size of the array to be sorted.


The answer is 2.71.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Note that the time complexity T ( n ) T(n) follows the following recurrence:

T ( n ) = 3 T ( 2 n 3 ) + Θ ( 1 ) T(n) = 3T \left( \frac{2n}{3} \right) + \Theta(1)

We now use the master theorem to conclude that T ( n ) Θ ( n log 3 2 3 ) α = log 3 2 3 2.71 T(n) \in \Theta\left (n^{\log_{\frac{3}{2}}3 } \right)\\\implies \alpha = \log_{\frac{3}{2}}3 \approx 2.71

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...