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 -
-
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 -
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!