Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

n a sequence = [ 1 , 2 , . . . , ] of integers, an inversion is a pair of elements and where

n a sequence =[1,2,...,] of integers, an inversion is a pair of elements and where
<(that is, appears before in the sequence) and >. For example, in the sequence
=2,1,5,3,4
the pairs (2,1),(5,3) and (5,4) are inversions.
An array with elements may have as many as
(
2)=(1)
2
inversions. When the number of inversions, , may be any value between 0 and (1)
2, the best
algorithm for counting inversions has running time ( log ). There also exists a (+)
algorithm for counting inversions, which is (2) when in (2).
Your goal in this lab is to create two algorithms which count the number of inversions in an input
sequence:
Input: An array of integers in the range 1 to .
Output: An integer, corresponding to the number of inversions in .
The first algorithm will have a ( log ) runtime and will be better for counting inversions
when >. The second algorithm will have runtime (+) and will be better when <=
(i.e.(+)=()).
Bonus:
Time permitting, you should try to implement them.

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

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

2. What should an employer do when facing an OSHA inspection?

Answered: 1 week ago