Answered step by step
Verified Expert Solution
Question
1 Approved Answer
An alternative for the PivotList algorithm would be to have two indices into the list. The first moves up from the bottom and the other
An alternative for the PivotList algorithm would be to have two indices
into the list. The first moves up from the bottom and the other moves down
from the top. The main loop of the algorithm will advance the lower index
until a value greater than the Pivotvalue is found, and the upper index is
moved until a value less than the PivotValue is found. Then these two are
swapped. This process repeats until the two indices cross. These inner loops
are very fast because the overhead of checking for the end of the list is elim
inated, but the problem is that they will do an extra swap when the indices
pass each other. So the algorithm does one extra swap to correct this. The
full algorithm is
Pivothist list, first, last
list the elements to work with
first the index of the first element
last the index of the last element
Pivotvalue list first
lower first
upper ast
do
do upper upper until list upper PivotValue
do lower lower until list lower Pivotvalue
Swap ist upper ist lower
until lower upper
undo the extra exchange
Swap list upper list lower
move pivot point into correct place
Swap list first list upper
return upper
c What operation is done significantly less frequently for this version of
PivotList?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started