Question

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 which insertion sort has a run time of an^2 + Θ(n).

3.

Let A[1, . . . , n] be a random permutation of {1, 2, . . . , n}. What is the expected

number of inversions of A. What can you conclude about the average case running time of

Insertion-Sort (where the average is over all arrays A of size n)?

Hint: Recall the linearity of expectation, i.e., for any real a, b, c and any random variables

X, Y , E(aX + bY + c) = aE(X) + bE(Y ) + c .

Homework Answers

Answer #1

Answer 1

Smallest inversions array are arrays with values in ascending order from 1 to n.

Smallest Inversions Array Example = [1, 2, 3, 4, 5, 6, 7, 8, 9]

Number of Inversions = 0

Largest inversions array are array with reverse order of element.

Largest Inversions Array Example = [9, 8, 6, 5, 3]

Number of inversions = (n-1) + (n-2) +...+1 = n(n-1)/2

Answer 3

Let's consider Xij represents the indicator random variable for the event that Ai > Aj (i<j).

Probability of two distinct integers having inversion is half so expected number

Assuming X is the random variable which denotes the total number of Inverted pairs then

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. 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...
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...
CountingSort(A, B, k) for i=1 to k C[i]= 0; for j=1 to n C[A[j]] += 1;...
CountingSort(A, B, k) for i=1 to k C[i]= 0; for j=1 to n C[A[j]] += 1; for i=2 to k C[i] = C[i] + C[i-1]; for j=n downto 1 B[C[A[j]]] = A[j]; C[A[j]] -= 1; illustrate the operation of COUNTING-SORT on the array A = {6,0,2,0, 1, 3, 5, 6, 1, 3, 2}. Specifically, show the four arrays A, B, C, and C'.
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...
Suppose an array A stores n integers, each of which is in {0, 1, 2, ...,...
Suppose an array A stores n integers, each of which is in {0, 1, 2, ..., 99}. Which of the following sorting algorithms can sort A in O(n) time in the worst case? Question 16 options: A) merge sort B) counting sort C) quicksort D) None of these options is correct. E) insertion sort
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...
1a. Given an array a of n distinct integers, a[i] = m is a local minimum...
1a. Given an array a of n distinct integers, a[i] = m is a local minimum of a iff a[i − 1] > m and a[i + 1] < m. Suppose that n ≥ 3, a[0] > a[1], and a[n − 2] < a[n − 1]. Explain why these “end point” conditions guarantee that a has a local minimum. Hint: argue by way of contradiction. (10 points) 1b. Assuming that a satisfies the conditions described in part a, clearly and...
Java : Modify the selection sort algorithm to sort an array of integers in descending order....
Java : Modify the selection sort algorithm to sort an array of integers in descending order. describe how the skills you have gained could be applied in the field. Please don't use an already answered solution from chegg. I've unfortunately had that happen at many occasion ....... ........ sec01/SelectionSortDemo.java import java.util.Arrays; /** This program demonstrates the selection sort algorithm by sorting an array that is filled with random numbers. */ public class SelectionSortDemo { public static void main(String[] args) {...
Let B[1...n] be an array of integers. To express that no integer occurs twice in the...
Let B[1...n] be an array of integers. To express that no integer occurs twice in the B We may write? (check all the answers that apply) a) forall i 1..n forall j in 1...n B[i] != B[j] b)for all i in 1...n forall j in 1...n, i != j => B[i] !=B[j] c)forll i in 1...n forall j in 1...n i != j and B[i] != B[j] d)forall i in 1...n forall j in 1...n B[i] =B[j] => i=j e)forall...
An online/anytime sorting algorithm is one that reads its input numbers one at a time, and...
An online/anytime sorting algorithm is one that reads its input numbers one at a time, and maintains a sorted array of all the inputs it has seen so far, so that if it is interrupted at any time, it will still output the correct answer for the inputs that it has processed. Not all sorting algorithms are amenable to modification to make them anytime. But one sorting algorithm, Bubble Sort, is easy to so modify. First, understand the ascending order...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT