Tutorial 4
Exercise Questions on Bubble Sort Complexity Analysis
Question 1:
Given the following array, perform a step-by-step Bubble Sort and determine the number of
comparisons and number of swaps required to sort the array in ascending order.
Array: [5, 2, 9, 1, 5, 6]
Question 2:
Bubble Sort has a time complexity of O(n²) in the worst case. Given that an input array of size
n=1000 requires 5 milliseconds to sort, how much time would it take to sort an array of size
n=5000 in the worst case? Assume that the time complexity is proportional to n2.
Exercise Questions on Insertion Sort Complexity
Analysis
Question 1:
Given the array [12, 11, 13, 5, 6], perform a step-by-step Insertion Sort and determine the
number of comparisons and number of shifts (or swaps) required to sort the array in ascending
order.
Question 2:
Consider an array of size n=2000 that is already sorted in ascending order. What will be the
time complexity of Insertion Sort for this array? How many comparisons will Insertion Sort
make?