### Partition algorithm problem

Verfasst:

**Mi 8. Nov 2017, 11:51**I need help to solve this algorighm.

1. Let p be the position in the array such that a[p] is the median

of a[left], a[m], and a[right] (where m is about midway

between left and right).

2. If p is not equal to left, swap a[p] and a[left].

3. Set pivot to a[left].

4. Set i = left + 1 and j = right.

5. While i ≤ j, repeat:

5.1. While i ≤ j and a[i] ≤ pivot, increment i.

5.2. While j ≥ i and a[j] ≥ pivot, decrement j.

5.3. If i < j, swap a[i] and a[j].

6. If j * left, set a[left] to a[j], and a[j] to pivot.

7. Terminate with answer j.

I know how to solve steps 2-7, step number 1 is a bit tricky.But A small part i was able to solve(i think) Can someone get me any clues at all please?

I didn't find the right solution from the internet.

References:

[Links deleted]

1. Let p be the position in the array such that a[p] is the median

of a[left], a[m], and a[right] (where m is about midway

between left and right).

2. If p is not equal to left, swap a[p] and a[left].

3. Set pivot to a[left].

4. Set i = left + 1 and j = right.

5. While i ≤ j, repeat:

5.1. While i ≤ j and a[i] ≤ pivot, increment i.

5.2. While j ≥ i and a[j] ≥ pivot, decrement j.

5.3. If i < j, swap a[i] and a[j].

6. If j * left, set a[left] to a[j], and a[j] to pivot.

7. Terminate with answer j.

I know how to solve steps 2-7, step number 1 is a bit tricky.But A small part i was able to solve(i think) Can someone get me any clues at all please?

I didn't find the right solution from the internet.

References:

[Links deleted]