Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C. Implement the algorithm developed in B in either Java 8 (or higher) or Python 3.7 (or higher). Read the input from a text file

C. Implement the algorithm developed in B in either Java 8 (or higher) or Python 3.7 (or higher). Read the input from a text file called inversionsinput.txt. This file should contain n lines where each line contains a single integer. The program should write a single line of descriptive output with the number of inversions found. For example:

The array contains 28 inversions. 

The program must be in a single file called either CountInversions.java or countinversions.py.

The following is B.

merge(arr,left right)

{

i=0,j=0,count=0

while( i

{

if (i ==left.length)

{

arr [ i+j ] = right[ j ]

j++

}

else if( j == right.length)

{

arr[ i+j ] = left[ i ]

i++

}

else if( left[i] <= right[ j ] )

{

arr[i+j] = left[ i ]

i++

}

else

{

arr[i+j] = right[j]

count= count+left.length - i

j++

}

}

return count

}

inv_count(arr)

{

if (n <2)

return 0;

else

mid = (n+1)/2

left[] = copy_array(arr,0,mid)

right[] = copy_array(arr,mid+1,n,)

return inv_count(left) + inv_count(rught) + merge(arr,left,right)

}

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

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions

Question

evaluate the quality of your data;

Answered: 1 week ago

Question

Understand why customers are loyal to a particular service firm.

Answered: 1 week ago