I don't know how to get comparisons of bubble sort... please help.
And are my answers correct?
Please advice and fix if you believe my answers are wrong... thanks!
IMPORTANT: I don't need any codings. I just want to make sure my answers are correct or not.
Are my selection, insertion, and bubble sort--- are they sorted correctly?Problem statement Given the following array 4 2 7 3 5 1 6
List each *different* state of the array after sorting it in ascending order with:
A) Insertion sort
B ) Selection sort
C) Bubble sort
A. Original array_____________Destination array_______Comparisons
4 2 7 3 5 1 6 (Insertion sort)
2 7 3 5 1 6__________________--4--> 4___________________0
7 3 5 1 6____________________--2--> 2 4 _________________1
3 5 1 6_____________________--7--> 2 4 7 ________________2
5 1 6 ______________________--3--> 2 3 4 7_______________2
1 6________________________--5--> 2 3 4 5 7______________4
6__________________________--1--> 1, 2, 3, 4, 5, 7_________1
___________________________--6--> 1, 2, 3, 4, 5, 6, 7_______6
____________________________________________________= 16 comparisons
B. 4 2 7 3 5 1 6 (Selection sort)
1 2 7 3 5 4 6_________________(get min of 7 elems swap at 0)____7
1 2 7 3 5 4 6_________________(get min of 6 elems swap at 1)____6
1 2 3 7 5 4 6_________________(get min of 5 elems swap at 3)____4
1 2 3 4 5 7 6_________________(get min of 4 elems swap at 2)____3
1 2 3 4 5 6 7_________________(get min of 3 elems swap at 1)____1
______________________________________________________= 21 comparisons
4 2 7 3 5 1 6 (Bubble sort)
2 4 7 3 5 1 6_________________(swap if A[i] > A[i+1]) __________1
2 4 3 7 5 1 6_________________(swap if A[i] > A[i+1]) __________dunno
2 3 4 7 5 1 6_________________(swap if A[i] > A[i+1]) __________-
2 3 4 5 7 1 6_________________(swap if A[i] > A[i+1]) __________-
2 3 4 5 1 7 6_________________(swap if A[i] > A[i+1]) __________dunno
2 3 4 1 5 7 6_________________(swap if A[i] > A[i+1]) __________dunno
2 3 1 4 5 7 6_________________(swap if A[i] > A[i+1]) __________help!
2 1 3 4 5 7 6_________________(swap if A[i] > A[i+1]) __________help!
1 2 3 4 5 6 7_________________(swap if A[i] > A[i+1]) __________help!
________________________________________________________= help me find total comparisons of bubble sort
This post has been edited by kelliethile: 10 Dec, 2007 - 08:12 PM