Question

Prove that the Merge() function of your own merge sort algorithm in the question 2 is...

Prove that the Merge() function of your own merge sort algorithm in the question 2 is correct using "induction on loop invariants" by following the guidelines below : (10 points)

3.1 Write down general description of loop invariant technique in your own words as proof of correctness. (2 points)

3.2 Identify the loop invariant of the loop in your merge() function (3 points)

3.3 Describe initialization step (0 points)

3.4 Describe maintenance step (4 points)

3.5 Describe Termination step (1 point)

Deliverable:

-Your answers in a simple text file format

0 0
Add a comment Improve this question Transcribed image text
Answer #1

3.1 Loop invariant technique:

A loop invariant is a condition that is necessarily true immediately before and immediately after each iteration of a loop.The loop invariants will be true on entry into a loop and following each iteration, so that on exit from the loop both the loop invariants and the loop termination condition can be guaranteed.

3.2 Loop Invariant

At the start of each iteration k of the for loop, the nonempty part of S contains the k − 1 smallest elements of L and R, in sorted order. Moreover, L[i] and R[j] are the smallest elements of their arrays that have not been copied to S.

3.3 Initialization Step:

The loop invariant holds prior to the first iteration of the loop. Here,i = j = 1, and S is completely empty. L[1] is the smallest element of L, while R[1] is the smallest element of R, so the initialization step holds

3.4 Maintenance Step:

Suppose without loss of generality that L[i] ≤ R[j]. Then L[i] is the smallest element not yet copied to S. The current nonempty part of S consists of the k − 1 smallest elements, so after the loop is over and L[i] is copied to S, the nonempty part of S will consist of the k smallest elements. Incrementing k (in the for loop update) and i reestablishes the loop invariant for the next iteration.

3.5 Termination Step:

At termination, k = m+ 1. By the loop invariant, S contains the m smallest elements of L and R, in sorted order. This is the result that we wanted (i.e. the merging of the two sorted arrays to produce a new sorted array).

Add a comment
Know the answer?
Add Answer to:
Prove that the Merge() function of your own merge sort algorithm in the question 2 is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a NOTEPAD or PDF file that restates the problem in your own words, specifies what input is needed, w...

    Create a NOTEPAD or PDF file that restates the problem in your own words, specifies what input is needed, what output is expected, the step by step process (algorithm) to get the output from the input, and test data (input for which you know the expected output) for each of the 3 problems given below. You should not write any actual C++ code. Make sure the problem statement is in your own words and is descriptive enough so someone not...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

  • Please help! Your task is to select an idea, improvement or opportunity that could be applied...

    Please help! Your task is to select an idea, improvement or opportunity that could be applied in a business operation. Describe the business and the project you might initiate. You will need to describe and define the project in context. Explain why such a project would be beneficial. What procedures might you use to ensure that the project was sponsored and supported by the organisation? Define the project, write a project narrative and develop a project plan, including the processes...

  • Please help! Your task is to select an idea, improvement or opportunity that could be applied...

    Please help! Your task is to select an idea, improvement or opportunity that could be applied in a business operation. Describe the business and the project you might initiate. You will need to describe and define the project in context. Explain why such a project would be beneficial. What procedures might you use to ensure that the project was sponsored and supported by the organisation? Define the project, write a project narrative and develop a project plan, including the processes...

  • Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of...

    Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of physician-centered and collaborative communication. How is the caregiver’s role different in each model? How is the patient’s role different? Answer: Physical-centered communication involves the specialists taking control of the conversation. They decide on the topics of discussion and when to end the process. The patient responds to the issues raised by the caregiver and acts accordingly. On the other hand, Collaborative communication involves a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT