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
Show that the worst case of the Quicksort is Ω(n2)
Show that the worst case of the Quicksort is Ω(n2)
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
20. The concept of best-, worst-, and average-case analyses extends beyond algorithms to other counting problems...
20. The concept of best-, worst-, and average-case analyses extends beyond algorithms to other counting problems in mathematics. Recall that the height of a binary tree is the number of edges in the longest path from the root to a leaf. (a) Find the best-case height of a binary tree with five nodes. (b) Find the worst-case height of a binary tree with five nodes. (c) Find the average-case height of a binary tree with five nodes. For this problem,...
There are three horses in a race. Historical records show that the time it takes each...
There are three horses in a race. Historical records show that the time it takes each horse to complete a similar race is Normally distributed with a mean and standard distribution given in the table below (all numbers are in minutes). Simulate 1,000 races using Excel. Approximately what proportion of the time will each horse win? Horse Mean Standard Dev. 1 0.87 0.17 2 0.95 0.06 3 1.10 0.14 Make sure you explain in your write up what each column...
A researcher measured the number of hours of community service performed during an average week in...
A researcher measured the number of hours of community service performed during an average week in a sample for three adolescent and young adult age groups. The results are shown below.   14 year olds                17 year olds                21 year olds             5                                              8                                              3                   6                                                12                                            5           3                                                7                                              7             5                                              4                                              4                              Conduct a one-way ANOVA to determine if there are any differences between the groups on community service....
Historical records show that in 1960 the average household size with 3.29 people with a standard...
Historical records show that in 1960 the average household size with 3.29 people with a standard deviation of 1.20 people in 2017 a sample 25 households in Richmond Virginia showed and mean number of residents per house where were 3.91 at a 0.1 significance level is it reasonable to conclude the mean number of residents in Richmond Virginia today is different from the typical American household in 1960? a. in the above problem, the critical values are (round to four...
Data from three hospitals show the number of surgeries performed on Monday thru Friday. At the...
Data from three hospitals show the number of surgeries performed on Monday thru Friday. At the 0.05 significance level, can we conclude there is a difference in the mean number of surgeries performed by hospital or by the day of the week? Hospital Surgery Data Day Hospital 1 Hospital 2 Hospital 3 Monday 25 31 35 Tuesday 26 33 33 Wednesday 24 28 30 Thursday 29 30 28 Friday 26 38 27 please show work clearly.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT