Answered step by step
Verified Expert Solution
Link Copied!

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

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

More Books

Students also viewed these Databases questions

Question

How Infl ation Aff ects Borrowing, Saving, and Investing

Answered: 1 week ago