Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8205775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:23:36+00:00 2026-06-07T08:23:36+00:00

Consider an array a of integers. A pair (i,j) is called an inversion in

  • 0

Consider an array a of integers. A pair (i,j) is called an inversion in A if i < j and A[i] > A[j].

For every position ‘i’ in the array there are two possible candidates: a[i] with probability p[i] and a[i]+x with probability 1-p[i].

Now I have to calculate expected number of inversions.
Given a[i] and p[i] for every index i and an integer x.

I know the O(n^2) approach (check every legal possible pair).
Also, I know the O(nlogn) approach to calculate the number of inversions in an array in which all the elements are predetermined with 100% probability. It is done by modifying merge sort.

I want to know an approach better than n squared. Please let me know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:23:37+00:00Added an answer on June 7, 2026 at 8:23 am

    This can be done with a simple modification to the standard merge-sort based algorithm for counting inversions, where we assign a weight to each value and compute the sum of W[i]*W[j] for i<j, A[i]>A[j] (when each weight is 1, we get the normal count). Instead of adding to the count the number of elements remaining in the left array, we add the sum of the weights for these elements multiplied by the weight of the element in the right array we are processing.

    To use this algorithm to solve the posed problem, simply create an array of twice the size, where each element in the original array is replaced by two elements (in sorted order), with weights given by the probabilities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume that we have multiple arrays of integers. You can consider each array as
Consider I have two arrays: $friends = Array('foo', 'bar', 'alpha'); $attendees = Array('foo', 'bar');
Consider I have an array of elements out of which I want to create
Fortran: There are two large arrays of integers, the goal is to find out
Consider the following array, which is claimed to have represented a binary tree: [1,
Consider this problem: You are given an array containing positive integers. All the integers
Problem: Consider the problem of adding two n-bit binary integers, stored in two n-element
I have a grid or a 2D array of size N*N. Consider a 6*6
Consider this array string[] presidents = { Adams, Arthur, Buchanan, Bush, Carter, Cleveland, Clinton,
Consider a string array shaped like this: string[] someName = new string[] { First,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.