Bubble sort pseudocode: Bubblesort (A, n) // A is array, n items to sort For i = n-1 to 1 For j = 1 to i If A[j] < A[j+1] Swap (A[j], A[j+1]) (A) Determine the big-O running time (tight bound) of bubble sort in the left column. Show your derivation. This pseudocode assumes the array starts at index 1. Count comparisons as the critical operation. Your solution should count the exact number of comparisons as a function of n (number of items being sorted). In converting your formula for number of comparisons to a closed-form formula (as opposed to a summation formula), you do not need to show the derivation (such as writing the summation twice and dividing by two), though it is okay to do that. You do need to show the closed-form formula for exact number of comparisons, before simplifying it to a big-O representation. As a reference, study the stairs examples in the book. See figure 1.2, pg. 20.
Bubble sort pseudocode: Bubblesort (A, n)
// A is array, n items to sort
For i = n-1 to 1
For j = 1 to i If A[j] < A[j+1]
Swap (A[j], A[j+1])
(A) Determine the big-O running time (tight bound) of bubble sort in the left column. Show your derivation. This pseudocode assumes the array starts at index 1. Count comparisons as the critical operation. Your solution should count the exact number of comparisons as a function of n (number of items being sorted). In converting your formula for number of comparisons to a closed-form formula (as opposed to a summation formula), you do not need to show the derivation (such as writing the summation twice and dividing by two), though it is okay to do that. You do need to show the closed-form formula for exact number of comparisons, before simplifying it to a big-O representation.
As a reference, study the stairs examples in the book. See figure 1.2, pg. 20.
(B) Prove that f(n) = 1000n5 + 20000n2 + 32 is O(n6 ); Is this a tight upper bound? Why or why not?
Trending now
This is a popular solution!
Step by step
Solved in 2 steps