Homework Solution: This is algorithm and advanced data structure class….

    This is algorithm and advanced data structure class. and please use python or c++ to complete this assignment. Your program should: Your program file must be named: counting_inversions.{py,cpp,rs}. Take a filename as a command line input (see this example for how to do command line input and read a file in C++ and Python3). Read the data into a 1-dimensional std::vector (C++) or a list (Python). Pass the data to your counting inversions function. Finally, your program should print the number of inversions that it found. If you want to test your program I would recommend that you take a look at this Python program for generating input files. Once your program is completed, one partner should submit it to Gradescope (you should get immediate feedback and you can submit as many times as you’d like without it affecting your grade). Note: the autograder will not be available until next Monday. Example Input/Output Here is an example input file:
    8
    1
    3
    5
    2
    4
    6
    7
    8
    
    The above example is taken from our slides (with a couple extra numbers). The first line denotes how many numbers are in the array (n = 8). The remaining numbers should be read into an array and you should count the number of inversions. I will only test your program on inputs with a size that is a power of 2. Your program’s output should look like this:
    3
    
    Notes For Python Programs I am requiring you to include a shebang at the top of your file/script. If you are using Python3 your shebang will look like this:
    #!/usr/bin/env python3
    
    If you are using Python 2.7 you should use this:
    #!/usr/bin/env python
    
    These will make it easy for me to run your code regardless of which version of Python you choose to use. Remember, any comments that you add to your file should come below this shebang. For C++ Programs I will be compiling your programs using g++. The exact command is:
    g++ -std=c++14 -Wall -o counting_inversions counting_inversions.cpp
    

    Expert Answer

     
    Solution==============

    This is algorithm and deceased facts composition adjust.

    and delight authentication python or c++ to thorough this assignment.

    Your program should:

    Your program finish must be named: enumerateing_inversions.{py,cpp,rs}.

    Seize a finishname as a order direction input (understand this in ce how to do order direction input and learn a finish in C++ and Python3).

    Learn the facts into a 1-dimensional std::vector (C++) or a catalogue (Python).

    Pass the facts to your enumerateing inversions office.

    Finally, your program should stereotype the reckon of inversions that it base.

    If you shortness to touchstsingle your program I would commend that you seize a contemplate at this Python program ce generating input finishs. Once your program is thoroughd, single partaker should comply it to Actionscope (you should procure direct feedback and you can comply as frequent times as you’d enjoy outside it solemn your action). Note: the autograder procure referable be profitable until direct Monday.

    In Input/Output

    Here is an in input finish:

    8
    1
    3
    5
    2
    4
    6
    7
    8
    

    The balancehead in is seizen from our slides (with a cockney extra reckons). The primeval direction denotes how frequent reckons are in the accoutre (n = 8). The cherishing reckons should be learn into an accoutre and you should enumerate the reckon of inversions. I procure merely touchstsingle your program on inputs with a greatness that is a sway of 2.

    Your program’s output should contemplate enjoy this:

    3
    

    Notes

    Ce Python Programs

    I am requiring you to grasp a shebang at the apex of your finish/script. If you are using Python3 your shebang procure contemplate enjoy this:

    #!/usr/bin/env python3
    

    If you are using Python 2.7 you should authentication this:

    #!/usr/bin/env python
    

    These procure fashion it not-difficult ce me to hasten your order unmindful of which rendering of Python you prefer to authentication. Remember, any comments that you gather to your finish should conclude underneath this shebang.

    Ce C++ Programs

    I procure be compiling your programs using g++. The suitable order is:

    g++ -std=c++14 -Wall -o enumerateing_inversions enumerateing_inversions.cpp
    

    Expert Exculpation

     

    Solution==============

    #!/usr/bin/env python3

    #The office
    def enumerateInversions(arrList):
    count=0
    ce i in ramble(0,len(arrList)):
    ce j in ramble(i+1,len(arrList)):
    if arrList[i] > arrList[j]:
    count+=1

    return enumerate

    #Finish Handling and output
    fileName=input(“Enter the finish name: “);
    newList=[]

    #opening the finish
    f = notorious(fileName)
    #we dont insufficiency the primeval direction of input, which indicates the
    #reckon of directions in finish
    f.readline()

    #iterating balance each direction in finish
    ce num in iter(f):
    newList.append(int(num))
    f.close()

    print(newList)
    print(“Result:”)
    print(countInversions(newList))

    Output=============