Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 1. Implement a merge sort algorithm in Python. Modify the code, so that it prints the following: The initial input sequence to be sorted,

Python

1. Implement a merge sort algorithm in Python. Modify the code, so that it prints the following:

The initial input sequence to be sorted, and its length. The order of the elements in the sequence, after the merge step has been performed on all the elements. Print this for every recursion depth, in the order the merges are performed. The total number of comparison operations performed during the run of the algorithm (a comparison operation is when 2 array elements are compared).

For instance, if the input array is [5, 3, 1, 2, 8, 4, 7, 6], you should print:

INPUT: 5,3,1,2,8,4,7,6 (length 8) MERGE STEP 1: 3,5,1,2,4,8,6,7 MERGE STEP 2: 1,2,3,5,4,6,7,8 MERGE STEP 3: 1,2,3,4,5,6,7,8 COMPARISONS: 14

Note that the number of comparisons will depend not only on the input given, but the specific way you implement merge sort, so you may get a slightly different number than above.

its output on the following input test cases: Array of numbers 1, 2, . . . , 50 (already in correct sorted order) Array of numbers 50, 49, . . . , 1 (reverse of correct sorted order) Array of 50 different random numbers

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

Step: 3

blur-text-image

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

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

Have issues been prioritized?

Answered: 1 week ago

Question

d. How will lack of trust be handled?

Answered: 1 week ago

Question

Are the rules readily available?

Answered: 1 week ago