Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the sorting algorithm shown below, which is called bubblesort. Algorithm 1 . 1 6 bubblesort Input: An array A [ 1 . . n
Consider the sorting algorithm shown below, which is called bubblesort.
Algorithm bubblesort
Input: An array An of n elements.
Output: An sorted in nondecreasing order.
i; sorted false
while i n and not sorted
sorted true
for j n downto i
if Aj Aj then
interchange Aj and Aj
sorted false
end if
end for
i i
end while
a What is the minimum number of element comparisons performed
by the algorithm? When is this minimum achieved?
b What is the maximum number of element comparisons performed
by the algorithm? When is this maximum achieved?
c What is the minimum number of element assignments performed
by the algorithm? When is this minimum achieved?
d What is the maximum number of element assignments performed
by the algorithm? When is this maximum achieved?
e Express the running time of Algorithm bubblesort in terms of the
O and notations.
f Can the running time of the algorithm be expressed in terms of the
Theta notation? Explain.
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