Write an algorithm that sorts a lists of \(n\) items by dividing it into three sublists of about \(n / 3\) items, sorting each sublist recursively and merging the three sorted sublists. Analyze your algorithm, and give the results under order notation.

Short Answer

Expert verified
The developed algorithm first divides the list into three sublists, sorts each using recursion, and then merges them. The analysis demonstrates that this three-way mergesort algorithm's time complexity is \(O(n*log(n))\) according to the Master's Theorem.

Step by step solution

01

Algorithm Design

Begin the designing of the algorithm. The algorithm should include splitting of the list into three equal parts, then recursively sort each part, and finally merge them back together. Here's a suggestion for the algorithm: 1. Check if length of list is less than or equal to 1, if so, the list is already sorted.2. Otherwise, divide the list into three roughly equal sublists.3. Sort each sublist by recursively applying this algorithm.4. Merge the three sorted sublists back into one.This is similar to merge sort, but with three sublists instead of two.
02

Algorithm Analysis

After designing the algorithm, it's time to perform an analysis of it with respect to time complexity.The time complexity T(n) of this three-way merge sort can be expressed with the recurrence relation T(n) = 3T(n / 3) + O(n). This is because the algorithm divides the problem into three sub-problems of size n / 3 (the three sublists), solves each in T(n / 3) time (recursively sorting the sublists), and then spends O(n) time to merge the sublists together.
03

Order Notation

To conclude the analysis, the results should be presented under order notation. According to the Master theorem, the solution to the recurrence T(n) = aT(n / b) + O(n^d) is T(n) = O(n^d * log^n) if a > b^d, T(n) = O(n^d) if a = b^d, and T(n) = O(n^(log_b a)) if a < b^d. Here, a = 3, b = 3, and d = 1, thus a = b^d. Therefore, by the Master theorem, this three-way merge sort algorithm has time complexity T(n) = O(n*log(n)).

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Write a nonrecursive algorithm for Quicksort (Algorithm 2.6). Analyze your algorithm, and give the results using order notation.

When a divide-and-conquer algorithm divides an instance of size \(n\) of a problem into subinstances each of size \(n / c,\) the recurrence relation is typically given by \\[\begin{array}{l}T(n)=a T\left(\frac{n}{c}\right)+g(n) \quad \text { for } n>1 \\ T(1)=d\end{array}\\] where \(g(n)\) is the cost of the dividing and combining processes, and \(d\) is a constant. Let \(n=c^{k}\) a. Show that \\[T\left(c^{k}\right)=d \times a^{k}+\sum_{j=1}^{k}\left[a^{k-j} \times g\left(c^{j}\right)\right]\\] b. Solve the recurrence relation given that \(g(n) \in \Theta(n)\)

Consider algorithm solve given below. This algorithm solves problem \(P\) by finding the output (solution) \(O\) corresponding to any input \(l\). void solve (input I, output& O) { if (size (I) == 1) find solution O directly; else{ partition I into 5 inputs I1, I2, I3, I4, I5, where size (Ij) = size (I)/3 for j = 1, ..., 5; for (j = 1; j < = 5; j++) solve (Ij, Oj); combine O1, O2, O3, O4, O5 to get O for P with input I; } } Assume \(g(n)\) basic operations for partitioning and combining and no basic operations for an instance of size 1 a. Write a recurrence equation \(T(n)\) for the number of basic operations needed to solve \(P\) when the input size is \(n\) b. What is the solution to this recurrence equation if \(g(n) \in \Theta(n) ?\) (Proof is not required.) c. Assuming that \(g(n)=n^{2}\), solve the recurrence equation exactly for \(n=27\) d. Find the general solution for \(n\) a power of 3

Use Mergesort (Algorithms 2.2 and 2.4 ) to sort the following list. Show the actions step by step. \(\begin{array}{llllllll}123 & 34 & 189 & 56 & 150 & 12 & 9 & 240\end{array}\)

Given the recurrence relation \\[\begin{array}{l} T(n)=7 T\left(\frac{n}{5}\right)+10 n \quad \text { for } n>1 \\\T(1)=1\end{array}\\] find \(T(625)\)

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free