Question

What is big-theta runtime of Merge sort and Quicksort on an almost sorted array? i.e. the...

What is big-theta runtime of Merge sort and Quicksort on an almost sorted array? i.e. the array is sorted except that two elements are swapped. Explain.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

******************************************************************************************
Please Upvote the answer as it matters to me a lot :)
*****************************************************************************************
As per HomeworkLib expert answering guidelines,Experts are supposed to answer only certain number of questions/sub-parts in a post.Please raise the remaining as a new question as per HomeworkLib guidelines.
******************************************************************************************

merge sort irrespective of the order of the elements performs the same complexity that is O(N log N) because it divides and conquers without seeing the elements

whereas in quicksort we choose the pivot , in case of almost sorted elements , it follows the following recurrence

T(n)= T(n-1)+ O(n)

if we solve the recurrence we get T(n)=O(n2)

Add a comment
Know the answer?
Add Answer to:
What is big-theta runtime of Merge sort and Quicksort on an almost sorted array? i.e. the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 6 6. Merge Bubble Sort: a) How does the merge bubble sort break the array into...

    6 6. Merge Bubble Sort: a) How does the merge bubble sort break the array into sublists? b) What does it need to use for each sublist and then what does it do with all of the sublists? c) What is the Big-O notation for this sort? 7. Merge Sort: a) How does the merge sort use recursion to break the array into sublists? b) What happens to each of these sublists to get the final sorted list? c) What...

  • 4. (15 points) Recall that in merge sort, we partitioned the array into two halves then...

    4. (15 points) Recall that in merge sort, we partitioned the array into two halves then recursively apply merge sort on those two halves. Suppose instead we partitioned the array into three parts. Write a threewayMergeSort(int list) that returns sorted version of list via apply merge sort on three partitions instead of two // ThreeWayMergeSort.java public class ThreeWayMergeSort f public int threewayMergeSort (int [] list) f (a) (10 points) Fill threewayMergeSort methood (b) (2 points) Write the runtime of threeway...

  • Consider a variation of Merge sort called 4-way Merge sort. Instead of splitting the array into...

    Consider a variation of Merge sort called 4-way Merge sort. Instead of splitting the array into two parts like Merge sort, 4-way Merge sort splits the array into four parts. 4-way Merge divides the input array into fourths, calls itself for each fourth and then merges the four sorted fourths. a) Give pseudocode for 4-way Merge sort. b) State a recurrence for the number of comparisons executed by 4-way Merge sort and solve to determine the asymptotic running time.

  • Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. E...

    Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. Execute the sort algorithms against the same list, recording information for the total number of comparisons and total execution time for each algorithm. Try several different lists, including at least one that is already in sorted order. ---------------------------------------------------------------------------------------------------------------- /** * Sorting demonstrates sorting and searching on an...

  • How do I create an almost sorted array with the size of 1,000 using numbers 1-10,000...

    How do I create an almost sorted array with the size of 1,000 using numbers 1-10,000 in JAVA. Almost sorted means the last two elements are swapped or every 10th element is random. For example my random array looks like this:                         int[] ranArr1000 = new int [1000];            for (int i = 0; i < ranArr1000.length; i++) {                ranArr1000[i] = (int)(Math.random() * 10000 + 1);            } Thanks

  • Given an array with n elements, after doing merge sort on the array, what is the...

    Given an array with n elements, after doing merge sort on the array, what is the time taken to conduct the merge sort (Choose one answer)? O(n) O ( n *n ) O(n log n)

  • HW58.1. Array Merge Sort You've done merge (on Lists), so now it's time to do merge...

    HW58.1. Array Merge Sort You've done merge (on Lists), so now it's time to do merge sort (on arrays). Create a public non-final class named Mergesort that extends Merge. Implement a public static method int[] mergesort(int[] values) that returns the input array of ints sorted in ascending order. You will want this method to be recursive, with the base case being an array with zero or one value. If the passed array is null you should return null. If the...

  • 11.3 0(N log,N) Sorts 11. A merge sort is used to sort an array of 1,000...

    11.3 0(N log,N) Sorts 11. A merge sort is used to sort an array of 1,000 test scores in descending order Which one of the following statements is true? a. The sort is fastest if the original test scores are sorted from smallest to largect b. The sort is fastest if the original test scores are in completely random order. The sort is fastest if the original test scores are sorted from largest to smallest c. The sort is the...

  • in Java Implement merging two sorted arrays into one sorted array. These arrays are sorted in...

    in Java Implement merging two sorted arrays into one sorted array. These arrays are sorted in descending order. For example [5, 4, 2]. Return an array with all the elements of these two arrays sorted, also in descending order. partb: if the two arrays as input are size n each. What is the big-O run time and space complexity of your implementation public int[] merge(int[] arr1, int[] arr2){

  • Sort 3, 5, 2, 1, 5, 9, 4, 7, 6, 3 using Quicksort with median-of-three partitioning....

    Sort 3, 5, 2, 1, 5, 9, 4, 7, 6, 3 using Quicksort with median-of-three partitioning. Assume a cutoff of 3, i.e. once a partition size reaches 3, the elements are sorted by explicit comparison. You do not have to show each step of the i and j pointers, but clearly indicate which elements are swapped in each step. Assume that the three candidate elements are not pre-sorted when selecting the pivot, but that the pivot is moved to the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT