Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use C++ to fill in all TODO sections by request. PLEASE FILL IN THE TODO SECTIONS? no other file need. 2. Problem You have

Please use C++ to fill in all "TODO" sections by request.

image text in transcribed

PLEASE FILL IN THE TODO SECTIONS? no other file need.

image text in transcribed

image text in transcribed

2. Problem You have been asked to find the number of inversions in an array. An inversion is when a larger number appears before a smaller number. In the follow example, there are 3 inversions 1. 3 before2 2. 3 before 1 3. 2 before 1 You need to write two different algorithms to solve this problem. One is "slow". It is the nave approach using nested loops. The "fast" approach uses a modified mergesort that counts the number of inversions and returns that count. Your program will always run the fast algorithm unless the user specifies "slow" as the (only) command-line argument. Here are some examples of how the program should run $. ./inversioncounter Enter sequence of integers, each followed by a space: x 1 2 3 Error: Non-integer value x' received at index 0 $. ./inversioncounter Enter sequence of integers, each followed by a space: Error: Sequence of integers not received $ ./inversioncounter slow Enter sequence of integers, each followed by a space: 1 11 1 Number of inversions: 0 $ ./inversioncounter Enter sequence of integers, each followed by a space: 3 101 2.9 Number of inversions: 5 3. Advice We store the input in a vector, since we don't know how many values the user will enter. You can easily pass the internal array of the vector to the function with &values [0] Make sure you test your program on large inputs. Test cases 17-20 and 33-36 have 100,000 numbers. You are allowed up to 8 seconds on linux lab for the "slow" version and 1.25 seconds for the "fast" version. You should have no trouble meeting these timing requirements

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

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

What is the source of production inputs for Gat Creek?

Answered: 1 week ago

Question

2. Which symptoms of ASPD did Bill have?

Answered: 1 week ago