Question

In: Computer Science

In Python For this programming assignment, we are going to investigate how much "work" different sorting...

In Python For this programming assignment, we are going to investigate how much "work" different sorting routines do, based on the input size and order of the data. We will record the work done by writing output CSV (comma separated value) files and creating various plots using matplotlib. Note: for this assignment, do not use Jupyter Notebook to code your solution. Use standard .py files and save your output to .csv and .png files (see the program details below for more on program output). Program Details: Data Structure Implement a doubly linked circular linked list of Node objects called CircularDoublyLinkedList. The data of each Node in the list is an integer. You will collect measurements for: An already sorted linked list An already sorted linked list in descending order A linked list containing random data List Size Configurations Generate each of the above linked lists with the following number of nodes: 500 1000 5000 10000 (more values if you wish) Note: Make copies of the original lists (as necessary) and pass the copies to each sorting routine so each routine is operating on the same data! This is important in order to compare the results of the different algorithms. Sorting Routines Implement 3 of the following linked list sorting routines (implemented as a function or as a method of your CircularDoublyLinkedList class): Choose 2 from the first 4 and 1 from the last 2 Selection sort Early exit bubble sort (stops when the list is sorted) Insertion sort Shell sort Merge sort Quick sort Data to Collect For each sorting routine above, create a pandas DataFrame with rows for each list size configuration and columns for each metric to collect. The metrics to collect include the algorithm's execution time using timeit and counts for the following operations: Number of data comparisons Number of loop control comparisons Number of assignment operations involving data Number of assignment operations involving loop control "Other" operations (operations that don't fall into one of the above categories) Total number of operations (sum of the above) Note: Be sure to comment everything you count in your code. Pictorially, here is an example DataFrame for a sorting routine: List configuration Seconds # Data # Loop # Data assignments # Loop assignments # Other Total Sorted N=500 Sorted N=1000 Sorted N=5000 Sorted N=10000 Descending sorted N=500 Descending sorted N=1000 Descending sorted N=5000 Descending sorted N=10000 Random N=500 Random N=1000 Random N=5000 Random N=10000 Program Output CSV Files Write the contents of each sorting routine DataFrame to a CSV file with a filename of the form _sort_results.csv. For example, bubble_sort_results.csv. See the function to_csv() in the pandas library for a straightforward way to do this! In total, your program should output 6 csv files, one for each sorting routine. Plots to Generate For each of the three list configurations (sorted, descending sorted, random), create two plots with list size on the x-axis (i.e. 500, 1000, 5000, 10000) and the following on the y-axis: Plot 1: running time Plot 2: total operation count Each plot should have a separate curve for each sorting routine. For example (example purposes only!!)

Solutions

Expert Solution

def printOrder(arr, n, k):

  

    len1 = k

    len2 = n - k

    arr1 = [0] * k

    arr2 = [0] * (n - k)

  

    # Store the k elements

    # in an array

    for i in range(k):

        arr1[i] = arr[i]

  

    # Store the remaining n-k

    # elements in an array

    for i in range(k, n):

        arr2[i - k] = arr[i]

  

    # sorting the array from

    # 0 to k-1 places

    arr1.sort()

  

    # sorting the array from

    # k to n places

    arr2.sort()

  

    # storing the values in the

    # final array arr

    for i in range(n):

        if (i < k):

            arr[i] = arr1[i]

  

        else :

            arr[i] = arr2[len2 - 1]

            len2 -= 1

      

    # printing the array

    for i in range(n):

        print(arr[i], end = " ")

  

# Driver code

if __name__ == "__main__":

    arr = [ 5, 4, 6, 2, 1,

            3, 8, 9, -1 ]

    k = 4

  

    n = len(arr)

  

    printOrder(arr, n, k)

output::

2 4 5 6 9 8 3 1 -1

Related Solutions

