Skip to content

Commit 473d0c7

Browse files
committed
Test almost sorted
1 parent d8fd039 commit 473d0c7

8 files changed

+75
-9
lines changed

Report.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,74 @@ Regression analysis will also be performed on the results of running time experi
161161

162162
## **Testing Results**
163163

164+
Testing results of different sorting algorithms will be shown for the following distribution. **Note** that shell sort and annealing sort are tested over different parameters.
165+
166+
For shell sort, it is tested using the following gap sequences.
167+
168+
* Shell 1 (Gap 1): [1601, 801, 300, 132, 57, 10, 1]
169+
170+
* Shell 2 (Gap 2): [600, 280, 75, 25, 8, 1]
171+
172+
* Shell 3 (Gap 3): [148, 99, 50, 1]
173+
174+
* Shell 4 (Gap 4): [256, 128, 64, 32, 16, 8, 4, 2, 1]
175+
176+
* Shell 5 (Gap 5): [200, 190, 180, 170, 160, 150]
177+
178+
* Shell 6 (Gap 6): [887, 510, 377, 233, 144, 89, 55, 34, 21, 13, 8, 5, 3, 2, 2, 1]
179+
180+
For annealing sort, it is tested over the following temparature and repetition sequences.
181+
182+
* Annealing 1 (Temp 1: [1600, 800, 400, 200, 100, 50, 25, 0], Rep 1: [5, 5, 5, 5, 5, 5, 5, 0])
183+
184+
* Annealing 2 (Temp 2: [1000, 800, 600, 400, 200, 0], Rep 2: [2, 2, 2, 2, 2, 0])
185+
186+
* Annealing 3 (Temp 3: [1024, 512, 216, 128, 64, 32, 16, 8, 4, 2, 1, 0], Rep 3: [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0])
187+
188+
* Annealing 4 (Temp 4: [929, 243, 81, 27, 9, 3, 0], Rep 4: [2, 2, 2, 2, 2, 2, 0])
189+
190+
* Annealing 5 (Temp 5: [256, 64, 16, 4, 0], Rep 5: [5, 5, 5, 5, 0])
191+
192+
* Annealing 6: (Temp 6: [1000, 850, 700, 550, 400, 250, 0], Rep 6: [3, 3, 3, 3, 3, 3, 0])
193+
164194
### Uniformly distributed permutations
165195

196+
In this section, the input testing data is permuted using uniformly distributed permutation.
197+
198+
1. The graph below shows the running time of different algorithms on increasing problem size. For shell sort and annealing sort, only the best two cases are shown in this graph.
199+
200+
![uniform sort](./uniform-sort.png)
201+
202+
Among all the sorting algorithms tested, annealing 4 is the fastest.
203+
204+
2. Perform regression analysis of the running time experiements. For shell sort and annealing sort, only the best two cases are shown in this graph.
205+
206+
![uniform regression](./uniform-regression.png)
207+
208+
Regression analysis also shows annealing 4 has the smallest slope on log-log scale which means it is the fastest.
209+
210+
3. The following graph shows the running time of shell sort over all different gap sequences above:
211+
212+
![shell sort](./uniform-shell.png)
213+
214+
The best two cases of shell sort are: shell 1 and shell 2. And shell 1 is even faster than shell 2. Overall, gap sequence: [1601, 801, 300, 132, 57, 10, 1] has the best performance.
215+
216+
4. The following graph shows the running time of annealing sort over all different temparature sequences and repetition sequences above:
217+
218+
![shell sort](./uniform-annealing.png)
219+
220+
The best two cases of annealing sort are: annealing 2 (orange line) and annealing 4 (red line). The lines of these two different parameters almost overlapped. Annealing 4 is a little bit better than annealing 2.
221+
222+
Annealing 4 has temparature sequence: [929, 243, 81, 27, 9, 3, 0] and reqetition sequence: [2, 2, 2, 2, 2, 2, 0]
223+
166224
### Almost-sorted permutations
167225

