-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSORTING_ALGORTIHMS_ANALYSIS
304 lines (245 loc) · 6.19 KB
/
SORTING_ALGORTIHMS_ANALYSIS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
+------------------------------------------------------------+
| @tittle: Sorting Algorithms Analysis
|
| @author: Sergio Penavades Suarez
|
| @date: 12/29/2016
|
| @version: 1.0
+------------------------------------------------------------+
---------------
I-Introduction
---------------
A sorting algorithm is an algorithm that receives a list/array of elements and put them in a numerical order. The output of the algorithm is in nondecreasing order and it is a permutation of the input.
# Algortihm properties:
------------------------
-Worst-case key comparisions: number of comparisions for worst-case.
-Worst-case swaps: number of swaps for worst-case.
-Memory usage(in-place): requires a constant amount of additional space. An in-place sort needs only O(1) memory beyond the items being sorted; sometimes O(log(n)) additional memory is considered "in-place".
-Recursion: some algorithms are either recursive or non-recursive, while others may be both.
-Stability: preserves the order of items in the array that are equal.
-Comparision Sort: examines the data only by comparing two elements with a comparison operator.
-Adaptability: the algorithm performance improves the more sorted the list is initially.
# The ideal sorting algorithm would have the following properties:
-------------------------------------------------------------------
Worst-case O(n·lg(n)) key comparisons.
Worst-case O(n) swaps.
Operates in place, requiring O(1) extra space.
Stable: Equal keys aren’t reordered.
Adaptive: Speeds up to O(n) when data is nearly sorted or when there are few unique keys.
There is no algorithm that has all of these properties, and so the choice of sorting algorithm depends on the application.
---------------------------------
II-Algorithms subject to analysis
---------------------------------
# Comparison algorithms
------------------------
-Selection sort
-Heapsort
-Insertion sort
-Shell sort
-Bubble sort
-Cocktail sort
-Comb sort
-Odd-even sort
-Gnome sort
-Merge sort
-Merge Bottom-up sort
-Quicksort
-Quicksort three way partition
# Non-comparison algorithms
----------------------------
-Bucket sort
-Counting sort
-Radix sort (LSD)
-------------------
III-Selection sort
-------------------
# Characteristics
-----------------
-Type: Selection
-Time worst-case: n^2
-Time best-case: n^2
-Time average: n^2
-Memory usage: 1
-Stable: NO
-Adaptive: NO
------------
IV-Heapsort
------------
# Characteristics
-----------------
-Type: Selection
-Time worst-case: n log(n)
-Time best-case: n log(n)
-Time verage: n log(n)
-Memory usage: 1
-Stable: NO
-Adaptive: NO(no really adaptative)
-----------------
V-Insertion sort
-----------------
# Characteristics
-----------------
-Type: Insertion
-Time worst-case: n^2
-Time best-case: n
-Time average: n^2
-Memory usage: 1
-Stable: YES
-Adaptive: O(n) time when nearly sorted
--------------
VI-Shell sort
--------------
# Characteristics
-----------------
-Type: Insertion
-Time worst-case: n log(n)^2
-Time best-case: n log(n)
-Time average: n log(n)^2 or n^(5/4)
-Memory usage: 1
-Stable: NO
-Adaptive: O(n·lg(n)) time when nearly sorted
----------------
VII-Bubble sort
----------------
# Characteristics
-----------------
-Type: Exchanging
-Time worst-case: n^2
-Time best-case: n
-Time average: n^2
-Memory usage: 1
-Stable: YES
-Adaptive: O(n) when nearly sorted
-------------------
VIII-Cocktail sort
-------------------
# Characteristics
-----------------
-Type: Exchanging
-Time worst-case: n^2
-TIme best-case: n
-Time average: n^2
-Memory usage: 1
-Stable: YES
-Adaptive:
-------------
IX-Comb sort
-------------
# Characteristics
-----------------
-Type: Exchanging
-Time worst-case: n^2
-Time best-case: n log(n)
-Time average: n^2
-Memory usage: 1
-Stable: NO
-Adaptive:
----------------
X-Odd-even sort
----------------
# Characteristics
-----------------
-Type: Exchanging
-Time worst-case: n^2
-Time best-case: n
-Time average: n^2
-Memory usage: 1
-Stable: YES
-Adaptive:
--------------
XI-Gnome sort
--------------
# Characteristics
-----------------
-Type: Exchanging
-Time worst-case: n^2
-Time best-case: n
-Time average: n^2
-Memory usage: 1
-Stable: YES
-Adaptive:
---------------
XII-Merge sort
---------------
# Characteristics
-----------------
-Type: Exchanging
-Time worst-case: n log(n)
-Time best-case: n log(n)
-Time average: n log(n)
-Memory usage: n
-Stable: YES
-Adaptive: NO
--------------------------
XIII-Merge Bottom-up sort
--------------------------
# Characteristics
-----------------
-Type: Exchanging
-Time worst-case: n log(n)
-Time best-case: n log(n)
-Time average: n log(n)
-Memory usage: n
-Stable: YES
-Adaptive: NO
--------------
XIV-Quicksort
--------------
# Characteristics
-----------------
-Type: Exchanging
-Time worst-case: n^2
-Time best-case: n log(n)
-Time average: n log(n)
-Memory usage: log(n) on average and n in worst-case
-Stable: NO
-Adaptive: NO
----------------------------------
XIV-Quicksort three way partition
----------------------------------
# Characteristics
-----------------
-Type: Exchanging
-Time worst-case: n^2
-Time best-case: n log(n)
-Time average: n log(n)
-Memory usage: log(n)
-Stable: NO
-Adaptive: O(n) time when O(1) unique keys
-------------------------
XV-Bucket sort
-------------------------
# Characteristics
-----------------
-Type: Distribution
-Time worst-case: n^2
-Time best-case: n + k (k is the number of buckets)
-Time average: n + k (k is the number of buckets)
-Memory usage: n + k (k is the number of buckets)
-Stable: YES
-Adaptive: -
-------------------------
XVI-Counting sort
-------------------------
# Characteristics
-----------------
-Type: Distribution
-Time worst-case: n + k (k is the number of buckets)
-Time best-case: n + k (k is the number of buckets)
-Time average: n + k (k is the number of buckets)
-Memory usage: k (k is the number of buckets)
-Stable: YES
-Adaptive: -
-------------------------
XVII-Radix sort (LSD)
-------------------------
# Characteristics
-----------------
-Type: Distribution
-Time worst-case: w * n (w is the word size)
-Time best-case: w * n (w is the word size)
-Time average: w * n (w is the word size)
-Memory usage: n + r (r is the radix)
-Stable:
-Adaptive: -