Question: In the following pseudocode the only basic step is to print one . Show that the RT of this code is O ( n ^

In the following pseudocode the only basic step is to print one . Show that the RT of this code is O(n^2). for i =0 to n-1: j :=0 while j < i: print one * j := j +1
Question 2.
In an array A of n different numbers two numbers A[i] and A[j] form an inversion if i < j, but A[i]> A[j], i.e. the bigger comes before the smaller. (For example 15 and 3 form an inversion in 8,15,1,10,3 since the 15 comes before 3).(a) How many inversions are there in 2,5,1,10,3?(b) Design a brute-force algo for counting the inversions, the running time should be O(n2), if the array contains n different numbers. (c) Design a divide-and-conquer algo for counting the inversions, here the running time should be O(nlogn) if the size of the array is n.for the last part we can notice inversions while performing mergesort.) you can suppose that the size of the array is a power of 2.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!