Docsity

QuickSelect Algorithm: A Step-by-Step Visual Guide, Lecture notes of Data Structures and Algorithms

Partial preview of the text

Download QuickSelect Algorithm: A Step-by-Step Visual Guide and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

Select the pivot at the right-most index

Swap the two values.

L R

L R

L H

L H

Move the left index up until we find a

value larger than the pivot.

L

R

L R

L H

L H

Move the right index down until we find a

value smaller than the pivot.

Move the left index up until we find a

value larger than the pivot.

L R

L

R

L H

L H

Move the right index down until we land

on the left index.

L

R

L H

L H

Swap the pivot to this point.

L R

L H

H

L

Move the left index up until we find a

value larger than the pivot.

L

Move the right index down until we find a

value smaller than the pivot.

L R

L H

H

L

L

Swap the two values.

L

H

Because we are at index 3, move the Low

index value up.

R L

L

H

Note that the right is below the left. The pivot

is in the correct spot.

We now have placed a pivot at the the target index.