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]
2 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]2 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
Explain and give examples of at least two search engines.
ale4655 [162]
Search engines are programs that search for and identify items based on a user input keyword, phrase, etc. Examples include google, bing, etc.
5 0
3 years ago
I want to sign up for brainly but it won't let me. It keeps saying "we can complete your registration at this time".
vekshin1
Try reinstalling the app or check if your wifi connection is good, if everything’s good but the app still doesn’t work then just use the website
5 0
2 years ago
Wich type of operating system is usually used in personal computers
Anvisha [2.4K]
The three most common operating systems for personal computers are Microsoft Windows, Apple Mac OS X, and Linux.
4 0
3 years ago
Read 2 more answers
"what is the problem with using challenge handshake authentication protocol (chap) as an authentication protocol?"
Alexxandr [17]

Its use of the message digest 5 (MD5) hash algorithm for security.

CHAP uses a combination of MD5 hashing and a challenge-response mechanism, and authenticates without sending passwords as plaintext over the network. The security of the MD5 hash function is severely compromised.

5 0
3 years ago
O How basic blocks are identified and how the blocks are used to construct control flow graphs
OLEGan [10]

Basic blocks are identified  because they are known to be a straight line that is known also as a code sequence that tends to have no branches in regards to its in and out branches and its exception is only to the entry and at the end.

Note that  Basic Block is said to be a composition  of statements that is known to be one that often always executes one after other, and this is often done in a sequence.

<h3>How do you create a flow graph from the basic blocks?</h3>

Flow graph  is gotten by:

  • Lets Block B1 be the initial node and also Block B2 will tend to follows B1, so from B2 to B1 there is seen a kind of an edge.

Note that the first task is for a person to partition a sequence of three-address code and this is done into basic blocks.

Hence, Basic blocks are identified  because they are known to be a straight line that is known also as a code sequence that tends to have no branches in regards to its in and out branches and its exception is only to the entry and at the end.

Learn more about basic blocks from

brainly.com/question/132319

#SPJ1

5 0
1 year ago
Other questions:
  • What three components make up a film camera?
    14·2 answers
  • Driving while wearing headphones or earphones
    12·2 answers
  • The ____ function sums the numbers in the specified range and then divides the sum by the number of cells with numeric values in
    14·1 answer
  • TCP is the protocol responsible for the delivery of data on the Internet, and IP provides addresses and routing information.
    12·1 answer
  • True or false there is no relationship between the purpose of the page and the page quality
    13·1 answer
  • In C++ please.
    8·1 answer
  • Why is it important to put the most specific case first? What types of errors does it help avoid?
    11·1 answer
  • What is collaboration
    14·1 answer
  • The action of entering data into your computer. This can be text typed in a word processing document, keywords entered in a sear
    8·1 answer
  • What is the function of ALU? <br>​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!