Question: Trace the PresortMode algorithm with the array A = [11, 14, 12, 13, 12, 11, 12, 14, 13, 12]. What is the modevalue, modefrequency, and
Trace the PresortMode algorithm with the array A = [11, 14, 12, 13, 12, 11, 12, 14, 13, 12]. What is the modevalue, modefrequency, and runvalue after three iterations of the outer while loop?(please show all steps)
PresortMode(A[0..n 1])
Sort the array A;
i = 0;
while (i <= n 1) do
{
runlength = 1; runvalue = A[i];
while (i + runlength <= n 1 AND A[i + runlength] = runvalue) do
runlength = runlength + 1;
if (runlength > modefrequency)
{
modefrequency = runlength;
modevalue = runvalue;
}
i = i + runlength;
}
return modevalue;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
