L1 = [9, 8, 7, 6, 5, 4, 3, 2, 1]
L2 = [8, 1, 3, 6, 9, 7, 4, 2, 5]
Would L1 cause bubblesort to do more swaps since the elements are in non-ascending order? I don’t really understand what determines bubblesort to do more/less swaps.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, L2 would make Bubble-sort do more swaps. Bubble-sort is seriously slowed down by
turtles(i.e., small numbers near the end of the list).Rabbits(i.e., large numbers near the beginning of the code) get swapped quickly and don’t matter while turtles move forward in the list slowly, once w/ every iteration.That’s why you almost never never use bubblesort in any heavy-duty sorting code. Introsort and Cocktail Sort are better variations of bubble-sort.
I don’t get why you’re asking this question here, and why you’ve tagged this question w/
python(though that is the only reason I saw this question in the first place).