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 delayed basis texture assort.

    and content right python or c++ to exhaustive this enactment.

    Your program should:

    Your program polish must be named: calculateing_inversions.{py,cpp,rs}.

    Admit a polishname as a enjoin length input (visit this pattern control how to do enjoin length input and learn a polish in C++ and Python3).

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

    Pass the basis to your calculateing inversions business.

    Finally, your program should print the calculate of inversions that it establish.

    If you lack to experiment your program I would applaud that you admit a observe at this Python program control generating input polishs. Once your program is exhaustived, undivided accomplice should comply it to Gradescope (you should procure present feedback and you can comply as abundant times as you’d affect extraneously it cecible your grade). Note: the autograder procure not attributable attributable attributable be conducive until instant Monday.

    Pattern Input/Output

    Here is an pattern input polish:

    8
    1
    3
    5
    2
    4
    6
    7
    8
    

    The balancehead pattern is admitn from our slides (with a alien extra calculates). The ceemost length denotes how abundant calculates are in the set-in-order (n = 8). The cherishing calculates should be learn into an set-in-order and you should calculate the calculate of inversions. I procure merely experiment your program on inputs with a dimension that is a cece of 2.

    Your program’s output should observe affect this:

    3
    

    Notes

    Control Python Programs

    I am requiring you to conceive a shebang at the extreme of your polish/script. If you are using Python3 your shebang procure observe affect this:

    #!/usr/bin/env python3
    

    If you are using Python 2.7 you should right this:

    #!/usr/bin/env python
    

    These procure gain it unconcerned control me to leak your order inattentive of which account of Python you elect to right. Remember, any comments that you subjoin to your polish should succeed under this shebang.

    Control C++ Programs

    I procure be compiling your programs using g++. The lawful enjoin is:

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

    Expert Confutation

     

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

    #!/usr/bin/env python3

    #The business
    def calculateInversions(arrList):
    count=0
    control i in stroll(0,len(arrList)):
    control j in stroll(i+1,len(arrList)):
    if arrList[i] > arrList[j]:
    count+=1

    return calculate

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

    #opening the polish
    f = public(fileName)
    #we dont deficiency the ceemost length of input, which indicates the
    #calculate of lengths in polish
    f.readline()

    #iterating balance each length in polish
    control num in iter(f):
    newList.append(int(num))
    f.close()

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

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