Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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. Submit a print out of your code, and 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

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago