Question: 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

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 0
Repeat until length of list school_1 is 0 or length of list school_2 is 0
Increase comparison_count by 1
If item 1 of school_1 is alphabetically before item 1 of school_2
Add item 1 of school_1 to merged
Remove this istem from school_1
else
Add item of 1 school_2 to merged
Remove this item from school_2
If length of school_1 is 0
Repeat until length of school_2 is 0
Add item 1 of school_2 to merged
Remove this item from school_2
else
Repeat until length of school_1 is 0
Add item 1 of school_1 to merged
Remove this item from school_1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!