Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Let {a1,a2,a3,...an} be a permutation of {1,2,3,...n}. (ai,aj) is an inversion if i < j and ai > aj. Your task is to implement both

Let {a1,a2,a3,...an} be a permutation of {1,2,3,...n}. (ai,aj) is an inversion if i < j and ai > aj. Your

task is to implement both the brute force method (O(n2)) and the divide and conquer method

(O(nlogn)) for counting the number of inversions for a given array A of size n, that contains

permutation of {1,2,3,...n}. You are provided with 14 input files,the names are 10, 50, 100, 150,

200, 250, 300, 350, 400, 450, 500, 1000, 5000, 10000. These files contain random permutation

of {1,2,3,...n}. The filename represents the number of entries in each of the files.

Use these as input for your program. Plot the running time of both the methods (brute force and divide and

conquer) on these 14 datasets. Also, report the number of inversions in all the datasets.

Note: If your brute-force technique starts taking too much time, then you can choose to abort

running the brute-force approach for larger values of n.

I won't give all 14 files as it will take up a huge amount of space but I'll give you the files 10, 50 and 100.

10:

3 9 10 6 4 1 5 2 7 8

50:

2 45 18 43 24 10 17 39 29 30 50 31 4 44 21 36 16 19 11 13 49 47 6 48 22 14 46 25 38 26 37 42 7 9 12 35 41 3 40 1 15 33 27 23 32 8 28 20 34 5

100:

72 32 66 16 75 87 62 82 51 50 89 55 83 49 21 86 7 68 96 29 90 70 58 11 79 33 17 95 69 65 48 67 100 34 10 18 61 30 98 91 85 53 43 36 1 37 13 54 64 74 38 73 94 23 20 44 88 42 24 84 71 99 15 6 92 5 52 3 39 31 4 80 81 26 35 45 60 22 8 27 40 63 46 14 78 56 59 57 41 93 25 97 76 2 77 9 12 19 28 47

Please show screenshots of code and output and let me know if I need to include more information.

Also needs to be completed in python

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_2

Step: 3

blur-text-image_3

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

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

Draw structures of the nine isomers of C7H16.

Answered: 1 week ago