0% found this document useful (0 votes)
7 views1 page

Bubble and Insertion Sort Exercises

The document contains exercise questions focused on analyzing the complexity of Bubble Sort and Insertion Sort algorithms. It includes specific tasks such as performing step-by-step sorting on given arrays and calculating time complexities for different scenarios. The exercises aim to enhance understanding of sorting algorithms and their efficiency in various cases.

Uploaded by

Gatleen Kaur
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Bubble and Insertion Sort Exercises

The document contains exercise questions focused on analyzing the complexity of Bubble Sort and Insertion Sort algorithms. It includes specific tasks such as performing step-by-step sorting on given arrays and calculating time complexities for different scenarios. The exercises aim to enhance understanding of sorting algorithms and their efficiency in various cases.

Uploaded by

Gatleen Kaur
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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?

You might also like