Identify and justify the asymptotic run time of this algorithm in terms of n. Nm un stepRightUp(A,n) 1 for i = 1 to n -

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Identify and justify the asymptotic run time of this algorithm in terms of n. Nm un stepRightUp(A,n) 1 for i = 1 to n -

Post by answerhappygod »

Identify And Justify The Asymptotic Run Time Of This Algorithm In Terms Of N Nm Un Steprightup A N 1 For I 1 To N 1
Identify And Justify The Asymptotic Run Time Of This Algorithm In Terms Of N Nm Un Steprightup A N 1 For I 1 To N 1 (65.78 KiB) Viewed 47 times
Identify and justify the asymptotic run time of this algorithm in terms of n. Nm un stepRightUp(A,n) 1 for i = 1 to n - 1 2 for j = 1 to n - 1 3 if A[j] > A[j + 1] 4 temp = A[j] 5 A[j] = A[j + 1] 6 A[j + 1] = temp A. Line 1 for loop runs O(n) times; line 2 for loop runs O(n) times; lines 3-6 can run up to O(n) times; multiply these together to get O(n*n*n) = O(n3) B. Line 1 for loop runs O(n) times; line 2 for loop runs O(n) times; lines 3-6 are o(1); multiply these together to get O(n*n*1) = O(n2) C. Line 1 for loop runs O(n) times; line 2 for loop runs O(n) times; lines 3-6 are 0(1); add these together to get O(n+n+1) = O(n) D. Due to test in line 3, asymptotic run time depends on whether the data is sorted or not. O E. Line 1 for loop runs O(n) times; line 2 for loop runs O(n) times; lines 3-6 can run up to O(n) times; add these together to get (n+n+n) = O(n)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply