Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.
The following problems refer to Snailsort. We want to count the number of comparisons. For each problem write out a summation and then simplify the...
The following problems refer to Snailsort. We want to count the number of comparisons. For
each problem write out a summation and then simplify the summation. Make your analyses as
exact as possible.
i <- 1
while i < n do
if a[i]>a[i+1] then
a[i] <-> a[i+1]
i <- 1
else
i <- i+1
end if
end while
Problem 1.
(a) What is the best case?
(b) What is the worst case?
(c) Challenge problem (will not be graded). What is the average case?
Problem 2. Assume you start with a sorted list. Pick two distinct elements at random and inter-
change them.
(a) What is the best case?
(b) What is the worst case?
(c) What is the average case?