Answered step by step
Verified Expert Solution
Link Copied!

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 =1 ast +1
do
do upper = upper -1 until list [upper] PivotValue
do lower = lower +1 until list [lower] Pivotvalue
Swap (1ist [ upper ],1ist [ 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?
image text in transcribed

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions