Question: Question 3 Given the following algorithm, MyAlgorithm, analyze what the algorithm does then answer the questions below. Algorithm MyAlgorithm ( A , n ) Input:
Question
Given the following algorithm, MyAlgorithm, analyze what the algorithm does then answer the
questions below.
Algorithm MyAlgorithmA n
Input: Array of integer containing n elements
Output: Possibly modified Array A
done true
j
while j n do
if Aj Aj then
swapAj Aj
done: false
j j
end while
j n
while j do
if Aj Aj then
swapAj Aj
done: false
j j
end while
if done
MyAlgorithmA n
else
return A
a Trace handrun MyAlgorithm for an array A You do not need to show every
single step of the trace What is the resulting A
b What is the BigO On and BigOmega Omega n time complexity for algorithm MyAlgorithm
below in terms of n Explain how you concluded such complexity.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