Java Programming In this assignment we are going to create our own programming language, and process...
Java Programming In this assignment we are going to create our own programming language, and process it Java. programming language has 6 commands enter add subtract multiply divide return enter, add, subtract, multiply, divide all take 1 parameter (a double value). return takes no parameters.
WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you...
WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you will write functions to encrypt and decrypt messages using simple substitution ciphers. Your solution MUST include: a function called encode that takes two parameters: key, a 26-character long string that identifies the ciphertext mapping for each letter of the alphabet, in order; plaintext, a string of unspecified length that represents the message to be encoded. encode will return a string representing the ciphertext. a...
Beginning Python Programming - Sorting: Write and test a Python program to print a set of...
Beginning Python Programming - Sorting: Write and test a Python program to print a set of real numbers in descending order. The program should also print out the median of the numbers input and how many numbers were input. The program should read in numbers until a negative number is read. The negative number serves as a sentinel or marker telling the program when to stop reading numbers. The program should then sort the numbers and print them out in...
In this assignment, we are going to work with a combination of variables representing integers, floating...
In this assignment, we are going to work with a combination of variables representing integers, floating point numbers (decimals), and strings. Strings are also known as literals. We will create, save, and run a Python batch file (i.e., a Python script file) that will ask the user to enter the name of an investment, the amount invested, the annual return rate, and number of years, after which Python will compute the investment's final value at the end of that time...
Assignment #1: Sorting with Binary Search Tree Through this programming assignment, the students will learn to...
Assignment #1: Sorting with Binary Search Tree Through this programming assignment, the students will learn to do the following: 1. Know how to process command line arguments. 2. Perform basic file I/O. 3. Use structs, pointers, and strings. 4. Use dynamic memory. This assignment asks you to sort the lines of an input file (or from standard input) and print the sorted lines to an output file (or standard output). Your program, called bstsort (binary search tree sort), will take...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the bubble sort algorithm. You must be able to sort both integers and doubles, and to do this you must overload a method. Bubble sort work by repeatedly going over the array, and when 2 numbers are found to be out of order, you swap those two numbers. This can be done by looping until there are no more swaps being made, or using a...
Assignment #1: Sorting with Binary Search Tree (IN C LANGUAGE) Through this programming assignment, the students...
Assignment #1: Sorting with Binary Search Tree (IN C LANGUAGE) Through this programming assignment, the students will learn to do the following: 1. Know how to process command line arguments. 2. Perform basic file I/O. 3. Use structs, pointers, and strings. 4. Use dynamic memory. This assignment asks you to sort the lines of an input file (or from standard input) and print the sorted lines to an output file (or standard output). Your program, called bstsort (binary search tree...
Python programming ***************************************************************************************************** If we load the json files then how could we use the objects...
Python programming ***************************************************************************************************** If we load the json files then how could we use the objects to extract particular values from those files. eg: fi1 = open("king.json", "rb") obj1 = yaml.safe_load(fi1.read()) fi1.close() fi2 = open("queen.json", "rb") obj2 = yaml.safe_load(fi2.read()) fi2.close() Now if the JSON file queen.json had elements like name, rule year, children, etc. and we wanted the name of the queen who ruled between particular years, how would we do it? second would be getting a value common for...
Assignment 1 – Writing a Linux Utility Program Instructions For this programming assignment you are going...
Assignment 1 – Writing a Linux Utility Program Instructions For this programming assignment you are going to implement a simple C version of the UNIX cat program called lolcat. The cat program allows you to display the contents of one or more text files. The lolcat program will only display one file. The correct usage of your program should be to execute it on the command line with a single command line argument consisting of the name you want to...
java programming Concepts ArrayList - Collections Sorting Enhanced For Loop Collections Class Auto-boxing Programming Assignment 1....
java programming Concepts ArrayList - Collections Sorting Enhanced For Loop Collections Class Auto-boxing Programming Assignment 1. Describe auto-boxing, including why it is useful. (Google for this one) Write a few lines of code that auto-box an int into an Integer, and un-box an Integer to an int. 2. Declare an ArrayList of Strings. Add 5 names to the collection. "Bob" "Susan" ... Output the Strings onto the console using the enhanced for loop. 3. Sort the list using the method...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT