1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nastasia [14]
3 years ago
8

Recall the problem of finding the number of inversions. As in the text, we are given a sequence of n numbers a1, . . . , an, whi

ch we assume are all distinct, and we define an inversion to be a pair i < j such that ai > aj.
We motivated the problem of counting inversions as a good measure of how different two orderings are. However, one might feel that this measure is too sensitive. Let’s call a pair a significant inversion if i < j and ai > 2aj. Give an O(n log n) algorithm to count the number of significant inversions between two orderings.
Computers and Technology
1 answer:
Kay [80]3 years ago
5 0

Answer:

The algorithm is very similar to the algorithm of counting inversions. The only change is that here we separate the counting of significant inversions from the merge-sort process.

Algorithm:

Let A = (a1, a2, . . . , an).

Function CountSigInv(A[1...n])

if n = 1 return 0; //base case

Let L := A[1...floor(n/2)]; // Get the first half of A

Let R := A[floor(n/2)+1...n]; // Get the second half of A

//Recurse on L. Return B, the sorted L,

//and x, the number of significant inversions in $L$

Let B, x := CountSigInv(L);

Let C, y := CountSigInv(R); //Do the counting of significant split inversions

Let i := 1;

Let j := 1;

Let z := 0;

// to count the number of significant split inversions while(i <= length(B) and j <= length(C)) if(B[i] > 2*C[j]) z += length(B)-i+1; j += 1; else i += 1;

//the normal merge-sort process i := 1; j := 1;

//the sorted A to be output Let D[1...n] be an array of length n, and every entry is initialized with 0; for k = 1 to n if B[i] < C[j] D[k] = B[i]; i += 1; else D[k] = C[j]; j += 1; return D, (x + y + z);

Runtime Analysis: At each level, both the counting of significant split inversions and the normal merge-sort process take O(n) time, because we take a linear scan in both cases. Also, at each level, we break the problem into two subproblems and the size of each subproblem is n/2. Hence, the recurrence relation is T(n) = 2T(n/2) + O(n). So in total, the time complexity is O(n log n).

Explanation:

You might be interested in
What is a required device(s) used to connect to an ISP Network?
Whitepunk [10]
A .switch isp connect network
8 0
3 years ago
Read 2 more answers
Create a method called fixArray(int[][] array, int row, int col, int value) that sets the [row][column] to the correct value. Th
PolarNik [594]

Answer:

  1. public class Main {
  2.    public static void main (String [] args) {
  3.        int[][] myArray = {{1,5,6}, {7, 9, 2}};
  4.        fixArray(myArray, 1, 2, 12);
  5.        System.out.println(myArray[1][2]);
  6.    }
  7.    private static void fixArray(int[][] array, int row, int col, int value){
  8.        array[row][col] = value;
  9.    }
  10. }

Explanation:

The solution code is written in Java.

Firstly, create the method fixArray with that takes four inputs, array, row, col and value (Line 11). Within the method body, use row and col as index to address a particular element from array and set the input value to it (Line 12).

Next, we test the method in the main program using a sample array (Line 4) and we try to change the row-1 and col-2 element from 2 to 12 (Line 5).

The print statement in Line 7 will display 12 in console.

7 0
4 years ago
Identify some advantages of using Excel over lists, paper files, or simple word documents?
ra1l [238]

Answer:

Explanation:

Difficult to manage advanced pricing rules. ...

Lack of control and security. ...

Excel is vulnerable to fraud/corruption. ...

Excel is susceptible to human error. ...

Excel is difficult to troubleshoot or test. ...

Excel is obstructive to regulatory compliance.

Whether it is family-based planning for a weekly, monthly or yearly calendar or a personal appointment daily planner or a schedule for managing bill payments, homework, favorite sports team's games, and many more, excel can make it easy to compile, filter, search, organize and simplify large amounts of data.

6 0
3 years ago
Refer to the exhibit. what is the administrative distance value of the route for router r1 to reach the destination ipv6 address
FromTheMoon [43]
The administrative value of distance of the route refer to the exhibit, for the router r1 to reach the destination ipv6 address of 2001:db8:cafe:4::a is 120. !220 is the administrative distance value of the route between the router r1 to reach the destination of ipv6 address.
6 0
3 years ago
List at least four items that security policy should include
forsale [732]

Answer:

Purpose.

Audience.

Information security objectives.

Authority and access control policy.

Data classification.

Data support and operations.

Security awareness and behavior.

Encryption policy.

4 0
2 years ago
Other questions:
  • Determine the value of base x of (211)x=(152)8
    8·2 answers
  • Using the expected format, of putting key information where the reader can’t find it, is an example of?
    8·2 answers
  • The icacls.exe command adds __________, which are visible by clicking the Advanced button in the folder Properties dialog box
    15·1 answer
  • Describe the 3 parts of a spreadsheet formula
    12·1 answer
  • ACL 1 has three statements, in the following order, with address and wildcard mask values as follows: 1.0.0.0 0.255.255.255, 1.1
    6·1 answer
  • Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards
    11·1 answer
  • What is the difference between a master device in a Bluetooth network and a base station in an 802.11 network?
    13·1 answer
  • You are writing a program using the Java language. Which of the following is a requirement of Java syntax?
    6·1 answer
  • How do i make a comment on brainly?
    15·1 answer
  • What happens after the initial rollout of a new network generation?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!