Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the big-O of the shellsort() function provided in Figure? Briefly explai

ID: 3672330 • Letter: W

Question

What is the big-O of the shellsort() function provided in Figure? Briefly explain how you arrived at your answer. Remember big-O measures the worst case runtime scenario.

/**

*Shellsort, using Shell’s (poor) increments.

*/

template <typename Comparable>

void shellsort ( vector<Comparable> & a)

{

for ( int gap = a.size() / 2; gap > 0; gap /= 2)

                        for ( int i = gap; i < a.size(); ++i )

                        {

                                    Comparable tmp = std::move( a[ i] );

                                    int j = i;

                                    for ( ; j >= gap && tmp < a[ j – gap ]; j-= gap )

                                                a [ j ] = std:: move ( a [j – gap] );

                                    a [ j ] = std:: move (tmp);

                        }

}

Explanation / Answer

Shell Sort Time Complexity is For      Best Case we can say    O(n).

                                                       Average Case is O((n log (n))^2).                                   

Shell sort does less than O(n ^3/2) Comparisons for this increment sequence.

Worst case of Shell Sort in Time Complexity O((n log(n))^2).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote