Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please come up with original solution, without copy-pasting it from already give answers int partition (int arr[), int first, int last) int mid first int

image text in transcribed

Please come up with original solution, without copy-pasting it from already give answers

int partition (int arr[), int first, int last) int mid first int pivot-arrfirst]a for lint sweep-first+1 sweeplast: sweep++) // Assertion: .. if larrsweep pivot) int tmparr[sweep] arr Isweeparr [mid+1] arr [mid+11-tmpi mid++ // Post:..' arrlfirstarr[mid] azrlmid]pivot return mid; The focus for this problem will be the main loop of partition. You will make arguments about what it attempts to accomplish. a) 3 marks] The diagram depicts what we hope is the state of arrfirst..last] just after the main loop terminates [but before the pivot is swapped into place]. Write down a post-condition that effectively summarizes the values and locations of the array elements, as they relate to indices first, last and mid. first mid last ivot 2 piv b) 3 marks] Write an assertion that is true at the beginning of each loop. Just like you did for part (a), it should summae the values and locations of the array elements, as they relate to al indices, i.e., first, last, mid, but also sweep Hint: Your answer is probably correct if, when you substitute sweeplast 1, it matches your answer to part (a) c) 5 marks] Prove that the partition algorithm is correct using the initialization-maintenance- termination technique shown in class

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

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

2. How can competencies be used in employee development?

Answered: 1 week ago