Question

In: Computer Science

Explain what happens in the Lomuto partition when there is a lot of the same elements...

Explain what happens in the Lomuto partition when there is a lot of the same elements in the input and justify the consequences it has for the time complexity of Quicksort.

Solutions

Expert Solution

Lomuto’s Partition Scheme

This scheme chooses a pivot that is typically the last element in the array. The algorithm maintains index i as it scans the array using another index j such that the elements lo through i (inclusive) are less than or equal to the pivot, and the elements i+1 through j-1 (inclusive) are greater than the pivot. As this scheme is more compact and easy to understand, it is frequently used in introductory material, although it is less efficient than Hoare's original scheme. This scheme degrades to O(n2) when the array is already in order.[10] There have been various variants proposed to boost performance including various ways to select pivot, deal with equal elements, use other sorting algorithms such as Insertion sort for small arrays and so on. In pseudocode, a quicksort that sorts elements lo through hi (inclusive) of an array A can be expressed as:

algorithm quicksort(A, lo, hi) is
    if lo < hi then
        p := partition(A, lo, hi)
        quicksort(A, lo, p - 1)
        quicksort(A, p + 1, hi)

algorithm partition(A, lo, hi) is
    pivot := A[hi]
    i := lo
    for j := lo to hi - 1 do
        if A[j] < pivot then
            swap A[i] with A[j]
            i := i + 1
    swap A[i] with A[hi]
    return i

Sorting the entire array is accomplished by quicksort(A, 0, length(A) - 1).

Consequences of Lomuto's algorithm

When all the elements of the array are same, then Lomuto's algorithm will result in n2 comparisons and hence, the complexity of quick sort will become O(n2)


Related Solutions

What happens when the signs of the function in IVT are the same? Is it true...
What happens when the signs of the function in IVT are the same? Is it true that they don’t have any roots? Show an example
8- Explain what happens to the number of elements in a line segment if we reduce...
8- Explain what happens to the number of elements in a line segment if we reduce the length of a ruler by a factor? 9- Explain what makes a fractal self-similar. 10- Explain what it means to have a fractal dimension between 1 and 2. # Could you please answer all questions, if you know only one question please do not answer it. I'm saying it because I don't have enough chances to ask again. Thank you for your hard...
Address the following and Explain: a) what happens when a strong base is added to a...
Address the following and Explain: a) what happens when a strong base is added to a solution that only has significant amounts of a weak base b) what happens when a strong base is added to a solution initially made up of significant amounts of a weak base and its conjugate acid
Explain what happens to Na+ concentration in the nephron when GFR increases.
Explain what happens to Na+ concentration in the nephron when GFR increases.
What happens to the production function when there is a technological improvement? Why? Explain. 2. What...
What happens to the production function when there is a technological improvement? Why? Explain. 2. What ceteris paribus assumptions are you making when answering question 1? List all your assumptions. 3. Pick an example to analyze the overall effects of a technological improvement. Here is an example on what I am looking here: https://www.economist.com/news/leaders/21737501-policymakers-must-apply-lessons-horseless-carriage-driverless-car-self-driving
Developing standards is problematic for a lot of companies. What happens if standards are set too...
Developing standards is problematic for a lot of companies. What happens if standards are set too high or too low? Have you ever been in a situation where you felt the standards you were being held to were not “fair”? From your research, did you find examples where adhering to strict standards resulted in any unintended consequences??
1. Explain what are the elements of the auditor’s report - Explain what are the elements...
1. Explain what are the elements of the auditor’s report - Explain what are the elements of the formal auditor report? - What is the relevance of the different elements of the auditors report? 2. The auditor’s responsibility - How is the auditor's responsibilities addressed in the auditors report? - Do you think that the elements of the report adequately address the rights and responsibilities of the auditors and the stakeholders using the report, or is there any suggestion for...
Explain when political failure of an embargo happens
Explain when political failure of an embargo happens
explain the theory of partition coefficient
explain the theory of partition coefficient
Show what happens when the symmetry is not imposed in FIR filters. what happens to the...
Show what happens when the symmetry is not imposed in FIR filters. what happens to the linear phase?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT