Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the problem of counting inversions, you are given a permutation a1,a2,an of numbers 1,2,,n, and the goal is to count the number of pairs

image text in transcribed

In the problem of counting inversions, you are given a permutation a1,a2,an of numbers 1,2,,n, and the goal is to count the number of pairs i,j, where iaj. In this homework problem, you are given a sequence of n numbers b1,b2,,bn and your task is to compute the "weighted count" of inversions defined as follows: An inversion is a pair of indices i,j where ibj. An i,j inversion has weight bi+bj and the weighted count for the input sequence is the sum of the weights of all its inversions. For example, for n=5 and input sequence 7,3,8,1,5, we have the following inversions weights: 7+3=10,7+1=8,7+5=12,3+1=4,8+1=9, and 8+5=13. The overall weighted count is: 10+8+12+4+9+13=56. Design an O(nlogn) algorithm which computes the weighted count of inversions for a given input sequence

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions