Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 comparisoncount to
Repeat until length of list school is or length of list school is
Increase comparisoncount by
If item of school is alphabetically before item of school
Add item of school to merged
Remove this istem from school
else
Add item of school to merged
Remove this item from school
If length of school is
Repeat until length of school is
Add item of school to merged
Remove this item from school
else
Repeat until length of school is
Add item of school to merged
Remove this item from school
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started