168-
## **Conclusion**
226+
In this section, the input testing data is almost sorted by independently choosing 2logn pairs, (i, j), where i and j are uniformly-chosen random integers in the range from 0 to n-1, and swap the numbers at positions i and j in the array/vector.
227+
228+
1. The graph below shows the running time of different algorithms on increasing problem size.
229+
230+
2. Regression analysis of the running time experiements
231+
232+
3. The following graph shows the running time of shell sort over all different gap sequences:
233+
234+
4. The following graph shows the running time of annealing sort over all different temparature sequences and repetition sequences:

main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ vector<int> get_random_shuffled_int_vector(int n)
2626
vector<int> vec = vector<int>(n);
2727
for(int i = 0; i < n; i++)
2828
vec[i] = (i + 1);
29-
shuffle_vector(vec);
30-
// almost_sorted_vector(vec); // Use this line to generate almost sorted array
29+
// shuffle_vector(vec);
30+
almost_sorted_vector(vec); // Use this line to generate almost sorted array
3131
return vec;
3232
}
3333

@@ -140,13 +140,13 @@ int main()
140140
const vector<int>& temps1{1600, 800, 400, 200, 100, 50, 25, 0};
141141
const vector<int>& temps2{1000, 800, 600, 400, 200, 0};
142142
const vector<int>& temps3{1024, 512, 216, 128, 64, 32, 16, 8, 4, 2, 1, 0};
143-
const vector<int>& temps4{243, 81, 27, 9, 3, 0};
143+
const vector<int>& temps4{929, 243, 81, 27, 9, 3, 0};
144144
const vector<int>& temps5{256, 64, 16, 4, 0};
145145
const vector<int>& temps6{1000, 850, 700, 550, 400, 250, 0};
146146
const vector<int>& repetitions1{5, 5, 5, 5, 5, 5, 5, 0};
147147
const vector<int>& repetitions2{2, 2, 2, 2, 2, 0};
148148
const vector<int>& repetitions3{7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0};
149-
const vector<int>& repetitions4{2, 2, 2, 2, 2, 0};
149+
const vector<int>& repetitions4{2, 2, 2, 2, 2, 2, 0};
150150
const vector<int>& repetitions5{5, 5, 5, 5, 0};
151151
const vector<int>& repetitions6{3, 3, 3, 3, 3, 3, 0};
152152

plotting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ def plot_timings_from_file(fname_list):
1414
x = n
1515
y = seconds
1616
plt.loglog(x=x, y=y, basex=2, basey=2)
17-
plt.plot(x, y, label=fname)
17+
plt.plot(x, y, label=fname.rstrip(".csv"))
1818

1919

2020
plt.xlabel('# of elements')
2121
plt.ylabel('time in seconds')
2222
plt.title('Performance of sort')
2323
plt.legend()
2424
plt.show()
25-
#plt.savefig('run.png')
25+
# plt.savefig('uniform-shell.png')
2626
plt.close()
2727

28-
plot_timings_from_file(["bubble.csv", "insertion.csv", "shell1.csv", "shell2.csv", "annealing1.csv"])
28+
plot_timings_from_file(["bubble.csv", "insertion.csv", "spin.csv", "shell1.csv", "shell2.csv", "annealing2.csv", "annealing4.csv"])

regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def plot_regression_lines(fname):
3030
m, b = get_regression_line_coefficients(n, seconds)
3131
plt.plot(x, m*x + b, label=f'{fname.rstrip(".csv")}: y ~ {round(m, 2)}x + {round(b, 2)}')
3232

33-
file_list = ["bubble.csv", "insertion.csv", "shell1.csv", "shell2.csv", "spin.csv"] # TODO: annealing1.csv, annealing2.csv
33+
file_list = ["bubble.csv", "insertion.csv", "spin.csv", "shell1.csv", "shell2.csv", "annealing2.csv", "annealing4.csv"]
3434

3535
# Plot graph
3636
plt.subplot(2, 1, 1)

uniform-annealing.png

106 KB
Loading

uniform-regression.png

92.5 KB
Loading

uniform-shell.png

99.2 KB
Loading

uniform-sort.png

104 KB
Loading

0 commit comments

Comments
 (0)