Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the algorithm DoSomething below a) Can the runtime of DoSomething be improved easily? Explain how (i.e. re-write another solution using Java that does exactly
Consider the algorithm DoSomething below
a) Can the runtime of DoSomething be improved easily? Explain how (i.e. re-write another solution using Java that does exactly what DoSomething is doing more efficiently)? b) Can the space complexity of DoSomething be improved? Explain how?
Algorithm DoSomething (A, n) Input: Array A of integer containing n elements Output: Array M of integer containing n elements 1. for i-0 to n-1 do 2. Zomli]-0 3. end for 4. for i-0 to n-2 do 5. forj-it1 ton-1 do 6. ifAliJKAi] then 7. 8. else .end if 11. end for 12. end for 13. for i-0 to n-1 do 14. MZom [i]]=A[i] 15. end for 16. Return M 10Step 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