Question

In: Computer Science

Show that the worst-case and average-case time complexities for the number of assignments of records performed...

Show that the worst-case and average-case time complexities for the number of assignments of records performed by the Exchange Sort algorithm (Algorithm 1.3) are given by

          W(n) = 3n(n-1)/2 ≈ n2/2 and A(n) = 3n(n-1)/4 ≈ n2/4

Solutions

Expert Solution

Let us define what is a worst-case and average-case scenario for a sorting algorithm, Worst case is defined as an array which is reversely sorted. The average case is, in general, between the worst case and best case i.e takes at least half the time of the worst-case scenario.

An exchange sort algorithm compares each element with all other elements starting from the first element and swaps if the latter element is lesser than the former. So for a worst-case scenario, the first element is compared with n-1 elements, the second element is compared with n-2 elements and so on. The second last element is compared just with the last element.

Hence number of comparisons = (n-1) + (n-2) + (n-3)......+(n-(n-1)) + (n-n)

There are n terms in the above equation. This can be simplifies as:

Number of comparisons = n*n + (1+2+3+....n)

Second term is arithmetic series 1+2+3.... +n= n(n+1)/2 = (n^2 +n)/2

Therefore, number of comparisons = n^2 + (n^2 + n)/2 = (3n^2 +n)/2 = (3n^2 -3n +2n)/2 = 3n(n-1)/2 + n

Hence worst case time complexity = 3n(n-1)/2 ~ n^2/2

Average case complexity takes around half the time as worst case complexity i.e 3n(n-1)/4 ~ n^2/4


Related Solutions

Show that the worst-case number of entries computed by the refined dynamic programming algorithm for the...
Show that the worst-case number of entries computed by the refined dynamic programming algorithm for the 0-1 Knapsack problem is in Ω(2n). Do this by considering the instance in which W = 2n −2 and wi = 2i−1 for 1 ≤ i ≤ n. Please answer with clear explanations!!! Excerpt From: Richard Neapolitan. “Foundations of Algorithms.”
Analyze the worst-case, best-case, and average-case number of comparisons of sequential search if exactly three-tenths of...
Analyze the worst-case, best-case, and average-case number of comparisons of sequential search if exactly three-tenths of the time, the element x to search for is not in the list and if x is in the list, it is equally likely to be in any position.
Please state the worst case run time for the following with an example of the worst...
Please state the worst case run time for the following with an example of the worst case and explain why! 1. Dijksta's Algorithm 2. Bellman-Ford Algorithm 3.DAG Algorithm 4. Prim's Algorithm 5. Kruskal's Algorithm 6. Baruvka's algorithm
What is recurrence for worst case of QuickSort and what is the time complexity in Worst...
What is recurrence for worst case of QuickSort and what is the time complexity in Worst case? algorithms coures
Show that the worst case of the Quicksort is Ω(n2)
Show that the worst case of the Quicksort is Ω(n2)
Given the below code, compute the values of the best case, worst case and average case...
Given the below code, compute the values of the best case, worst case and average case knowing that the basic operation in the first loop takes 4 ns to execute and the basic operation in the second loop takes 5 ns to execute. int A[20]; for (int i=0; i < 20; i++) {           cin >> A[i]; } for (i=0; i < 20; i++) {           if (A[i] % 3 == 0)                     break; }
merge sort Determine the best, average, and worst case inputs for merge sort.
merge sort Determine the best, average, and worst case inputs for merge sort.
6. List and explain the worst-case and average-case running times for each LinkedList method below: (a)...
6. List and explain the worst-case and average-case running times for each LinkedList method below: (a) insert(iterator here, Object item) (b) insertAtHead (c) insertAtTail (aka push back) (d) get(iterator here) (e) get(index i) (f) remove(iterator here) (g) remove(index i) (h) splice(iterator place here, iterator from here, iterator to here) 7. When should you use a Vector, and when should you use a Linked List?
For the problem below, please estimate the worst-case Running Time for a random array of size...
For the problem below, please estimate the worst-case Running Time for a random array of size n, and prove that it is indeed ( ). Please show all your work. Just stating something like "since 2 Binary Search runs in ( ) time, our algorithm has the same runtime estimate" is not enough. A rigorous explanation is expected. import java.util.*; public class Main { static int binarySearch(int arr[], int l, int r, int x) { if (r >= l) {...
Calculate the time complexity of each algorithm for best, worst and average cases. Give all steps...
Calculate the time complexity of each algorithm for best, worst and average cases. Give all steps of your calculation and results in Big-O notation. algorithm : Selection Sort Bubble Sort Insertion Sort
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT