Question

1. Let A = ha1, a2, . . . , ani be an array of numbers....

1. Let A = ha1, a2, . . . , ani be an array of numbers. Let’s define a ’flip’ as a pair of distinct indices i, j ∈ {1, 2, . . . , n} such that i < j but ai > aj . That is, ai and aj are out of order. For example - In the array A = [1, 3, 5, 2, 4, 6], (3, 2), (5, 2) and (5, 4) are the only flips i.e. the total number of flips is 3. (Note that in this example the indices are the same as the actual values)

At most, how many flips can A contain in terms of the array size n?

Homework Answers

Answer #1
If the array is sorted in reverse order like: [6, 5, 4, 3, 2, 1], then there will total 5 + 4 + 3 + 2 + 1 = 15 inversions (flips)

So, for an array of size N, It will be: 1 + 2 + .. + (N-1) = N(N-1)/2 flips
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Know the answer?
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
Similar Questions
1. Define the problem Closest-Pair as follows. • Input: an array A consisting of distinct numbers....
1. Define the problem Closest-Pair as follows. • Input: an array A consisting of distinct numbers. • Output: the numbers x, y in A such that |x − y| is as small as possible. Design an O(n log n) time algorithm for this problem . Define the List-Delete problem as follows. • Input: A linked list L of distinct integers and an element a of L. • Output: L with the element a deleted. Design an O(1)-time algorithm for the...
1. Determine in each of the following cases, whether the described system is or not a...
1. Determine in each of the following cases, whether the described system is or not a group. Explain your answers. Determine what of them is an Abelian group. a) G = {set of integers}, a* b = a − b b) G = {set of matrices of size 2 × 2}, A * B = A · B c) G = {a0, a1, a2, a3, a4}, ai * aj = a|i+j|, if i+j < 5, ai *aj = a|i+j−5|, if...
We are given an array A of size n containing n positive and negative integers (the...
We are given an array A of size n containing n positive and negative integers (the array is indexed starting from 0). Our goal is to find two indices i and j such that 0 ≤ i ≤ j ≤ n and Pk=j k=i A[k] is maximized. Input sequence: [2, -4, 1, 9, -6, 7, -3] Output: [1, 9, -6, 7] or i = 2 and j = 5 Input sequence: [1, 2, 3, 4, 5, 6, -3] Output: [1,...
Let a1, a2, ..., an be distinct n (≥ 2) integers. Consider the polynomial f(x) =...
Let a1, a2, ..., an be distinct n (≥ 2) integers. Consider the polynomial f(x) = (x−a1)(x−a2)···(x−an)−1 in Q[x] (1) Prove that if then f(x) = g(x)h(x) for some g(x), h(x) ∈ Z[x], g(ai) + h(ai) = 0 for all i = 1, 2, ..., n (2) Prove that f(x) is irreducible over Q
C++ program for : 1. Given an array of real numbers and the dimension n (n...
C++ program for : 1. Given an array of real numbers and the dimension n (n is entered from the keyboard). B form an array, each element bi - arithmetic mean of the array elements and excluding ai. 2. Given an array of integers dimension n. Change the array so that all the elements of the module which is not equal to the maximum element of the array, replaced by zero, and equal - unit. 3. Given an array of...
(8 marks) Let S = {(a1, a2, . . . , an)| n ≥ 1, ai...
Let S = {(a1, a2, . . . , an)| n ≥ 1, ai ∈ Z ≥0 for i = 1, 2, . . . , n, an 6= 0}. So S is the set of all finite ordered n-tuples of nonnegative integers where the last coordinate is not 0. Find a bijection from S to Z +.
Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between...
Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between 1 and 100. 2- Moves all multiple of 3-numbers in the array that created in part-a into a new array. 3- Moves all multiple of 5-numbers in the array that created in part-a into a new array. 4- Find the maximum and the minimum multiple of 3-numbers, if exist. 5- Find the maximum and the minimum multiple of 5-numbers, if exist. 6- Prints the...
Let A = (A1, A2, A3,.....Ai) be defined as a sequence containing positive and negative integer...
Let A = (A1, A2, A3,.....Ai) be defined as a sequence containing positive and negative integer numbers. A substring is defined as (An, An+1,.....Am) where 1 <= n < m <= i. Now, the weight of the substring is the sum of all its elements. Showing your algorithms and proper working: 1) Does there exist a substring with no weight or zero weight? 2) Please list the substring which contains the maximum weight found in the sequence.
1.) Generate an array of 10 random numbers between 1 - 100 2.) Copy the array...
1.) Generate an array of 10 random numbers between 1 - 100 2.) Copy the array to a temp array 3.) Call each of the methods to sort (bubble, selection, insertion, quick, merge), passing it the array 4.) In-between the calls, you are going to refresh the array to the original numbers. 5.) Inside of each sorting method, you are going to obtain the nanoseconds time, before and after the method Subtract the before time from the after time to...
Complete following function which receives an array of integers and the length of the array, and...
Complete following function which receives an array of integers and the length of the array, and then returns the sum of all the positive numbers in the array. For example, if an array that is passed to this function contains following numbers: -1, 2, 0, 3, 4, -3, 0, 2, 0, and then the return value of the function should be 11. Will this function be working correctly? Yes or No? int sumPositive(int a[],int length) { int s=0;     for(int...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT