notes13d

Iterate repeatedly through the list and swap the

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: [3,4,9,7,6] – 3 is compared to [4,9]. It is less than 9 and 4 so it is inserted in 3 [3,4,7,9,6] – 7 is compared to [3,4,9]. It is less than 9 but greater than 7 4 [3,4,6,7,9] – 6 is compared to [3,4,7,9]. It is less than 7 but greater than 4 n n - 1 Time Complexity: Worst Case - O(n ²) Best Case – O(n) – Already sorted Bubble Sort 1. Iterate repeatedly through the list and swap the adjacent item, if they are not in order Example: [4,9,3,7,6]...
View Full Document

Ask a homework question - tutors are online