Question: 8. Algorithm Design: Iterative (13 points) An iterative strategy to move any and all zeroes in an array A of n numbers, n1, to the

8. Algorithm Design: Iterative (13 points) An iterative strategy to move any and all zeroes in an array A of n numbers, n1, to the left end of the array: 1. Let leftp be a pointer to the leftmost index of A and rightp be a pointer to the rightmost index of A. 2. Move leftp right until leftp is pointing to a cell containing a non-zero number or leftp reaches the right end of A. 3. Move rightp left until rightp is pointing to a cell containing a zero or r reaches the left end of A. 4. If leftp and rightp are not equal or have not crossed (passed) each other, swap the numbers in cells pointed to by leftp and rightp and repeat 2-4. 5. If leftp and rightp are equal or have crossed (passed) each other then stop. The corresponding iterative algorithm is given in part below. Complete it.

Move-zeroes-iterative(A: array [p..r] of number, rp0)

1. leftp = p; rightp = r

2. repeat

3. swap(A[leftp], A[rightp])

4. while leftpr and ___________

5. __________

6. while rightpp and __________

7. ______________

8. until_____________

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!