Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

b. Next you will write a script to merge the two sorted lists. The idea behind the merging algorithm is that we repeatedly compare

image text in transcribed

b. Next you will write a script to merge the two sorted lists. The idea behind the merging algorithm is that we repeatedly compare the item at the front of the first list with the item at the front of the second list: whichever is the smaller is added to the merged list, then removed from its original list. At some point, one list will become empty and we can then simply append the contents of the other list to the merged list. The steps of the algorithm are as follows, including the steps that are there to count the number of times two items are compared. Empty the merged list Initialise comparison_count to o Repeat until length of list school I is 0 or length of list school 2 is 0 Increase comparison count by If length else If item I of school I is alphabetically before item I of school_2 Add item I of school I to merged else Remove this item from school! Add item I of school_2 to merged. Remove this item from school_2 of school is o Repeat until length of school_2 is 0 Add item of school 2 to merged. Remove this item from school_2 Repeat until length of school is o Add item I of school_I to merged Remove this item from school Create a when [m] key_pressed script that implements the algorithm above. i. Take a screenshot of your complete when [m]key_pressed script and paste it into your TMA document. ii. Run your when[m]key_pressed script and note how many comparisons were required. Add this number to the numbers of comparisons that were required to sort the individual lists in part (a), to get the total number of comparisons taken to generate the final sorted list of children from both schools. iii. Suppose that instead of following Strategy 2 (sorting the lists then merging the results) we had instead used Strategy 1 (appending the second list to the first and then sorting the combined list using bubble sort 2). Use the formula given earlier to calculate how many comparisons would have been needed and briefly comment on which of the two strategies seems to be the most efficient in this example. (15 marks)

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

Entrepreneurship

Authors: Andrew Zacharakis, William D Bygrave

5th Edition

1119563097, 9781119563099

Students also viewed these Algorithms questions