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
Let A[1, . . . , n] be an array of n distinct numbers. If i...
Let A[1, . . . , n] be an array of n distinct numbers. If i < j and A[i] > A[j], then the pair (i, j) is called an inversion of A. 1. Which arrays with distinct elements from the set {1, 2, . . . , n} have the smallest and the largest number of inversions and why? State the expressions exactly in terms of n. 2. For any 0 < a < 1/2, construct an array for...
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...
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...
First, understand the Selection-sort algorithm below: Selection-sort(A: Array [1..n] of numbers) 1       for i=n down to...
First, understand the Selection-sort algorithm below: Selection-sort(A: Array [1..n] of numbers) 1       for i=n down to 2 2                position=i 3                for j=1 to (i–1) 4                          if A[j]>A[position] then position=j 5                if position ≠ i then 6                          temp=A[i] 7                          A[i]=A[position] 8                          A[position]=temp (4 points) If input A=[12,5,11,6,10,7,9,8], what will A be after the 3rd iteration of the outermost for loop of the Selection-sort algorithm completes? A=[__, __, __, __, __, __, __, __] (8 points) Modify the algorithm to solve the...
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 +.
2. Design a deterministic algorithm to solve the following problem. input: An array A[1...n] of n...
2. Design a deterministic algorithm to solve the following problem. input: An array A[1...n] of n integers. output: Two different indices i and j such that A[i] = A[j], if such indices exist. Otherwise, return NONE. Your algorithm must take O(n log(n)) time. You must describe your algorithm in plain English (no pseudocode) and you must explain why the running time of your algorithm is O(n log(n)).
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.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT