Just got off Eclipse...here is the result i got for few data and different sorting algoritm.. ins
Normal Bubbleelapsed--6435455
1>1>1>3>4>6>6>6>10>13>15>18>18>19>21>21>21>22>23>23>23>25>26>27>28>29>29>29>31>31>31>33>33>33>35>36>36>36>36>37>38>39>41>44>44>44>45>45>45>45>48>49>50>51>51>52>53>53>53>53>53>61>64>64>64>64>65>65>66>66>66>66>66>67>67>68>68>69>72>73>74>77>77>79>79>80>80>80>81>81>81>82>83>84>85>85>85>85>85>88>88>88>88>88>90>90>92>94>95>95>96>96>99>100>100>
Decreasing n/window elapsed--22908
1>1>1>3>4>6>6>6>10>13>15>18>18>19>21>21>21>22>23>23>23>25>26>27>28>29>29>29>31>31>31>33>33>33>35>36>36>36>36>37>38>39>41>44>44>44>45>45>45>45>48>49>50>51>51>52>53>53>53>53>53>61>64>64>64>64>65>65>66>66>66>66>66>67>67>68>68>69>72>73>74>77>77>79>79>80>80>80>81>81>81>82>83>84>85>85>85>85>85>88>88>88>88>88>90>90>92>94>95>95>96>96>99>100>100>
Cocktail Sort elapsed--22908
1>1>1>3>4>6>6>6>10>13>15>18>18>19>21>21>21>22>23>23>23>25>26>27>28>29>29>29>31>31>31>33>33>33>35>36>36>36>36>37>38>39>41>44>44>44>45>45>45>45>48>49>50>51>51>52>53>53>53>53>53>61>64>64>64>64>65>65>66>66>66>66>66>67>67>68>68>69>72>73>74>77>77>79>79>80>80>80>81>81>81>82>83>84>85>85>85>85>85>88>88>88>88>88>90>90>92>94>95>95>96>96>99>100>100>
Insertion Sort elapsed--18159
1>1>1>3>4>6>6>6>10>13>15>18>18>19>21>21>21>22>23>23>23>25>26>27>28>29>29>29>31>31>31>33>33>33>35>36>36>36>36>37>38>39>41>44>44>44>45>45>45>45>48>49>50>51>51>52>53>53>53>53>53>61>64>64>64>64>65>65>66>66>66>66>66>67>67>68>68>69>72>73>74>77>77>79>79>80>80>80>81>81>81>82>83>84>85>85>85>85>85>88>88>88>88>88>90>90>92>94>95>95>96>96>99>100>100>
Let me explain what insertion does best. It tries to select a certain window and sorts that window and anything added to that window and slowly increases the window till it covers all. The worse case will be when the sequence is reverse and each entry needs to be move to the right, ie each window needs to sort. Here is such an example-->
Input array {100,50,40,30,20,10,9,8,7,6,5};
Normal elapsed--1939912
5>6>7>8>9>10>20>30>40>50>
Decreasing n/window elapsed--9778
5>6>7>8>9>10>20>30>40>50>
Cocktail Sort elapsed--10896
5>6>7>8>9>10>20>30>40>50>
Insertion Sort elapsed--10057
5>6>7>8>9>10>20>30>40>50>
As you can see, there isn't much significant difference between the last 3 because of the order of the array. It seems to tend to the same complexity O(n2). Here is a good site for this-->http://www.iti.fh-flensburg.de/lang/algorithmen/sortieren/insert/insertionen.htm
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment