-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcmsc351.html
261 lines (261 loc) · 552 KB
/
cmsc351.html
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>cmsc351</title><style type="text/css"> * {margin:0; padding:0; text-indent:0; }
h1 { color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 24.5pt; }
.s1 { color: black; font-family:Calibri, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 14pt; }
.s2 { color: black; font-family:Cambria, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s3 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s4 { color: black; font-family:SimSun; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.p, p { color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; margin:0pt; }
h2 { color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 14pt; }
.s5 { color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt; }
.h4, h4 { color: black; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt; }
.s6 { color: #00F; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s7 { color: #00F; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s8 { color: #00F; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s9 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s10 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; }
h3 { color: black; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 12pt; }
.s11 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; }
.s12 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 8pt; }
.s13 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s14 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; }
.s15 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s16 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s17 { color: black; font-family:"Bookman Old Style", serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 7pt; }
.s18 { color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; }
.s19 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 7pt; }
.s20 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 5pt; }
.s21 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 3pt; }
.s22 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 9pt; }
.s23 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 9pt; }
.s24 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; }
.s25 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -6pt; }
.s26 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: underline; font-size: 10pt; }
.s27 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: underline; font-size: 10pt; }
.s28 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; vertical-align: 6pt; }
.s29 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 9pt; }
.s30 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -7pt; }
.s31 { color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -6pt; }
.s32 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: underline; font-size: 10pt; vertical-align: 6pt; }
.s33 { color: black; font-family:"Times New Roman", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; }
.s34 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 6pt; }
.s35 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; }
.s36 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -7pt; }
.s37 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -7pt; }
.s38 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -10pt; }
.s39 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -3pt; }
.s40 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 4pt; }
.s41 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -9pt; }
.s42 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; vertical-align: -2pt; }
.s43 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -9pt; }
.s44 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 2pt; }
.s45 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -6pt; }
.s46 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; vertical-align: -5pt; }
.s47 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; vertical-align: -10pt; }
.s48 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -4pt; }
.s49 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 17pt; }
.s50 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 7pt; }
.s51 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -1pt; }
.s52 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -4pt; }
.s53 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -1pt; }
.s54 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 7pt; vertical-align: 5pt; }
.s55 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: underline; font-size: 7pt; }
.s56 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: underline; font-size: 7pt; }
.s57 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 7pt; }
.s58 { color: black; font-family:"Times New Roman", serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 7pt; }
.s59 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -3pt; }
.s60 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 5pt; vertical-align: -1pt; }
.s61 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -2pt; }
.s62 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 5pt; }
.s63 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; vertical-align: 4pt; }
.s64 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 5pt; }
.s65 { color: black; font-family:"Times New Roman", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s66 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 1pt; }
.s67 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 5pt; }
.s68 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 3pt; }
.s70 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -3pt; }
.s71 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -4pt; }
.s72 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 11pt; }
.s73 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -11pt; }
.s74 { color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; }
.s75 { color: black; font-family:"Times New Roman", serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; }
.s76 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -3pt; }
.s77 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: underline; font-size: 5pt; }
.s78 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 5pt; vertical-align: 1pt; }
.s79 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 6pt; }
.s80 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: underline; font-size: 7pt; vertical-align: -2pt; }
.s81 { color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; vertical-align: -1pt; }
.s82 { color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 4pt; }
.s83 { color: black; font-family:Calibri, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s84 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: underline; font-size: 7pt; vertical-align: 4pt; }
.s85 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 5pt; vertical-align: -1pt; }
.s86 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -3pt; }
.s87 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; vertical-align: -3pt; }
.s88 { color: #F00; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s89 { color: #F00; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s90 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 4pt; }
.s91 { color: #F00; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -2pt; }
.s92 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -2pt; }
.s93 { color: #F00; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s94 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 2pt; }
.s95 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -4pt; }
.s96 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -8pt; }
.s97 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 11pt; }
.s98 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 5pt; vertical-align: 7pt; }
.s99 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 11pt; }
.s100 { color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -2pt; }
.s101 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 8pt; }
.s102 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 3pt; }
.s103 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -7pt; }
.s104 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -2pt; }
.s105 { color: black; font-family:Arial, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 5pt; }
.s106 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 5pt; vertical-align: -2pt; }
.s107 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -8pt; }
.s108 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 8pt; }
.s109 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: underline; font-size: 10pt; vertical-align: -6pt; }
.s110 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -5pt; }
.s111 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: underline; font-size: 10pt; vertical-align: -3pt; }
.s112 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 5pt; }
.s113 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 4pt; }
.s114 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -5pt; }
.s116 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -5pt; }
.s117 { color: black; font-family:"Times New Roman", serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 5pt; }
.s118 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -6pt; }
.s119 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 3pt; }
.s120 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -4pt; }
.s121 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 14pt; }
.s122 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 5pt; vertical-align: 2pt; }
.s123 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 4pt; }
.s124 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; vertical-align: 6pt; }
.s126 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -14pt; }
.s127 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -11pt; }
.s128 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 5pt; vertical-align: -3pt; }
.s129 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 5pt; vertical-align: -5pt; }
.s130 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 3pt; }
.s131 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 5pt; vertical-align: -3pt; }
.s132 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 5pt; vertical-align: -2pt; }
.s134 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 14pt; }
.s135 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 8pt; }
.s136 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 9pt; }
.s137 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 5pt; vertical-align: 2pt; }
.s138 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 14pt; }
.s139 { color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s140 { color: black; font-family:SimSun; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; }
.s141 { color: black; font-family:SimSun; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s142 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -6pt; }
.s143 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 12pt; }
.s144 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 13pt; }
.s145 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 1pt; }
.s146 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 6pt; }
.s147 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -13pt; }
.s148 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 8pt; }
.s149 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -8pt; }
.s150 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -3pt; }
.s151 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -10pt; }
.s152 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -5pt; }
.s153 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 7pt; }
.s154 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 21pt; }
.s155 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; }
.s156 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: underline; font-size: 7pt; vertical-align: 2pt; }
.s157 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 1pt; }
.s158 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 6pt; }
.s159 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 3pt; }
.s160 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 7pt; }
.s161 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; vertical-align: -4pt; }
.s162 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 2pt; }
.s163 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -6pt; }
.s164 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -7pt; }
.s165 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s166 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s167 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s168 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s169 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -3pt; }
.s170 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; }
.s171 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; }
.s172 { color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -3pt; }
.s173 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 5pt; vertical-align: 6pt; }
.s174 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 5pt; vertical-align: 6pt; }
.s175 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 1pt; }
.s176 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 1pt; }
.s177 { color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -1pt; }
.s178 { color: black; font-family:"Lucida Sans Unicode", sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s179 { color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 9pt; }
.s180 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -17pt; }
.s181 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 3pt; }
.s182 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -9pt; }
.s183 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -9pt; }
.s184 { color: black; font-family:"Bookman Old Style", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 1pt; }
.s185 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -8pt; }
.s186 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -5pt; }
.s187 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 7pt; vertical-align: 4pt; }
.s188 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 5pt; }
.s189 { color: black; font-family:"Lucida Sans Unicode", sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s190 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: 4pt; }
.s191 { color: black; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: underline; font-size: 10pt; }
.s192 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 9pt; }
.s193 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 10pt; vertical-align: 7pt; }
.s194 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: 6pt; }
.s195 { color: black; font-family:Arial, sans-serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 1pt; }
.s196 { color: black; font-family:"Times New Roman", serif; font-style: normal; font-weight: normal; text-decoration: underline; font-size: 7pt; vertical-align: 4pt; }
.s197 { color: black; font-family:Arial, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; }
.s198 { color: black; font-family:"Times New Roman", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 1pt; }
.s199 { color: black; font-family:"Bookman Old Style", serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -8pt; }
.s200 { color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -8pt; }
.s201 { color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 7pt; vertical-align: -8pt; }
li {display: block; }
#l1 {padding-left: 0pt;counter-reset: c1 1; }
#l1> li:before {counter-increment: c1; content: counter(c1, decimal)" "; color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt; }
#l1> li:first-child:before {counter-increment: c1 0; }
#l2 {padding-left: 0pt;counter-reset: c2 1; }
#l2> li:before {counter-increment: c2; content: counter(c2, upper-latin)". "; color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt; }
#l2> li:first-child:before {counter-increment: c2 0; }
li {display: block; }
#l3 {padding-left: 0pt;counter-reset: d1 1; }
#l3> li:before {counter-increment: d1; content: counter(d1, decimal)" "; color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 14pt; }
#l3> li:first-child:before {counter-increment: d1 0; }
li {display: block; }
#l4 {padding-left: 0pt;counter-reset: e1 5; }
#l4> li:before {counter-increment: e1; content: counter(e1, decimal)" "; color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 14pt; }
#l4> li:first-child:before {counter-increment: e1 0; }
#l5 {padding-left: 0pt;counter-reset: e2 1; }
#l5> li:before {counter-increment: e2; content: counter(e2, decimal)" "; color: black; font-style: normal; font-weight: normal; text-decoration: none; }
#l5> li:first-child:before {counter-increment: e2 0; }
li {display: block; }
#l6 {padding-left: 0pt;counter-reset: f1 9; }
#l6> li:before {counter-increment: f1; content: counter(f1, decimal)" "; color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 14pt; }
#l6> li:first-child:before {counter-increment: f1 0; }
#l7 {padding-left: 0pt; }
#l7> li:before {content: "· "; color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; }
#l8 {padding-left: 0pt; }
#l8> li:before {content: "· "; color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; }
#l9 {padding-left: 0pt; }
#l9> li:before {content: "· "; color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; vertical-align: -6pt; }
#l10 {padding-left: 0pt; }
#l10> li:before {content: "• "; color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; }
li {display: block; }
#l11 {padding-left: 0pt;counter-reset: j1 12; }
#l11> li:before {counter-increment: j1; content: counter(j1, decimal)" "; color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 14pt; }
#l11> li:first-child:before {counter-increment: j1 0; }
li {display: block; }
#l12 {padding-left: 0pt;counter-reset: k1 14; }
#l12> li:before {counter-increment: k1; content: counter(k1, decimal)" "; color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 14pt; }
#l12> li:first-child:before {counter-increment: k1 0; }
#l13 {padding-left: 0pt; }
#l13> li:before {content: "• "; color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; }
#l14 {padding-left: 0pt; }
#l14> li:before {content: "– "; color: black; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt; }
#l15 {padding-left: 0pt; }
#l15> li:before {content: "• "; color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; }
#l16 {padding-left: 0pt; }
#l16> li:before {content: "– "; color: black; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt; }
#l17 {padding-left: 0pt; }
#l17> li:before {content: "– "; color: black; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt; }
#l18 {padding-left: 0pt; }
#l18> li:before {content: "– "; color: black; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt; }
#l19 {padding-left: 0pt; }
#l19> li:before {content: "• "; color: black; font-family:Meiryo, sans-serif; font-style: italic; font-weight: normal; text-decoration: none; font-size: 10pt; }
li {display: block; }
#l20 {padding-left: 0pt;counter-reset: l1 1; }
#l20> li:before {counter-increment: l1; content: counter(l1, upper-latin)". "; color: black; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 12pt; }
#l20> li:first-child:before {counter-increment: l1 0; }
</style></head><body><h1 style="padding-top: 4pt;padding-left: 62pt;text-indent: 0pt;line-height: 26pt;text-align: center;">CMSC 351</h1><p class="s1" style="padding-left: 62pt;text-indent: 0pt;line-height: 13pt;text-align: center;">Algorithms</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 225pt;text-indent: 0pt;text-align: left;"><span><img width="85" height="102" alt="image" src="cmsc351/Image_001.gif"/></span></p><p class="s2" style="padding-top: 13pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">Alex Reustle</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">• •</p><p style="text-indent: 0pt;text-align: left;"/><p class="s2" style="padding-left: 62pt;text-indent: 0pt;line-height: 12pt;text-align: center;">Dr. Clyde Kruskal Fall 2017 University of Maryland</p><p style="padding-left: 62pt;text-indent: 0pt;line-height: 13pt;text-align: center;"><a href="http://cs.umd.edu/class/fall2017/cmsc351/" class="s4">http://cs.umd.edu/class/fall2017/cmsc351/</a></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="669" height="1" alt="image" src="cmsc351/Image_002.png"/></span></p><p style="padding-top: 4pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Last Revision: January 6, 2018</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h2 style="padding-left: 7pt;text-indent: 0pt;text-align: left;">Table of Contents</h2><ol id="l1"><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Maximum Subarray Problem</span> 5</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Brute Force solution</span> 5</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Analysis of the Algorithm</span> 5</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Methods to improve integer list summation algorithm.</span> 6</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Timing analysis</span> 6</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Classes of algorithms</span> 6</p><p class="s9" style="padding-left: 44pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><a href="#bookmark15" class="s6">Θ(</a><a href="#bookmark15" class="s7">n</a><a href="#bookmark15" class="s8">2</a><span style=" color: #00F; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">)</span> <span class="p">6</span></p><p class="s9" style="padding-left: 44pt;text-indent: 0pt;line-height: 11pt;text-align: left;"><a href="#bookmark16" class="s6">Θ(</a><a href="#bookmark16" class="s7">n </a><a href="#bookmark16" class="s6">log(</a><a href="#bookmark16" class="s7">n</a><span style=" color: #00F; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">))</span> <span class="p">6</span></p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Others</span> 6</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Bubble Sort Analysis</span> 7</h4><p style="padding-left: 21pt;text-indent: 0pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Average Case Analysis</span> 7</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Insertion Sort with Sentinel</span> 7</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Analysing Number of Comparisons</span> 8</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Best Case Comparisons</span> 8</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Worst Case Comparisons</span> 8</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Average Case Comparisons</span> 8</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Analyzing Exchanges</span> 9</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Best Case Exchanges</span> 9</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Worst Case Exchanges</span> 9</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Average Case Exchanges</span> 9</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Insertion Sort without Sentinel</span> 9</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Best Case Comparisons</span> 10</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Worst Case Comparisons</span> 10</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Average Case Comparisons</span> 10</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Exchanges</span> 10</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Selection Sort</span> 11</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Comparisons</span> 11</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Exchanges</span> 11</p></li><li style="padding-top: 3pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Merge Sort</span> 11</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Merge Comparison analysis</span> 11</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Equal length arrays</span> 11</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Different length arrays</span> 12</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Mergesort Comparison Analysis</span> 12</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Merge Sort Recurrence</span> 12</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Integer Arithmetic</span> 13</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Addition</span> 13</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Problem size</span> 13</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Multiplication</span> 13</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Recursive Multiplication</span> 13</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Better Multiplication</span> 14</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><a href="#bookmark86" class="s5">Recursion Master </a><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Formula</span> 15</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Applying to known algorithms</span> 16</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Multiplication</span> 16</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Better Multiplication</span> 17</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Mergesort</span> 17</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Implementation details</span> 17</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Heapsort</span> 17</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Create Heap</span> 18</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Heap Creation Analysis</span> 18</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Finish</span> 19</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Implementation Details</span> 19</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Optimization</span> 20</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Pseudocode</span> 20</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Finding Bounds to summation functions</span> 21</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Mathematical Preliminaries</span> 21</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Geometric Series</span> 21</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Gauss’s Sum</span> 22</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Harmonic Sum</span> 22</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Using continuous math to solve discrete math</span> 23</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Gauss’s Sum</span> 23</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Harmonic Sum</span> 23</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Order Notation</span> 24</h4></li><li style="padding-top: 10pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Quicksort</span> 26</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Comparison Analysis</span> 26</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Quicksort Worst case comparisons</span> 26</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Quicksort Best case comparisons</span> 26</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Proof by Constructive Induction</span> 27</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Quicksort Worst Case from Recurrence</span> 27</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Quicksort Best Case from Recurrence</span> 28</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Average case analysis of quicksort from approximate recurrence</span> 28</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Average case analysis of quicksort from exact recurrence.</span> 29</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">New Book method</span> 30</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Is Quicksort In place?</span> 30</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Randomized pivot selection</span> 31</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">3 Median Pivot</span> 31</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Small Size Optimization</span> 31</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Algorithm Strengths and Weaknesses</span> 31</h4><p style="padding-left: 21pt;text-indent: 0pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Memory Hierarchy</span> 31</p></li><li style="padding-top: 3pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Linear Sorting Algorithms</span> 31</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Re-evaluating Sort</span> 31</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Find biggest element in array</span> 31</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Find second largest element in array</span> 31</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Find k largest elements in array</span> 31</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Natural approach: Hold a Tournament</span> 32</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Finding Best and Worst</span> 32</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Counting Sort</span> 32</h4></li><li style="padding-top: 10pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Radix Sort</span> 33</h4><p style="padding-left: 21pt;text-indent: 0pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Analysis of running time</span> 33</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><a href="#bookmark177" class="s5">Bucket </a><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Sort</span> 34</h4></li><li style="padding-top: 10pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Selection</span> 34</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Analyzing the recurrence</span> 34</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Lower Bound</span> 34</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Constrained case analysis</span> 35</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Average case Analysis</span> 35</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Finding Median explicitly during selection</span> 36</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Worst Case analysis</span> 36</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Theory</span> 37</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Graph Algorithms</span> 37</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Memory Usage</span> 37</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Edge Lookup</span> 37</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">List all Edges</span> 38</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Take aways</span> 38</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Changing the number of nodes</span> 38</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Adding Nodes</span> 38</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Removing Nodes</span> 38</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Depth First Search</span> 38</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Applications</span> 38</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Breadth First Search</span> 38</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Identifying Connected Components</span> 38</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Bridges of Köningsberg</span> 39</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Trees</span> 39</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Definitions</span> 39</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Minimum Spanning Tree Algorithms</span> 40</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Kruskal’s Algorithm</span> 40</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Prim’s Algorithm</span> 40</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Proof for Kruskal’s and Prim’s Algorithms</span> 40</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><a href="#bookmark236" class="s5">Shortest Path </a><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Algorithms</span> 41</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Dijkstra’s Algorithm</span> 41</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Correctness Proof</span> 41</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Implementation details</span> 42</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">NP-Completeness</span> 42</h4><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Decision Problem Theory</span> 42</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">The Class of NP problems</span> 43</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Reduction</span> 43</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Traveling Salesman Problem</span> 43</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Theory</span> 43</p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Problems between P and NP-Complete</span> 43</p><p style="padding-top: 3pt;padding-left: 21pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Exam Materials</span> 43</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Formula SAT</span> 44</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Graph Coloring Problem</span> 44</p></li><li style="padding-top: 9pt;padding-left: 21pt;text-indent: -14pt;text-align: left;"><h4 style="display: inline;"><span style=" color: #00F; font-family:Georgia, serif; font-style: normal; font-weight: bold; text-decoration: none; font-size: 10pt;">Appendices</span> 45</h4><ol id="l2"><li style="padding-left: 35pt;text-indent: -13pt;line-height: 12pt;text-align: left;"><p style="display: inline;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Transpositions</span> 45</p></li><li style="padding-left: 35pt;text-indent: -13pt;line-height: 12pt;text-align: left;"><p style="display: inline;"><span style=" color: #00F; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;">Summation Properties</span> 45</p></li></ol></li></ol><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="669" height="1" alt="image" src="cmsc351/Image_003.png"/></span></p><ol id="l3"><li style="padding-top: 3pt;padding-left: 30pt;text-indent: -23pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark0">Maximum Subarray Problem</a><a name="bookmark4">‌</a></h2><p style="padding-top: 8pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Given a sequence of integers, find the largest collection which is a sum of adjacent values. Sequence is in an array with indices from 1 to n.</p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 7pt;text-align: center;">3 <span class="s3">− </span>5 4<u> 3 </u><span class="s3">− </span>6 4 8 <span class="s3">−</span>5 3 <span class="s3">− </span>7 2 1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 247pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="22" height="2" alt="image" src="cmsc351/Image_004.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-top: 12pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark1">Brute Force solution</a><a name="bookmark5">‌</a></h3><p class="s12" style="padding-left: 7pt;text-indent: 0pt;line-height: 19pt;text-align: left;"><span class="s11">Sum</span> <span class="s13"> </span><span class="s14">=13 </span>..</p><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;line-height: 88%;text-align: left;">Brute force solution: try every possible sum. (I’d guess it’s <span class="s15">n</span><span class="s16">3</span>) Sum variable M set to zero. We will allow empty sums (no elements, sum = 0).</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-top: 2pt;padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">1 <span class="s15">M </span><span class="s9">0</span><span class="p">;</span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">2 </span>for <span class="s18">i=1 to n</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="114" alt="image" src="cmsc351/Image_005.png"/></span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">3 </span>for <span class="s18">j=i to n</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="81" alt="image" src="cmsc351/Image_006.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">4 <span class="s15">S </span><span class="s9">0</span><span class="p">;</span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">5 </span>for <span class="s18">k=i to j</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="32" alt="image" src="cmsc351/Image_007.png"/></span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">6 </span>S <span class="s9">= </span>S <span class="s9">+ </span>A<span class="s9">[</span>k<span class="s9">]</span><span class="p">;</span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">7 </span>M <span class="s9">= max(</span>M, S<span class="s9">)</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;text-align: left;">8 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 12pt;text-indent: 0pt;text-align: left;">9 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">10 <span class="h4">end</span></p><h4 style="padding-left: 149pt;text-indent: 0pt;line-height: 9pt;text-align: left;">Algorithm 1: <span class="p">Matrix Subarray Brute Force</span></h4><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">),</p><p style="text-indent: 0pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">),</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Insight: Loops in programs are like summation in Mathematics.(for i=1) to n == <span class="s19">),</span><span class="s20">n</span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">j</p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 234pt;text-indent: 0pt;text-align: left;"><span style=" color: black; font-family:"Bookman Old Style", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;"> </span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 183pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p style="padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: left;">Nested loops are nested summations. <span class="s19">),</span><span class="s20">n</span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 183pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s11" style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;line-height: 8pt;text-align: left;">n j<span class="s14">=</span>i</p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 150pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">),</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 7pt;text-indent: 0pt;line-height: 6pt;text-align: left;">k<span class="s14">=</span>i <span class="s21">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 84pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p style="padding-left: 6pt;text-indent: 0pt;line-height: 91%;text-align: left;">Simplify summation using summation algebra from the inside out. <span class="s19">),</span><span class="s20">n</span></p><p class="s11" style="text-indent: 0pt;line-height: 5pt;text-align: center;">n</p><p class="s11" style="padding-left: 62pt;text-indent: 0pt;line-height: 6pt;text-align: center;">j<span class="s14">=</span>i</p><p class="s15" style="text-indent: 0pt;line-height: 11pt;text-align: left;">j <span class="s3">− </span>i <span class="s9">+ 1</span></p><p style="padding-left: 6pt;text-indent: 0pt;line-height: 5pt;text-align: left;">Tangent: since j is the variable, i and 1 are constants. So it can be separated into two sums.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark2">Analysis of the Algorithm</a><a name="bookmark6">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Actual progress: Change a variable to manage sum. Like integrals in calculus. Every technique in calculus for integrations are matched by similar techniques in summations. Change of variable by example. See appendix for examples of summation properties.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-top: 3pt;padding-left: 41pt;text-indent: 0pt;line-height: 2pt;text-align: left;">n n j n n</p><p class="s15" style="padding-top: 5pt;padding-left: 37pt;text-indent: 0pt;text-align: left;"><span class="s22"> </span><span class="s13"> </span><span class="s9">1 =</span><span class="s23"> </span>j <span class="s3">− </span>i <span class="s9">+ 1 </span><span class="p">By adding 1 </span>j <span class="s3">− </span>i <span class="p">times, and fenceposting</span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1 </span>j<span class="s14">=</span>i k<span class="s14">=</span>i</p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1 </span>j<span class="s14">=</span>i</p><p class="s74" style="padding-left: 37pt;text-indent: 0pt;line-height: 7pt;text-align: left;"> </p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1 </span>j<span class="s14">=</span>i k<span class="s14">=</span>i</p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1 </span>j<span class="s14">=</span>i</p><p class="s74" style="padding-left: 37pt;text-indent: 0pt;line-height: 7pt;text-align: left;"> </p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 2pt;text-indent: 0pt;text-align: right;">n</p><p class="s9" style="padding-top: 2pt;text-indent: 0pt;text-align: right;">=</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 2pt;padding-left: 108pt;text-indent: -4pt;line-height: 9pt;text-align: left;">i<span class="s14">=1 </span>n</p><p class="s11" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">n<span class="s24">−</span>i<span class="s14">+1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">j<span class="s14">=1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="text-indent: 0pt;text-align: left;">j <span class="p">By change of variable Method</span></p><p class="s26" style="padding-left: 92pt;text-indent: 0pt;line-height: 36%;text-align: left;"><span class="s25">= </span><span class="s10">(</span>n <span class="s27">− </span>i <span class="s10">+ 1)(</span>n <span class="s27">− </span>i <span class="s10">+ 2)</span></p><p class="s9" style="text-indent: 0pt;line-height: 8pt;text-align: right;">2</p><p style="padding-top: 1pt;padding-left: 92pt;text-indent: 0pt;text-align: left;">Gausses sum</p><p class="s11" style="padding-left: 104pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=1</span></p><p class="s11" style="padding-left: 127pt;text-indent: 0pt;line-height: 2pt;text-align: left;">n</p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 3pt;padding-left: 92pt;text-indent: 0pt;line-height: 87%;text-align: left;">= <u>1</u> <span class="s3">×</span><span class="s29"> </span>(<span class="s15">n </span><span class="s3">− </span><span class="s15">i </span>+ 1)(<span class="s15">n </span><span class="s3">− </span><span class="s15">i </span>+ 2) <span class="p">Expanding is error prone. Change variable instead</span></p><p class="s11" style="padding-left: 123pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=1</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 137pt;text-indent: 0pt;line-height: 5pt;text-align: left;">n</p><p class="s10" style="text-indent: 0pt;line-height: 6pt;text-align: right;">1</p><p class="s9" style="text-indent: 0pt;line-height: 67%;text-align: right;">= <span class="s30">2 </span><span class="s3">×</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 13pt;text-align: left;">n<span class="s24">−</span>i<span class="s14">+1=1</span></p><p class="s11" style="padding-left: 4pt;text-indent: 0pt;line-height: 1pt;text-align: left;">n</p><p class="s15" style="padding-top: 4pt;text-indent: 0pt;text-align: left;">i<span class="s9">(</span>i <span class="s9">+ 1) </span><span class="p">substitute i=n-i+1</span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 3pt;padding-left: 92pt;text-indent: 0pt;line-height: 87%;text-align: left;">= <u>1</u> <span class="s3">×</span><span class="s29"> </span><span class="s15">i</span>(<span class="s15">i </span>+ 1) <span class="p">simplify bounds</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="text-indent: 0pt;line-height: 7pt;text-align: right;">1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_008.png"/></span></p><p class="s9" style="text-indent: 0pt;line-height: 67%;text-align: right;">= <span class="s30">2 </span><span class="s3">×</span></p><p class="s11" style="text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=1</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="91" height="1" alt="image" src="cmsc351/Image_009.png"/></span></p><p class="s15" style="padding-left: 1pt;text-indent: 0pt;line-height: 76%;text-align: left;">n<span class="s9">(</span>n <span class="s9">+ 1)(</span>n <span class="s9">+ 2) </span><span class="s31">magic.</span></p><p class="s9" style="padding-left: 32pt;text-indent: 0pt;line-height: 9pt;text-align: left;">3</p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 9pt;text-align: center;">n<span class="s9">(</span>n <span class="s9">+ 1)(</span>n <span class="s9">+ 2)</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="91" height="1" alt="image" src="cmsc351/Image_010.png"/></span></p><p class="s9" style="padding-left: 92pt;text-indent: 0pt;line-height: 7pt;text-align: left;">=</p><p class="s9" style="text-indent: 0pt;line-height: 9pt;text-align: center;">6</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s12" style="padding-top: 3pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><span class="p">This first method is </span><span class="s9">Θ</span>(<span class="s15">n</span><span class="s16">3</span>)<span class="p">.</span></p><h3 style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark3">Methods to improve integer list summation algorithm.</a><a name="bookmark7">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Remember previous sums, do not recalculate known data.</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-top: 1pt;padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">1 <span class="s15">M </span><span class="s9">0</span><span class="p">;</span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">2 </span>for <span class="s18">i=1 to n</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="81" alt="image" src="cmsc351/Image_011.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">3 <span class="s15">S </span><span class="s9">0</span><span class="p">;</span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">4 </span>for <span class="s18">j = i to n</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="32" alt="image" src="cmsc351/Image_012.png"/></span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">5 </span>S <span class="s9">= </span>S <span class="s9">+ </span>A<span class="s9">[</span>j<span class="s9">]</span><span class="p">;</span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">6 </span>M <span class="s9">= max(</span>M, S<span class="s9">)</span></p><p class="s17" style="padding-top: 1pt;padding-left: 12pt;text-indent: 0pt;text-align: left;">7 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 12pt;text-indent: 0pt;text-align: left;">8 <span class="h4">end</span></p><h4 style="padding-left: 62pt;text-indent: 0pt;text-align: center;">Algorithm 2: <span class="s15">n</span><span class="s16">2 </span><span class="p">Subarray</span></h4><p class="s11" style="padding-left: 168pt;text-indent: 0pt;line-height: 2pt;text-align: left;">n n n n</p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 2pt;padding-left: 163pt;text-indent: 0pt;line-height: 87%;text-align: left;"><span class="s22"> </span><span class="s13"> </span><span class="s9">1 =</span><span class="s23"> </span>n <span class="s3">− </span>i <span class="s9">+ 1 =</span><span class="s23"> </span>i <span class="s9">= </span><u>n</u><span class="s10">(</span><u>n </u><span class="s10">+ 1)</span></p><p class="s12" style="padding-top: 5pt;padding-left: 6pt;text-indent: 0pt;line-height: 20pt;text-align: left;"><span class="p">This new method is </span><span class="s9">Θ</span>(<span class="s15">n</span><span class="s16">2</span>)<span class="p">.</span></p><p class="s11" style="padding-left: 6pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=1 </span>j<span class="s14">=</span>i</p><p class="s11" style="padding-left: 6pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=1</span></p><p class="s11" style="padding-left: 6pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Loosely speaking the maximum sum is just the previous maximum sum, plus the current value.</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">← ←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 1pt;padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">1 </span>M <span class="s9">0</span>, S <span class="s9">0</span><span class="p">;</span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">2 </span>for <span class="s18">i = 1 to n</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="32" alt="image" src="cmsc351/Image_013.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">3 </span>S <span class="s9">max(</span>S <span class="s9">+ </span>A<span class="s9">[</span>i<span class="s9">]</span>, <span class="s9">0)</span><span class="p">;</span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">4 </span>M <span class="s9">= max(</span>M, S<span class="s9">)</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">5 <span class="h4">end</span></p><h4 style="padding-left: 62pt;text-indent: 0pt;line-height: 12pt;text-align: center;">Algorithm 3: <span class="p">Linear Subarray</span></h4><p class="s9" style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="p">The third method is </span>Θ(<span class="s15">n</span>)<span class="p">.</span></p><p class="s15" style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="p">Correctness of the algorithm stems from proof by induction on </span>S <span class="s9">= max(</span>S <span class="s9">+ </span>A<span class="s9">[</span>i<span class="s9">]</span>, <span class="s9">0)</span><span class="p">. This is the Loop Invariant.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p></li><li style="padding-left: 30pt;text-indent: -23pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark8">Timing analysis</a><a name="bookmark13">‌</a></h2><h4 style="padding-top: 8pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Lower Bound</h4><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-left: 10pt;text-indent: 0pt;text-align: left;">n</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 1pt;padding-left: 22pt;text-indent: 0pt;text-align: left;">1 = <span class="s15">n</span></p><p class="s11" style="padding-top: 2pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 6pt;text-indent: 0pt;text-align: left;">No algorithm is Faster than this boundary condition, the lower bound time. Best Case scenario, very hard to prove in the general case.</p><h4 style="padding-left: 6pt;text-indent: 0pt;text-align: left;">Upper Bound</h4><p style="padding-left: 6pt;text-indent: 0pt;text-align: left;">Some Algorithm can obtain upper bound time. Worst case Scenario.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark9">Classes of algorithms</a><a name="bookmark14">‌</a></h3><p class="s9" style="padding-top: 5pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark10">Θ(</a><span class="s15">n</span><span class="s16">2</span>)<a name="bookmark15">‌</a></p><p style="padding-top: 5pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Bubble sort Insertion Sort Selection Sort</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark11">Θ(</a><span class="s15">n </span>log(<span class="s15">n</span>))<a name="bookmark16">‌</a></p><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Merge Sort Heap Sort Quick Sort</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark12">Others</a><a name="bookmark17">‌</a></h4><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Radix Sort</p></li><li style="padding-top: 3pt;padding-left: 30pt;text-indent: -23pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark18">Bubble Sort Analysis</a><a name="bookmark20">‌</a></h2><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-top: 4pt;padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">1 </span>for <span class="s18">i = n downto 2</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="81" alt="image" src="cmsc351/Image_014.png"/></span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">2 </span>for <span class="s18">j = 1 to i-1</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="48" alt="image" src="cmsc351/Image_015.png"/></span></p><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">3 </span><span class="h4">if </span>A<span class="s10">[</span>j<span class="s10">] </span>> A<span class="s10">[</span>j <span class="s10">+ 1]</span><span class="s9"> </span><span class="h4">then</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;">4 <span><img width="1" height="16" alt="image" src="cmsc351/Image_016.png"/></span><span class="s33"> </span><span class="p">swap (A[j],A[j+1]);</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">5 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 12pt;text-indent: 0pt;text-align: left;">6 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 12pt;text-indent: 0pt;text-align: left;">7 <span class="h4">end</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-top: 8pt;padding-left: 12pt;text-indent: 0pt;text-align: left;">Algorithm 4: <span class="p">Bubble Sort</span></h4><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 7pt;text-indent: 0pt;line-height: 192%;text-align: left;">Major Growth Elements of Bubble sort will be Comparisons and Exchanges (swaps). Best case number of comparisons require you to view every element unconditionally.</p><p class="s11" style="padding-top: 5pt;padding-left: 102pt;text-indent: 0pt;line-height: 4pt;text-align: left;">n i<span class="s24">−</span><span class="s14">1 </span>n</p><p class="s9" style="padding-top: 5pt;padding-left: 98pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s22"> </span><span class="s13"> </span>1 =<span class="s23"> </span><span class="s15">i </span><span class="s3">− </span>1</p><p class="s11" style="text-indent: 0pt;line-height: 8pt;text-align: right;">i<span class="s14">=2 </span>j<span class="s14">=1</span></p><p class="s11" style="padding-left: 4pt;text-indent: 0pt;line-height: 8pt;text-align: center;">i<span class="s14">=2</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 5pt;text-indent: 0pt;line-height: 11pt;text-align: center;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 16pt;text-align: left;">= (<span class="s15">i </span>+ 1) <span class="s3">− </span>1</p><p class="s11" style="padding-left: 5pt;text-indent: 0pt;line-height: 8pt;text-align: center;">i<span class="s14">=1</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 5pt;text-indent: 0pt;line-height: 12pt;text-align: center;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s9" style="text-indent: 0pt;line-height: 11pt;text-align: center;">= <span class="s15">i</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">( \</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 2pt;padding-left: 5pt;text-indent: 0pt;line-height: 9pt;text-align: center;">i<span class="s14">=1</span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 7pt;text-indent: 0pt;line-height: 20pt;text-align: left;"><span class="s9">= </span><span class="s28">(</span>n <span class="s27">− </span><span class="s10">1)</span>n<span class="s15"> </span><span class="s9">= </span><span class="s34">n </span><span class="p">Equivalent to n choose 2</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Comparisons will always occur, regardless of state of list.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Best Case Exchanges occur when the list is sorted. Zero exchanges.</p><p style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Worst Case Exchanges occur when the list is reverse sorted. Same number of exchanges as comparisons.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Definition 3.1 <span class="p">(Random)</span>. <span class="p">Each permutation (ordering) of the list is equally likely.</span></h4><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">Rotations of list permutations are equally likely to be in any position, but are not random because they ignore other possible permutations.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark19">Average Case Analysis</a><a name="bookmark21">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Count Transpositions. Two elements that are out of order related to each other. See appendix for details about transpositions.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">In the best case there are no transpositions.</p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">In the worst case there are n choose 2 transpositions. Every element is out of order with the number of elements below it. So the number of transpositions is the number of unique pairs. Which is n choose 2 pairs.</p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">4</p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 7pt;text-indent: 0pt;line-height: 88%;text-align: left;"><span class="p">In a randomized sample the permutations are equally likely to be out of order greater or lesser, so the number of average case exchanges will be half the number of comparisons. </span>n<span class="s35">(</span>n<span class="s27">−</span><span class="s35">1)</span><span class="s16"> </span><span class="p">.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p></li><li style="padding-top: 4pt;padding-left: 30pt;text-indent: -23pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark22">Insertion Sort with Sentinel</a><a name="bookmark31">‌</a></h2></li></ol><p style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Every 0 to [i-1] index during the loop will be sorted.</p><p style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;line-height: 81%;text-align: left;">ith term is stored in tmp. Values in the sorted subarray which are larger than the tmp value are brought forward individually until tmp > A[j]. A sentinel <span class="s3">−∞ </span>is used at <span class="s15">A</span><span class="s9">[0]</span>, so values don’t drop off array.</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">← −∞</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-top: 3pt;padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">1 <span class="s15">A</span><span class="s9">[0] </span><span class="p">;</span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;"><span class="s17">2 </span>for <span class="s18">i = 2 to n</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="113" alt="image" src="cmsc351/Image_017.png"/></span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 14pt;text-align: left;"><span class="s17">3 </span>t <span class="s3">← </span>A<span class="s9">[</span>i<span class="s9">]</span><span class="p">;</span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">4 </span>j <span class="s3">← </span>i <span class="s3">− </span><span class="s9">1</span><span class="p">;</span></p><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">5 </span><span class="h4">while </span>A<span class="s10">[</span>j<span class="s10">] </span><span class="s27">≥</span><span class="s3"> </span>t<span class="s15"> </span><span class="h4">do</span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 16pt;text-align: left;"><span class="s17">6 </span><span><img width="1" height="32" alt="image" src="cmsc351/Image_018.png"/></span><span class="s33"> </span>A<span class="s9">[</span>j <span class="s9">+ 1] </span><span class="s3">← </span>A<span class="s9">[</span>j<span class="s9">]</span><span class="p">;</span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 10pt;text-align: left;"><span class="s17">7 </span>j <span class="s3">← </span>j <span class="s3">− </span><span class="s9">1</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 8pt;text-align: left;">8 <span class="h4">end</span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 16pt;text-align: left;"><span class="s17">9 </span>A<span class="s9">[</span>j <span class="s9">+ 1] </span><span class="s3">← </span>t<span class="p">;</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 10pt;text-align: left;">10 <span class="h4">end</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;">Algorithm 5: <span class="p">Insertion Sort with Sentinel</span></h4><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-top: 5pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark23">Analysing Number of Comparisons</a><a name="bookmark32">‌</a></h3><h4 style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark24">Best Case Comparisons</a><a name="bookmark33">‌</a></h4><p style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">In the case where the array is already correctly sorted, there will be only 1 comparison for each iteration of the other for loop. It will always evaluate false. So the number of best case comparisons is just the number of for loop iterations.</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 7pt;padding-left: 130pt;text-indent: 0pt;line-height: 8pt;text-align: left;">n</p><p class="s9" style="padding-left: 142pt;text-indent: 0pt;line-height: 18pt;text-align: left;">1 = (<span class="s15">n </span><span class="s3">− </span>2) + 1 <span class="p">Already sorted</span></p><p class="s11" style="padding-left: 126pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=2</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-top: 10pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark25">Worst Case Comparisons</a><a name="bookmark34">‌</a></h4><p class="s9" style="padding-left: 6pt;text-indent: 0pt;line-height: 18pt;text-align: left;">= <span class="s15">n </span><span class="s3">− </span>1</p><p style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">In the worst case the array is reverse sorted, and every element must be moved. The while loop always decrements j to zero to compare against the sentinel value.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="padding-left: 122pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 1pt;text-indent: 0pt;text-align: right;">i <span class="s9">=</span></p><p class="s11" style="padding-top: 2pt;text-indent: 0pt;text-align: right;">i<span class="s14">=2</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-left: 3pt;text-indent: 0pt;text-align: center;">n</p><p class="s13" style="padding-top: 5pt;text-indent: 0pt;text-align: left;"> <span class="s36"> </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 1pt;text-indent: 0pt;text-align: right;">i</p><p class="s11" style="padding-top: 2pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">i<span class="s14">=1</span></p><p class="s3" style="padding-top: 15pt;padding-left: 8pt;text-indent: 0pt;text-align: left;">− <span class="s9">1 </span><span class="p">Reverse Sorted</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="49" height="1" alt="image" src="cmsc351/Image_019.png"/></span></p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">n<span class="s9">(</span>n <span class="s9">+ 1)</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 4pt;padding-left: 140pt;text-indent: 0pt;text-align: left;">= <span class="s30">2 </span><span class="s3">− </span>1 <span class="p">must remove i=1</span></p><p class="s10" style="padding-left: 140pt;text-indent: 0pt;line-height: 72%;text-align: left;"><span class="s25">= </span>(<span class="s26">n </span>+ 2)(<span class="s26">n </span><span class="s27">− </span>1)</p><p class="s9" style="padding-left: 180pt;text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><h4 style="padding-top: 9pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark26">Average Case Comparisons</a><a name="bookmark35">‌</a></h4><p class="s13" style="text-indent: 0pt;line-height: 64%;text-align: left;">), <span class="s37">·</span><span class="s38">∈</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">In the average case we must determine the probability that a given element will move. So for evaluation we want the expected value over the set </span><span class="s39">x X </span>P <span class="s9">(</span>x<span class="s9">) </span>V <span class="s9">(</span>x<span class="s9">)</span><span class="p">.</span></p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 9pt;text-align: left;">Starting at location i, go until reach location j-1. Probability (P) that 1 element (A[i]) will end up in any location in</p><p style="text-indent: 0pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_020.png"/></span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: left;">the subarray is <span class="s40">1 </span>. Value (V) is number of moves which is (i-j+1).</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-top: 2pt;text-indent: 0pt;text-align: left;"><span class="s22"> </span><span class="s13"> </span><u>1</u> <span class="s3">· </span>(<span class="s15">i </span><span class="s3">− </span><span class="s15">j </span>+ 1) =<span class="s23"> </span><u>1</u><span class="s23"> </span>(<span class="s15">i </span><span class="s3">− </span><span class="s15">j </span>+ 1) <span class="p">Pull out 1/i</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 3pt;padding-left: 82pt;text-indent: 0pt;text-align: left;">n i n i</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-top: 3pt;text-indent: 0pt;line-height: 10pt;text-align: right;">i</p><p class="s11" style="text-indent: 0pt;line-height: 8pt;text-align: right;">i<span class="s14">=2 </span>j<span class="s14">=1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-left: 70pt;text-indent: -4pt;line-height: 11pt;text-align: left;">i<span class="s14">=2 </span>n</p><p class="s15" style="padding-top: 3pt;padding-left: 2pt;text-indent: 0pt;line-height: 10pt;text-align: left;">i</p><p class="s11" style="padding-left: 55pt;text-indent: 0pt;line-height: 8pt;text-align: center;">j<span class="s14">=1</span></p><p class="s11" style="padding-top: 2pt;text-indent: 0pt;line-height: 2pt;text-align: center;">i</p><p class="s9" style="padding-bottom: 1pt;padding-left: 172pt;text-indent: 0pt;line-height: 17%;text-align: left;"><span class="s41">=</span> <u>1</u> <span class="s43">j</span></p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">i</p><p style="padding-left: 201pt;text-indent: 0pt;line-height: 10pt;text-align: left;"/><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s10" style="padding-top: 1pt;text-indent: 0pt;text-align: left;"><span class="s25">=</span><span class="s44"> </span>1<span class="s9"> </span><span class="s45">· </span><span class="s26">i</span>(<span class="s26">i </span>+ 1)</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 187pt;text-indent: -4pt;line-height: 110%;text-align: left;">i<span class="s14">=2 </span>j<span class="s14">=1 </span>n</p><p class="s15" style="padding-top: 7pt;padding-left: 17pt;text-indent: 0pt;line-height: 10pt;text-align: center;">i <span class="s9">2</span></p><p class="s11" style="padding-left: 62pt;text-indent: 0pt;line-height: 7pt;text-align: center;">i<span class="s14">=2</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 5pt;text-align: center;">n</p><p class="s10" style="padding-left: 172pt;text-indent: 0pt;line-height: 77%;text-align: left;"><span class="s25">= </span>(<span class="s26">i </span>+ 1)</p><p class="s9" style="text-indent: 0pt;line-height: 6pt;text-align: center;">2</p><p class="s13" style="padding-top: 5pt;text-indent: 0pt;text-align: left;"> <span class="s36"> </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: right;">i<span class="s14">=2</span></p><p class="s46" style="padding-top: 1pt;text-indent: 0pt;line-height: 73%;text-align: right;">1<span class="s9"> </span><span class="s11">n</span></p><p class="s9" style="text-indent: 0pt;line-height: 7pt;text-align: right;">=</p><p class="s9" style="text-indent: 0pt;line-height: 6pt;text-align: right;">2</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-top: 5pt;padding-left: 4pt;text-indent: 0pt;text-align: left;">i <span class="s9">+ 1</span></p><p class="s11" style="padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">i<span class="s14">=2</span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">=</p><p style="text-indent: 0pt;text-align: left;"/><p class="s47" style="padding-top: 9pt;padding-bottom: 3pt;text-indent: 0pt;text-align: right;">1<span class="s30"> </span><span class="s48">n</span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="padding-left: 184pt;text-indent: 0pt;line-height: 10pt;text-align: left;"/><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="padding-left: 24pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s9" style="padding-top: 1pt;padding-left: 4pt;text-indent: 0pt;text-align: left;"><span class="s15">i </span>+<span class="s23"> </span>1<span class="s49"> </span></p><p class="s13" style="padding-top: 5pt;text-indent: 0pt;text-align: left;"> <span class="s36"> </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 2pt;text-indent: 0pt;text-align: right;">i<span class="s14">=2</span></p><p class="s46" style="padding-top: 1pt;text-indent: 0pt;line-height: 73%;text-align: right;">1<span class="s9"> </span><span class="s11">n</span></p><p class="s9" style="text-indent: 0pt;line-height: 7pt;text-align: right;">=</p><p class="s9" style="text-indent: 0pt;line-height: 7pt;text-align: right;">2</p><p class="s11" style="text-indent: 0pt;line-height: 2pt;text-align: right;">i<span class="s14">=1</span></p><p class="s11" style="padding-top: 2pt;padding-left: 16pt;text-indent: 0pt;text-align: left;">i<span class="s14">=2</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="text-indent: 0pt;text-align: left;">i <span class="s3">− </span><span class="s9">1 + (</span>n <span class="s3">− </span><span class="s9">1)</span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s10" style="padding-left: 172pt;text-indent: 0pt;text-align: left;"><span class="s25">= </span>1<span class="s50"> </span>(<span class="s26">n</span>)(<span class="s26">n </span>+ 1)<span class="s9"> </span><span class="s45">− </span><span class="s9">1 + </span>2(<span class="s26">n </span><span class="s27">− </span>1)<span class="s9"> </span><span class="s19">7</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="72" height="1" alt="image" src="cmsc351/Image_021.png"/></span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">=</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">+</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 81%;text-align: center;"><u>1</u> <span class="s50"> </span>(<span class="s15">n</span><span class="s16">2 </span>+ <span class="s15">n </span><span class="s3">− </span>2) <u>2</u><span class="s26">n </span><span class="s27">−</span><span class="s3"> </span><u>2</u> <span class="s19">7</span></p><p class="s9" style="padding-left: 50pt;text-indent: 0pt;line-height: 9pt;text-align: center;">2 2 2</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 2pt;padding-left: 9pt;text-indent: 0pt;line-height: 11pt;text-align: center;">(<span class="s15">n</span><span class="s16">2 </span>+ 3<span class="s15">n </span>4)</p><p style="text-indent: 0pt;text-align: left;"><span><img width="78" height="1" alt="image" src="cmsc351/Image_022.png"/></span></p><p class="s9" style="padding-left: 172pt;text-indent: 0pt;line-height: 6pt;text-align: left;">=</p><p class="s9" style="text-indent: 0pt;line-height: 9pt;text-align: center;">4</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark27">Analyzing Exchanges</a><a name="bookmark36">‌</a></h3><h4 style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark28">Best Case Exchanges</a><a name="bookmark37">‌</a></h4><p class="s10" style="padding-left: 7pt;text-indent: 0pt;line-height: 73%;text-align: left;"><span class="s25">= </span>(<span class="s26">n </span>+ 4)(<span class="s26">n </span><span class="s27">− </span>1)</p><p class="s9" style="padding-left: 47pt;text-indent: 0pt;line-height: 9pt;text-align: left;">4</p><p class="s9" style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;line-height: 62%;text-align: justify;"><span class="p">Best case number of moves = </span>2<span class="s15">n </span><span class="s3">− </span>1<span class="p">. There is 1 move in in the </span><span class="s3">−∞ </span><span class="p">assignment at the top, then in the for loop there are 2 moves per iteration, moving A[i] into t, and moving it back into the same spot. </span>1 + 2(<span class="s15">n </span><span class="s3">− </span>1) = 2<span class="s15">n </span><span class="s3">− </span>1<span class="p">.</span></p><h4 style="padding-top: 12pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark29">Worst Case Exchanges</a><a name="bookmark38">‌</a></h4><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">− − −</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 7pt;padding-left: 6pt;text-indent: 0pt;text-align: justify;"><span class="p">Worst case number of moves is 2 for each iteration of outer loop plus worst case number of comparisons, minus the time when the comparison is false at the end, of the inner loop, plus 1 for the top assignment. </span>2(<span class="s15">n </span>1)+<span class="s15">COM P </span>(<span class="s15">n </span>1)+1<span class="p">. Note the short cut, at each iteration we’re doing one more move than comparison. So just easily take the value already derived for Worst case comparisons, and add the number of loop iterations, plus 1 for the sentinel assignment.</span></p><p class="s10" style="padding-top: 8pt;padding-left: 62pt;text-indent: 0pt;line-height: 77%;text-align: center;">(<span class="s26">n </span>+ 2)(<span class="s26">n </span><span class="s27">− </span>1)<span class="s9"> </span><span class="s25">+ </span><span class="s15">n</span></p><p class="s9" style="text-indent: 0pt;line-height: 9pt;text-align: center;">2</p><h4 style="padding-top: 10pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark30">Average Case Exchanges</a><a name="bookmark39">‌</a></h4><p style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">In the average case, whenever there’s a comparison, there will always be a move, except the 1 time per iteration it evaluates false. So the analysis method is the same as for the worse case. Since we know the number.</p><p class="s10" style="padding-top: 8pt;padding-left: 62pt;text-indent: 0pt;line-height: 77%;text-align: center;">(<span class="s26">n </span>+ 4)(<span class="s26">n </span><span class="s27">− </span>1)<span class="s9"> </span><span class="s25">+ </span><span class="s15">n</span></p><p class="s9" style="padding-left: 247pt;text-indent: 0pt;line-height: 9pt;text-align: left;">4</p><h4 style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Remark 4.1. <span class="p">An important trick is to recognize that the moves are related to the comparisons 1 to 1 and that there will be 1 time when the comparison evaluates false each iteration, so you subtract that from the final analysis.</span></h4><p style="text-indent: 0pt;text-align: left;"><br/></p><ol id="l4"><li style="padding-left: 30pt;text-indent: -23pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark40">Insertion Sort without Sentinel</a><a name="bookmark45">‌</a></h2><p style="padding-top: 8pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Add another comparison in the algorithm so the A[0] term is unnecessary, by checking that you haven’t gone past i=1.</p><h4 style="padding-top: 2pt;padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;"><span class="s17">1 </span>for <span class="s18">i=2 to n</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="113" alt="image" src="cmsc351/Image_023.png"/></span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 14pt;text-align: left;"><span class="s17">2 </span>t <span class="s3">← </span>A<span class="s9">[</span>i<span class="s9">]</span><span class="p">;</span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">3 </span>j <span class="s3">← </span>i <span class="s3">− </span><span class="s9">1</span><span class="p">;</span></p><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">4 </span><span class="h4">while </span>j > <span class="s10">0 </span><span class="s27">∧ </span>A<span class="s10">[</span>j<span class="s10">] </span>> t<span class="s15"> </span><span class="h4">do</span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 16pt;text-align: left;"><span class="s17">5 </span><span><img width="1" height="32" alt="image" src="cmsc351/Image_024.png"/></span><span class="s33"> </span>A<span class="s9">[</span>j <span class="s9">+ 1] </span><span class="s3">← </span>A<span class="s9">[</span>j<span class="s9">]</span><span class="p">;</span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 10pt;text-align: left;"><span class="s17">6 </span>j <span class="s3">← </span>j <span class="s3">− </span><span class="s9">1</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 8pt;text-align: left;">7 <span class="h4">end</span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 16pt;text-align: left;"><span class="s17">8 </span>A<span class="s9">[</span>j <span class="s9">+ 1] </span><span class="s3">← </span>t<span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 10pt;text-align: left;">9 <span class="h4">end</span></p><h4 style="padding-left: 162pt;text-indent: 0pt;text-align: left;">Algorithm 6: <span class="p">Insertion Sort w/o Sentinel</span></h4><p style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">A note about comparisons. We don’t count index value comparisons, because index values can easily be stored in registers and won’t have the same cost to check as array value comparisons.</p><h3 style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark41">Best Case Comparisons</a><a name="bookmark46">‌</a></h3><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">),</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">In the best case, the array is already sorted, so there will just be 1 comparison per iteration of the outer loop.</p><p class="s11" style="padding-left: 17pt;text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p class="s11" style="padding-left: 17pt;text-indent: 0pt;line-height: 10pt;text-align: left;">i<span class="s14">=2</span></p><p class="s9" style="text-indent: 0pt;line-height: 18pt;text-align: left;">1 = (<span class="s15">n </span><span class="s3">− </span>2) + 1 = <span class="s15">n </span><span class="s3">− </span>1</p><h3 style="padding-top: 9pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark42">Worst Case Comparisons</a><a name="bookmark47">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">In the worst case, the array is reverse sorted, and every ith iteration of the loop must compare against all previous</p><p class="s9" style="padding-left: 5pt;text-indent: 0pt;line-height: 18pt;text-align: left;">(<span class="s15">i </span><span class="s3">− </span>1) <span class="p">elements.</span></p><p class="s11" style="padding-top: 3pt;padding-left: 15pt;text-indent: 0pt;line-height: 4pt;text-align: center;">n i<span class="s24">−</span><span class="s14">1 </span>n</p><p class="s9" style="padding-top: 5pt;padding-left: 184pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s22"> </span><span class="s13"> </span>1 =<span class="s23"> </span>(<span class="s15">i </span><span class="s3">− </span>1)</p><p class="s11" style="text-indent: 0pt;line-height: 8pt;text-align: right;">i<span class="s14">=2 </span>j<span class="s14">=1</span></p><p class="s11" style="padding-left: 18pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=2</span></p><p class="s11" style="padding-left: 22pt;text-indent: 0pt;line-height: 2pt;text-align: left;">n n</p><p class="s9" style="padding-top: 5pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">= <span class="s23"> </span><span class="s15">i </span><span class="s3">− </span><span class="s29"> </span>1</p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=2</span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=2</span></p><p style="padding-left: 235pt;text-indent: 0pt;line-height: 7pt;text-align: left;"><span style=" color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 6.5pt;"> </span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=2</span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=2</span></p><p style="padding-left: 235pt;text-indent: 0pt;line-height: 7pt;text-align: left;"><span style=" color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 6.5pt;"> </span></p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">n<span class="s9">(</span>n <span class="s9">+ 1)</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="49" height="1" alt="image" src="cmsc351/Image_025.png"/></span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 67%;text-align: center;">= <span class="s30">2 </span><span class="s3">− </span>1 <span class="s3">− </span>(<span class="s15">n </span><span class="s3">− </span>1)</p><p class="s15" style="padding-top: 1pt;padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">n<span class="s9">(</span>n <span class="s9">+ 1)</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="49" height="1" alt="image" src="cmsc351/Image_026.png"/></span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 67%;text-align: center;">= <span class="s30">2 </span><span class="s3">− </span><span class="s15">n</span></p><p class="s15" style="padding-top: 1pt;padding-left: 62pt;text-indent: 0pt;line-height: 9pt;text-align: center;">n<span class="s16">2 </span><span class="s9">+ </span>n <span class="s9">2</span>n</p><p style="text-indent: 0pt;text-align: left;"><span><img width="38" height="1" alt="image" src="cmsc351/Image_027.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="15" height="1" alt="image" src="cmsc351/Image_028.png"/></span></p><p class="s30" style="padding-left: 62pt;text-indent: 0pt;line-height: 61%;text-align: center;"><span class="s9">= </span>2 <span class="s3">− </span>2</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 2pt;padding-left: 62pt;text-indent: 0pt;line-height: 11pt;text-align: center;">n<span class="s16">2 </span>n</p><p style="text-indent: 0pt;text-align: left;"><span><img width="38" height="1" alt="image" src="cmsc351/Image_029.png"/></span></p><p class="s9" style="text-indent: 0pt;line-height: 6pt;text-align: center;">=</p><p class="s9" style="text-indent: 0pt;line-height: 9pt;text-align: center;">2</p><p class="s26" style="padding-left: 62pt;text-indent: 0pt;line-height: 74%;text-align: center;"><span class="s25">= </span>n<span class="s10">(</span>n <span class="s27">− </span><span class="s10">1)</span></p><p class="s9" style="text-indent: 0pt;line-height: 9pt;text-align: center;">2</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark43">Average Case Comparisons</a><a name="bookmark48">‌</a></h3><h4 style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Remark 5.1. <span class="p">HARMONIC SERIES and brick problem. How far out can you stack bricks on top of one another? Arbitrarily far out (but not infinitely far out)</span></h4><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">i</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">3</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">4</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">5</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 7pt;padding-left: 150pt;text-indent: 0pt;text-align: left;"><span class="s15">H </span>=<span class="s23"> </span><u>1</u> = 1 + <u>1</u> + <u>1</u> + <u>1</u> + <u>1</u> + <span class="s3">· · · ≈ </span>ln <span class="s15">n </span>+ 1</p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 178pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 178pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">i</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">3</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">4</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">5</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 7pt;padding-left: 159pt;text-indent: 0pt;text-align: left;"><span class="s15">H </span><span class="s3">− </span>1 =<span class="s23"> </span><u>1</u> = <u>1</u> + <u>1</u> + <u>1</u> + <u>1</u> + <span class="s3">· · · ≈ </span>ln <span class="s15">n</span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=2</span></p><p style="padding-left: 203pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=2</span></p><p style="padding-left: 203pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p style="text-indent: 0pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_030.png"/></span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 2pt;padding-left: 7pt;text-indent: 0pt;line-height: 14pt;text-align: left;">Harmonic Series come up again and again because of the idea that something has a <span class="s40">1 </span>chance of happening in an</p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">iteration.</p><p style="text-indent: 0pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_031.png"/></span></p><p style="padding-top: 7pt;padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">What are we saving when we don’t have a sentinel? In the event that the ith element is the smallest element in the A[1..i-1] sub-array, we will descend all the way to the 1st index of the list. If that happens, we won’t have the 1 extra step of comparing against the sentinel. So only when the ith element is the smallest seen thus far do we save 1 step. Probability that current ith element is smallest in sub array is <span class="s40">1 </span>. The value when that occurs is 1. Thus over all n</p><p style="text-indent: 0pt;line-height: 12pt;text-align: left;">elements of the array, on average the sentinel would have cost us</p><p style="text-indent: 0pt;text-align: left;"/><p class="s39" style="text-indent: 0pt;line-height: 17pt;text-align: left;">i<span class="s14">=2 </span>i <span class="s9">= </span><span class="s15">Hn </span><span class="s3">− </span><span class="s9">1 </span><span class="p">comparisons.</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s16" style="text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="p">So average case comparisons without sentinel is average case with sentinel minus average cost of sentinel. </span>(<span class="s15">n</span><span class="s3">−</span>1)(<span class="s15">n</span>+4) <span class="s3">−</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-bottom: 1pt;padding-left: 62pt;text-indent: 0pt;line-height: 9%;text-align: center;">i <span class="s51">),</span><span class="s39">n </span><span class="s52">1</span></p><p style="padding-left: 319pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_032.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 457pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="57" height="1" alt="image" src="cmsc351/Image_033.png"/></span></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">4</p><p style="padding-left: 477pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">4</p><p style="padding-left: 477pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">4</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="padding-left: 5pt;text-indent: 0pt;line-height: 78%;text-align: left;"><span class="s9">(</span><span class="s15">H</span><span class="s53">n </span>− <span class="s9">1) </span>≈ <span class="s54">(</span><span class="s55">n</span><span class="s56">−</span><span class="s57">1)(</span><span class="s55">n</span><span class="s57">+4)</span><span class="s14"> </span>− <span class="s9">ln </span><span class="s15">n</span><span class="p">.</span></p><h3 style="padding-top: 9pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark44">Exchanges</a><a name="bookmark49">‌</a></h3><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Removing the sentinel from insertion sort adds no new exchanges, nor does it alter when a change might have been done already. Therefore, the best, worst and average cases are all the same as insertion sort with sentinel.</p></li><li style="padding-top: 3pt;padding-left: 30pt;text-indent: -23pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark50">Selection Sort</a><a name="bookmark53">‌</a></h2><p style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Summary: Find biggest element, put at bottom of list, recurse for sub array.</p><h4 style="padding-top: 1pt;padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">1 </span>for <span class="s18">i=n downto 2</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="113" alt="image" src="cmsc351/Image_034.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">2 <span class="s15">k </span><span class="s9">1</span><span class="p">;</span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">3 </span>for <span class="s18">j=2 to i</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="48" alt="image" src="cmsc351/Image_035.png"/></span></p><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">4 </span><span class="h4">if </span>A<span class="s10">[</span>j<span class="s10">] </span>> A<span class="s10">[</span>k<span class="s10">]</span><span class="s9"> </span><span class="h4">then</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;">5 <span><img width="1" height="16" alt="image" src="cmsc351/Image_036.png"/></span><span class="s33"> </span><span class="s15">k j</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">6 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 12pt;text-indent: 0pt;text-align: left;">7 <span class="h4">end</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;text-align: left;">8 <span class="p">swap (A[k], A[i]);</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">9 <span class="h4">end</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-top: 9pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark51">Comparisons</a><a name="bookmark54">‌</a></h3><h4 style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Algorithm 7: <span class="p">Selection Sort</span></h4><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">The comparison is always run, so the comparison value should be the same for all cases.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-top: 3pt;padding-left: 62pt;text-indent: 0pt;line-height: 2pt;text-align: center;">n i n</p><p class="s9" style="padding-top: 5pt;text-indent: 0pt;line-height: 18pt;text-align: center;"><span class="s22"> </span><span class="s13"> </span>1 = <span class="s23"> </span>(<span class="s15">i </span><span class="s3">− </span>1)</p><p class="s11" style="text-indent: 0pt;line-height: 8pt;text-align: right;">i<span class="s14">=2 </span>j<span class="s14">=2</span></p><p class="s11" style="padding-left: 18pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=2</span></p><p class="s10" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;line-height: 77%;text-align: left;"><span class="s25">= </span>(<span class="s26">n </span><span class="s27">− </span>1)<span class="s26">n</span></p><p class="s9" style="padding-left: 35pt;text-indent: 0pt;line-height: 9pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-top: 5pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark52">Exchanges</a><a name="bookmark55">‌</a></h3><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">),</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Exchanges don’t occur inside the conditional, so exchanges number is simply n-1.</p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="p">How many times do we exchange a number with itself? How many times does i=k? </span>1<span class="s15">/i </span>= <span class="s15">Hn</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p></li><li style="padding-left: 30pt;text-indent: -23pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark56">Merge Sort</a><a name="bookmark62">‌</a></h2><p style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Divide and Conquer. Recursively split array in half down to 1 element, then merge sorted sublists. First call of Mergesort is (A,1,n)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">1 <span class="p">MERGESORT (A,p,r);</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">2 <span class="p">//p and r are indices in array defining sub array.;</span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;"><span class="s17">3 </span>if <span class="s18">p<r</span><span class="p"> </span>then</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="64" alt="image" src="cmsc351/Image_037.png"/></span></p><p class="s17" style="text-indent: 0pt;line-height: 17pt;text-align: left;">4 <span class="s15">q </span><span class="s3">← l J</span><span class="p">;</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s55" style="padding-left: 20pt;text-indent: 0pt;line-height: 8pt;text-align: center;">p<span class="s57">+</span>r</p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: center;">2</p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 10pt;text-align: left;">5 <span class="p">MERGESORT (A,p,q);</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">6 <span class="p">MERGESORT (A,q+1,r);</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">7 <span class="p">MERGE (A, (p,q), (q+1,r));</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">8 <span class="h4">end</span></p><h4 style="padding-left: 62pt;text-indent: 0pt;line-height: 12pt;text-align: center;">Algorithm 8: <span class="p">Merge Sort</span></h4><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark57">Merge Comparison analysis</a><a name="bookmark63">‌</a></h3><h4 style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark58">Equal length arrays</a><a name="bookmark64">‌</a></h4><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;"><span class="p">Merge algorithm is linear over 2 sorted lists of same size (n). Total number of comparisons in the worst case during merge is </span>2<span class="s15">n </span>1<span class="p">, best case comparisons is n, where 1 array is strictly greater than the other.</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><span class="p">Can’t do better than </span>2<span class="s15">n </span>1 <span class="p">in worst case, because worst case situation is 2 lists with interleaved values. In this case the granularity of difference is on the scale of 1 value. So you must check every value to ensure against that. The last remaining value of 2 lists is not compared, which leads to 2n-1.</span></p><p style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">This gives us very tight bounds and lets us know everything there is to know about merging.</p><h4 style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark59">Different length arrays</a><a name="bookmark65">‌</a></h4><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">≤ −</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="p">Arrays of size m and n where </span>m n <span class="p">Worst case comparisons = </span>m <span class="s9">+ </span>n <span class="s9">1</span></p><p class="s15" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;line-height: 81%;text-align: left;"><span class="p">When </span>m << n <span class="p">you can get close to </span><span class="s9">log </span>n <span class="p">running time using binary search. But when m is close to n you are much closer to the </span>m <span class="s9">+ </span>n <span class="s3">− </span><span class="s9">1 </span><span class="p">worst case.</span></p><h3 style="padding-top: 10pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark60">Mergesort Comparison Analysis</a><a name="bookmark66">‌</a></h3><h4 style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Exact Number of Comparisons During a merge</h4><p class="s15" style="padding-top: 7pt;padding-left: 135pt;text-indent: 0pt;text-align: left;"><span class="s9">(</span>q <span class="s3">− </span>p <span class="s9">+ 1) + (</span>r <span class="s3">− </span><span class="s9">(</span>q <span class="s9">+ 1) + 1) </span><span class="s3">− </span><span class="s9">1 = (</span>r <span class="s3">− </span>p<span class="s9">) </span><span class="p">comparisons</span></p><p style="padding-top: 5pt;padding-left: 5pt;text-indent: 1pt;text-align: left;">starting at index p and ending at index q. So for the full list, where p=1 and q=n a MERGESORT will start with (n-1) comparisons and have the following behavior.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s58" style="text-indent: 0pt;line-height: 8pt;text-align: left;"> <span class="s55">n</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s59" style="text-indent: 0pt;text-align: right;">2<span class="s60">2 </span><span class="s3">− </span><span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 12pt;padding-left: 8pt;text-indent: 0pt;text-align: center;">.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s59" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">2 <span class="s3">− </span><span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="105" height="34" alt="image" src="cmsc351/Image_038.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="70" height="31" alt="image" src="cmsc351/Image_039.png"/></span></p><p class="s55" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s58" style="text-indent: 0pt;line-height: 8pt;text-align: left;"> <span class="s55">n</span></p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 8pt;text-indent: 0pt;text-align: center;">+</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 62pt;text-indent: 0pt;text-align: center;">. .</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s59" style="padding-left: 10pt;text-indent: 0pt;text-align: left;">2<span class="s60">2 </span><span class="s3">− </span><span class="s9">1</span></p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">n <span class="s3">− </span><span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="209" height="36" alt="image" src="cmsc351/Image_040.png"/></span></p><p style="padding-left: 8pt;text-indent: 0pt;text-align: center;">+</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="70" height="31" alt="image" src="cmsc351/Image_041.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="70" height="31" alt="image" src="cmsc351/Image_042.png"/></span></p><p class="s58" style="text-indent: 0pt;line-height: 8pt;text-align: left;"> <span class="s55">n</span></p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 8pt;text-indent: 0pt;text-align: center;">+</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 62pt;text-indent: 0pt;text-align: center;">. .</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s59" style="padding-left: 10pt;text-indent: 0pt;text-align: left;">2<span class="s60">2 </span><span class="s3">− </span><span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s59" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">2 <span class="s3">− </span><span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="105" height="34" alt="image" src="cmsc351/Image_043.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="70" height="31" alt="image" src="cmsc351/Image_044.png"/></span></p><p class="s55" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 8pt;text-indent: 0pt;text-align: center;">+</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 62pt;text-indent: 0pt;text-align: center;">. .</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s59" style="padding-left: 10pt;text-indent: 0pt;text-align: left;">2<span class="s60">2 </span><span class="s3">− </span><span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="53" height="30" alt="image" src="cmsc351/Image_045.png"/></span></p><p class="s58" style="text-indent: 0pt;line-height: 8pt;text-align: left;"> <span class="s55">n</span></p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 12pt;text-indent: 0pt;text-align: right;">.</p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">2<span class="s16">0 </span>(<span class="s15">n </span><span class="s3">− </span>1)</p><p class="s9" style="text-indent: 0pt;text-align: left;"><span class="s12">(</span><span class="s13"> )</span>2 <span class="s3">−</span>1</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 3pt;text-indent: 0pt;text-align: center;">+</p><ol id="l5"><li style="padding-top: 8pt;padding-left: 62pt;text-indent: -11pt;line-height: 9pt;text-align: left;"><p class="s55" style="display: inline;">n</p><p class="s14" style="text-indent: 0pt;line-height: 8pt;text-align: center;">2</p><p class="s9" style="text-indent: 0pt;text-align: left;"><span class="s12">(</span><span class="s13"> )</span>2 <span class="s3">−</span>1</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 5pt;text-indent: 0pt;text-align: center;">+</p></li><li style="padding-top: 7pt;padding-left: 60pt;text-indent: -11pt;line-height: 9pt;text-align: left;"><p class="s58" style="display: inline;"> <span class="s55">n</span></p><p class="s61" style="padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">2<span class="s62">2</span></p><p style="padding-top: 4pt;text-indent: 0pt;text-align: center;">+</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: center;">.</p><p style="padding-top: 4pt;text-indent: 0pt;text-align: center;">+</p><p style="text-indent: 0pt;text-align: left;"><span><img width="53" height="30" alt="image" src="cmsc351/Image_046.png"/></span></p><p class="s12" style="padding-left: 10pt;text-indent: 0pt;line-height: 15pt;text-align: left;">(<u> </u><span class="s55">n</span><span class="s11"> </span><span class="s3">− </span><span class="s9">1</span>)<span class="p">+</span>(<u> </u><span class="s55">n</span><span class="s11"> </span><span class="s3">− </span><span class="s9">1</span>)</p><p class="s3" style="padding-top: 5pt;padding-left: 10pt;text-indent: 0pt;line-height: 10pt;text-align: left;">· · ·</p><p style="padding-top: 5pt;padding-left: 10pt;text-indent: 0pt;line-height: 10pt;text-align: left;">+ <span class="s3">· · ·</span></p><p class="s12" style="padding-left: 10pt;text-indent: 0pt;line-height: 15pt;text-align: left;">(<u> </u><span class="s55">n</span><span class="s11"> </span><span class="s3">− </span><span class="s9">1</span>)<span class="p">+</span>(<u> </u><span class="s55">n</span><span class="s11"> </span><span class="s3">− </span><span class="s9">1</span>)</p><p class="s9" style="padding-left: 10pt;text-indent: 0pt;line-height: 15pt;text-align: left;">2<span class="s15">k </span><span class="s12">(</span><span class="s63"> </span><span class="s55">n</span><span class="s11"> </span><span class="s3">− </span>1<span class="s12">)</span></p><p class="s61" style="padding-left: 16pt;text-indent: 0pt;line-height: 9pt;text-align: left;">2<span class="s64">k </span>2<span class="s64">k</span></p><p class="s65" style="padding-left: 13pt;text-indent: 0pt;text-align: left;"><span><img width="42" height="36" alt="image" src="cmsc351/Image_047.png"/></span> <span><img width="42" height="36" alt="image" src="cmsc351/Image_048.png"/></span></p><p style="padding-left: 10pt;text-indent: 0pt;text-align: left;">0 + 0 0 + 0</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="42" height="36" alt="image" src="cmsc351/Image_049.png"/></span></p><p class="s3" style="padding-top: 11pt;padding-left: 10pt;text-indent: 0pt;text-align: left;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 10pt;text-indent: 0pt;text-align: left;">+ <span class="s3">· · ·</span></p><p class="s61" style="padding-left: 10pt;text-indent: 0pt;line-height: 9pt;text-align: left;">2<span class="s64">k </span>2<span class="s64">k</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: right;">0 +</p><p class="s61" style="padding-left: 62pt;text-indent: 0pt;line-height: 9pt;text-align: center;">2<span class="s64">k</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: center;">+</p><p style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">0 <span class="s66">= </span><span class="s9">0</span><span class="s15">n</span></p><p style="padding-top: 5pt;text-indent: 0pt;text-align: center;">=</p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=0</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s61" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2<span class="s64">i</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 4pt;padding-left: 62pt;text-indent: 0pt;text-align: center;"><span class="s19">),</span><span class="s67">lg </span><span class="s11">n </span>2<span class="s68">i</span>(<u> </u><span class="s55">n</span><span class="s11"> </span><span class="s3">− </span>1)</p><p style="padding-top: 2pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Because this gives <span class="s9">lg </span><span class="s15">n </span>terms, we can make it a little easier by dropping the bottom row, which sums to 0 anyway, because it’s <span class="s9">0</span><span class="s15">n</span>.</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="padding-top: 5pt;text-indent: 0pt;text-align: right;">lg <span class="s11">n</span><span class="s24">−</span>1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;text-align: right;">i<span class="s14">=0</span></p><p class="s9" style="padding-top: 11pt;text-indent: 0pt;line-height: 16pt;text-align: left;">2<span class="s15">i</span>( <span class="s32">n</span><span class="s15"> </span>1) =</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s70" style="padding-left: 13pt;text-indent: 0pt;line-height: 45%;text-align: left;">2<span class="s11">i</span></p><p class="s14" style="padding-top: 5pt;text-indent: 0pt;line-height: 11pt;text-align: left;">lg <span class="s11">n</span><span class="s24">−</span>1</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 23pt;text-indent: 0pt;line-height: 16pt;text-align: left;">(<span class="s15">n </span><span class="s3">− </span>2<span class="s15">i</span>)</p><p class="s11" style="padding-left: 5pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=0</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="text-indent: 0pt;line-height: 11pt;text-align: right;">lg <span class="s11">n</span><span class="s24">−</span>1</p><p class="s9" style="text-indent: 0pt;line-height: 16pt;text-align: right;">= <span class="s15">n </span><span class="s3">−</span></p><p class="s11" style="text-indent: 0pt;line-height: 8pt;text-align: right;">i<span class="s14">=0</span></p><p class="s14" style="text-indent: 0pt;line-height: 12pt;text-align: left;">lg <span class="s11">n</span><span class="s24">−</span>1</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s71" style="padding-left: 24pt;text-indent: 0pt;line-height: 58%;text-align: left;">2<span class="s11">i</span></p><p class="s11" style="padding-top: 4pt;padding-left: 5pt;text-indent: 0pt;text-align: left;">i<span class="s14">=0</span></p><p class="s9" style="padding-left: 160pt;text-indent: 0pt;line-height: 16pt;text-align: left;">= (<span class="s15">n </span>lg <span class="s15">n</span>) <span class="s3">− </span>(2<span class="s16">lg </span><span class="s15">n</span><span class="s3">−</span><span class="s16">1+1 </span><span class="s3">− </span>1) <span class="p">geometric series</span></p><p class="s9" style="padding-left: 160pt;text-indent: 0pt;line-height: 15pt;text-align: left;">= (<span class="s15">n </span>lg <span class="s15">n</span>) <span class="s3">− </span>(<span class="s15">n </span><span class="s3">− </span>1)</p><p class="s15" style="padding-left: 160pt;text-indent: 0pt;line-height: 17pt;text-align: left;"><span class="s9">= </span>n <span class="s9">lg </span>n <span class="s3">− </span>n <span class="s9">+ 1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark61">Merge Sort Recurrence</a><a name="bookmark67">‌</a></h3><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">When expressed as a recurrence relation, the mergesort algorithm given previously behaves like</p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 1pt;padding-left: 60pt;text-indent: 0pt;text-align: left;">S<span class="s9">(</span>n<span class="s9">) = </span>S <span class="s72">(</span><span class="s13"> </span><u>n</u> <span class="s72">\</span><span class="s13"> </span><span class="s9">+ </span>S <span class="s72">(</span><span class="s13"> </span><u>n</u> <span class="s72">\</span><span class="s13"> </span><span class="s9">+ </span>n <span class="s3">− </span><span class="s9">1</span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 2pt;padding-left: 83pt;text-indent: 0pt;text-align: left;"><span class="s9">= 2 </span><span class="s3">· </span>S <span class="s72">(</span><span class="s13"> </span><u>n</u> <span class="s72">\</span><span class="s13"> </span><span class="s9">+ </span>n <span class="s3">− </span><span class="s9">1</span></p><p style="padding-top: 7pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Which gives the following recurrence relation</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">\</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 9pt;padding-left: 61pt;text-indent: 0pt;line-height: 10pt;text-align: left;">S<span class="s9">(0) = </span>S<span class="s9">(1) = 0 </span><span class="p">Base case of 0 comparisons with 0 or 1 element</span></p><p class="s15" style="padding-left: 60pt;text-indent: 0pt;line-height: 21pt;text-align: left;">S<span class="s9">(</span>n<span class="s9">) = </span>S <span class="s72">(</span></p><p class="s26" style="padding-top: 2pt;text-indent: 0pt;line-height: 8pt;text-align: center;">n</p><p class="s3" style="padding-left: 62pt;text-indent: 0pt;line-height: 68%;text-align: center;">l <span class="s30">2 </span>J</p><p class="s13" style="text-indent: 0pt;line-height: 82%;text-align: left;">\ <span class="s73">+ </span><span class="s15">S </span>(</p><p class="s26" style="padding-top: 2pt;text-indent: 0pt;line-height: 8pt;text-align: center;">n</p><p class="s3" style="padding-left: 55pt;text-indent: 0pt;line-height: 68%;text-align: center;">1 <span class="s30">2 </span>1</p><p style="text-indent: 0pt;text-align: left;"><br/></p></li></ol></li><li style="padding-top: 5pt;padding-left: 30pt;text-indent: -23pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark68">Integer Arithmetic</a><a name="bookmark74">‌</a></h2></li></ol><h3 style="padding-top: 9pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark69">Addition</a><a name="bookmark75">‌</a></h3><p class="s9" style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">Just like in elementary addition, the time to add 2 n digit numbers is proportional to the number of digits. </span>Θ(<span class="s15">n</span>)<span class="p">. Since each digit must be used to compute the sum this is the right order for best case time.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s74" style="padding-top: 4pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">1 1</p><p class="s25" style="padding-top: 1pt;padding-left: 62pt;text-indent: 0pt;line-height: 63%;text-align: center;">+ <span class="p">1 2 3 4</span></p><p class="s75" style="text-indent: 0pt;line-height: 9pt;text-align: center;"> <span class="s18">5 6 7 8</span></p><p style="padding-left: 62pt;text-indent: 0pt;line-height: 12pt;text-align: center;">6 9 1 2</p><p class="s15" style="padding-top: 9pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">We assume that each digital addition takes constant time (with carry also, so ignore that little trouble spot) and label this constant </span>α<span class="p">. The time to add 2 n digit numbers is then </span>α<span class="s9">(</span>n<span class="s9">)</span><span class="p">.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark70">Problem size</a><a name="bookmark76">‌</a></h3><p style="padding-top: 6pt;padding-left: 9pt;text-indent: 0pt;text-align: center;">If we were attempting to determine if a number was prime we would divide it by consecutive primes up to the square root of that number. In Computer Science we want to approach all problems in terms of the problem size. So we</p><p style="padding-top: 6pt;text-indent: 0pt;line-height: 23%;text-align: center;">should look at both in ter<span class="s76">√</span>m<u>s</u> of the NUMBER OF DIGITS, and not the size of the number. So while the prime</p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">identification problem is <span class="s9">Θ</span></p><p class="s77" style="padding-left: 24pt;text-indent: 0pt;line-height: 1pt;text-align: left;">n</p><p class="s15" style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;">N <span class="p">where N is the number, expressed in binary as </span><span class="s9">2</span>n<span class="p">, n being the number of binary digits.</span></p><p class="s9" style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Θ(2 <span class="s78">2 </span>)<span class="p">. Giving an exponential time algorithm.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark71">Multiplication</a><a name="bookmark77">‌</a></h3><p class="s15" style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;line-height: 75%;text-align: left;"><span class="p">Elementary school approach to multiplication runs in </span>n<span class="s16">2 </span><span class="p">time because every digit on top is multiplied by every digit on the bottom. There are </span><span class="s9">2</span>n<span class="s9">(</span>n <span class="s3">− </span><span class="s9">1) </span><span class="p">atomic additions in this elementary approach as described in class.</span></p><p style="padding-top: 14pt;padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">1 2 3 4</p><p class="s79" style="padding-left: 62pt;text-indent: 0pt;line-height: 16pt;text-align: center;">× <span class="p">5 6 7 8</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="57" height="1" alt="image" src="cmsc351/Image_050.png"/></span></p><p style="padding-left: 62pt;text-indent: 0pt;line-height: 12pt;text-align: center;">9 8 7 2</p><p style="padding-left: 62pt;text-indent: 0pt;line-height: 12pt;text-align: center;">8 6 3 8</p><p style="padding-left: 62pt;text-indent: 0pt;line-height: 12pt;text-align: center;">7 4 0 4</p><p class="s18" style="padding-left: 62pt;text-indent: 0pt;line-height: 12pt;text-align: center;">6 1 7 0 </p><p style="padding-left: 62pt;text-indent: 0pt;line-height: 12pt;text-align: center;">7 0 0 6 6 5 2</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-top: 5pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark72">Recursive Multiplication</a><a name="bookmark78">‌</a></h4><p style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">By memorizing the numbers in large bases, say base 100, 2 digit decimal numbers can be treated as 1 digit numbers in base 100. That makes the multiplication easier, because there are fewer steps.</p><p class="s77" style="padding-left: 270pt;text-indent: 0pt;line-height: 0pt;text-align: left;">n<span class="s64"> </span><span class="s80">n</span></p><p style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;line-height: 75%;text-align: left;">To generalize this for n digit numbers, treat them as base <span class="s9">10 </span><span class="s78">2 </span>and cut each in half. Each has <span class="s59">2 </span>digits, and we know the base. Then, recurse through this method until we reach a base we really have memorized the table for. Then</p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">multiply them as 2 2 digit numbers, and pull out the answer.</p><p style="text-indent: 0pt;text-align: left;"><span><img width="17" height="34" alt="image" src="cmsc351/Image_051.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="35" height="36" alt="image" src="cmsc351/Image_052.png"/></span></p><p style="padding-left: 21pt;text-indent: 0pt;text-align: center;">bd</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 3pt;text-indent: 0pt;text-align: left;">d</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 3pt;text-indent: 0pt;text-align: left;">cd</p><p style="text-indent: 0pt;text-align: left;"/><p class="s55" style="text-indent: 0pt;line-height: 7pt;text-align: center;">n</p><p class="s14" style="text-indent: 0pt;line-height: 9pt;text-align: center;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s55" style="text-indent: 0pt;line-height: 7pt;text-align: center;">n</p><p class="s14" style="text-indent: 0pt;line-height: 9pt;text-align: center;">2</p><p style="text-indent: 0pt;text-align: left;"/><p style="text-indent: 0pt;line-height: 21pt;text-align: right;">n <span><img width="19" height="23" alt="image" src="cmsc351/Image_053.png"/></span><span class="s65"> </span>c</p><p style="text-indent: 0pt;text-align: left;"><span><img width="23" height="19" alt="image" src="cmsc351/Image_054.png"/></span></p><p class="s55" style="text-indent: 0pt;line-height: 7pt;text-align: center;">n</p><p class="s14" style="text-indent: 0pt;line-height: 9pt;text-align: center;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s55" style="text-indent: 0pt;line-height: 7pt;text-align: center;">n</p><p class="s14" style="text-indent: 0pt;line-height: 9pt;text-align: center;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s18" style="text-indent: 0pt;line-height: 13pt;text-align: left;">a <span class="s81">b </span> </p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 2pt;text-indent: 0pt;text-align: left;">ab</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="text-indent: 0pt;line-height: 19pt;text-align: right;">× <span class="p">n </span>× <span><img width="19" height="23" alt="image" src="cmsc351/Image_055.png"/></span><span class="s65"> </span>× × </p><p style="text-indent: 0pt;line-height: 11pt;text-align: right;">bd</p><p style="text-indent: 0pt;line-height: 12pt;text-align: left;">ad</p><p style="text-indent: 0pt;text-align: left;"/><p style="text-indent: 0pt;line-height: 14pt;text-align: right;"><span class="s82">bc </span>}<span class="s15">αn </span>time</p><p style="text-indent: 0pt;line-height: 12pt;text-align: right;">+ ac</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 21pt;text-indent: 0pt;line-height: 11pt;text-align: center;">ac</p><p style="text-indent: 0pt;text-align: left;"/><p style="text-indent: 0pt;text-align: left;"><span><img width="76" height="20" alt="image" src="cmsc351/Image_056.png"/></span></p><p class="s83" style="padding-left: 41pt;text-indent: -30pt;text-align: left;">↓ <span class="p">+ </span>↓ <span class="p">ad+bc</span></p><p class="s15" style="padding-top: 5pt;padding-left: 37pt;text-indent: 0pt;text-align: left;">αn <span class="p">time Total add time = </span><span class="s9">2</span>αn</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 184pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="57" height="1" alt="image" src="cmsc351/Image_057.png"/></span></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">( )</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 2pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">ac <span class="p">is an n digit number, as are </span>ad<span class="p">, </span>bc<span class="p">, </span>bd<span class="p">. When adding, </span>bd <span class="p">is not shifted, but </span>ad<span class="p">, and </span>bc <span class="p">are shifted by </span><span class="s84">n</span><span class="s11"> </span><span class="p">digits, and </span>ac <span class="p">is shifted by n digits. Since there’s no overlap for </span>ac <span class="p">and </span>bd<span class="p">, you can add them simply by concatenation. </span>ad <span class="s9">+ </span>bc <span class="p">takes </span>αn <span class="p">time. That value plus the center (overlapping) segment of </span>ac <span class="s9">+ </span>bd <span class="p">is also </span>αn<span class="p">.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><span class="p">So without writing out the algorithm: </span>M <span class="s9">(</span>n<span class="s9">) = 4</span>M <u>n</u> <span class="s9">+ 2</span>αn <span class="p">which gives us a nice recursion to work on. Let’s assume the time to multiply in the base case is </span>µ<span class="p">. The base case is when both of our numbers are 1 digit long </span>M <span class="s9">(1) = </span>µ<span class="p">.</span></p><p class="s9" style="padding-top: 1pt;padding-left: 3pt;text-indent: 0pt;text-align: left;">4<span class="s16">0</span>(2<span class="s15">αn</span>)</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 1pt;padding-left: 68pt;text-indent: 0pt;text-align: left;">2<span class="s15">αn</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-top: 2pt;padding-left: 10pt;text-indent: 0pt;text-align: left;">· · ·</p><p class="s3" style="padding-top: 2pt;padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p class="s3" style="padding-top: 2pt;padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p class="s9" style="padding-top: 4pt;padding-left: 15pt;text-indent: 0pt;text-align: left;">2<span class="s15">α </span><span class="s26">n</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="113" height="25" alt="image" src="cmsc351/Image_058.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="145" height="21" alt="image" src="cmsc351/Image_059.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="160" height="25" alt="image" src="cmsc351/Image_060.png"/></span></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p class="s3" style="padding-top: 10pt;text-indent: 0pt;text-align: right;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="text-indent: 0pt;line-height: 12pt;text-align: left;">4<span class="s16">1</span>(2<span class="s15">α </span><span class="s26">n</span><span class="s15"> </span>)</p><p style="padding-left: 23pt;text-indent: 0pt;line-height: 12pt;text-align: left;"/><p style="text-indent: 0pt;text-align: left;"><span><img width="58" height="25" alt="image" src="cmsc351/Image_061.png"/></span></p><p style="padding-top: 8pt;text-indent: 0pt;text-align: center;">.</p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="padding-top: 14pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">· · ·</p><p class="s61" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2<span class="s64">k</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s9">4</span>k<span class="s9">(2</span>α<u> n</u> <span class="s9">)</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2<span class="s15">α</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s58" style="text-indent: 0pt;line-height: 8pt;text-align: left;"> <span class="s55">n </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="padding-top: 8pt;padding-left: 8pt;text-indent: 0pt;text-align: left;">· · · <span class="s59">2</span><span class="s85">k </span><span><img width="63" height="25" alt="image" src="cmsc351/Image_062.png"/></span></p><p class="s14" style="padding-top: 1pt;padding-left: 3pt;text-indent: 0pt;text-align: left;"><span class="s70">4</span>lg(<span class="s11">n</span>)<span class="s86">µ</span></p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 210pt;text-indent: 0pt;text-align: left;"><span><img width="59" height="21" alt="image" src="cmsc351/Image_063.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 6pt;text-indent: 0pt;text-align: left;">Which is fun, I’m having fun.</p><p class="s15" style="padding-left: 6pt;text-indent: 0pt;line-height: 9pt;text-align: left;">µ µ µ µ</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 66pt;text-indent: 0pt;text-align: left;">atomic actions <span class="s9">=</span></p><p class="s14" style="padding-top: 2pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">lg(<span class="s11">n</span>)<span class="s24">−</span>1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">i<span class="s14">=0</span></p><p class="s15" style="padding-top: 7pt;text-indent: 0pt;line-height: 17pt;text-align: left;"><span class="s9">(4</span>i<span class="s9">(2</span>α <u>n</u> <span class="s9">)) + 4</span><span class="s16">lg(</span>n<span class="s16">)</span>µ</p><p class="s70" style="padding-left: 26pt;text-indent: 0pt;line-height: 38%;text-align: left;">2<span class="s11">i</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="text-indent: 0pt;text-align: right;">= 2<span class="s15">αn</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="text-indent: 0pt;text-align: right;">= 2<span class="s15">αn</span></p><p class="s14" style="text-indent: 0pt;line-height: 13pt;text-align: left;">lg <span class="s11">n</span><span class="s24">−</span>1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 4pt;text-align: left;">i<span class="s14">=0 lg </span>n<span class="s24">−</span><span class="s14">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">( )</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 4pt;text-indent: 0pt;text-align: left;">i<span class="s14">=0</span></p><p class="s87" style="padding-top: 4pt;text-indent: 0pt;line-height: 9pt;text-align: left;">4<span class="s11">i</span></p><p class="s30" style="text-indent: 0pt;line-height: 67%;text-align: left;">2<span class="s48">i </span><span class="s3">· · ·</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="text-indent: 0pt;text-align: left;">2<span class="s15">i </span><span class="s3">· · ·</span></p><p class="s9" style="padding-left: 132pt;text-indent: 0pt;line-height: 17pt;text-align: left;">= 2<span class="s15">αn </span>2<span class="s16">lg </span><span class="s15">n</span><span class="s3">−</span><span class="s16">1+1 </span><span class="s3">− </span>1 <span class="s3">· · · </span><span class="p">geometric series</span></p><p class="s15" style="padding-left: 132pt;text-indent: 0pt;line-height: 17pt;text-align: left;"><span class="s9">= 2</span>αn <span class="s9">(</span>n <span class="s3">− </span><span class="s9">1) + 4</span><span class="s16">lg(</span>n<span class="s16">)</span>µ</p><p class="s15" style="padding-left: 132pt;text-indent: 0pt;line-height: 17pt;text-align: left;"><span class="s9">= 2</span>αn <span class="s9">(</span>n <span class="s3">− </span><span class="s9">1) + </span>n<span class="s16">lg(4)</span>µ <span class="s9">4</span><span class="s16">lg(</span>n<span class="s16">)</span>µ <span class="s9">= </span>n<span class="s16">lg 4</span>µ</p><p class="s15" style="padding-left: 132pt;text-indent: 0pt;line-height: 16pt;text-align: left;"><span class="s9">= 2</span>αn <span class="s9">(</span>n <span class="s3">− </span><span class="s9">1) + </span>n<span class="s16">2</span>µ n<span class="s16">lg 4</span>µ <span class="s9">= </span>n<span class="s16">2</span>µ</p><p class="s15" style="padding-left: 132pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s9">= 2</span>αn <span class="s9">(</span>n <span class="s3">− </span><span class="s9">1) + </span>n<span class="s16">2</span>µ</p><p style="padding-top: 5pt;padding-left: 7pt;text-indent: 0pt;line-height: 88%;text-align: left;">We’re doing <span class="s15">n</span><span class="s16">2 </span>multiplications and <span class="s15">n</span><span class="s16">2 </span>additions, so our application of recursion didn’t improve the running time of our algorithm. There’s a better way!</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark73">Better Multiplication</a><a name="bookmark79">‌</a></h3><p class="s9" style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">With the distributive law </span>(<span class="s15">a </span>+ <span class="s15">b</span>)(<span class="s15">c </span>+ <span class="s15">d</span>) = <span class="s15">ac </span>+ <span class="s15">ad </span>+ <span class="s15">bc </span>+ <span class="s15">bd</span><span class="p">, we can use this property to improve the fast multiplication algorithm. This will let us replace 1 recursive multiplication with 1 new addition and 1 subtraction, as we shall see.</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="24" height="34" alt="image" src="cmsc351/Image_064.png"/></span></p><p class="s15" style="padding-left: 2pt;text-indent: 0pt;line-height: 10pt;text-align: left;">v</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 3pt;text-indent: 0pt;line-height: 10pt;text-align: left;">u</p><p style="text-indent: 0pt;text-align: left;"/><p class="s88" style="padding-top: 1pt;padding-left: 3pt;text-indent: 0pt;text-align: left;">w <span class="s89">= (</span>a <span class="s89">+ </span>b<span class="s89">)(</span>c <span class="s89">+ </span>d<span class="s89">)</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 123pt;text-indent: 0pt;line-height: 16pt;text-align: left;">2 <span class="s3">·</span><span class="s90"> </span><span class="s55">n</span><span class="s11"> </span><span class="p">additions, 1n multiplication</span></p><p class="s9" style="padding-left: 10pt;text-indent: 0pt;line-height: 79%;text-align: left;">= <span class="s15">ac </span>+ <span class="s15">ad </span>+ <span class="s15">bc </span>+ <span class="s15">bd </span><span class="s91">+ </span><span class="s92">z</span></p><p class="s15" style="padding-top: 3pt;padding-left: 18pt;text-indent: 0pt;text-align: left;">u <span class="s9">= </span>ac <span class="p">1n mult.</span></p><p class="s15" style="padding-top: 1pt;padding-left: 18pt;text-indent: 0pt;line-height: 12pt;text-align: left;">v <span class="s9">= </span>bd <span class="p">1n mult.</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="101" height="23" alt="image" src="cmsc351/Image_065.png"/></span></p><p class="s88" style="padding-left: 18pt;text-indent: 0pt;line-height: 19pt;text-align: left;">z <span class="s89">= </span>w <span class="s93">− </span><span class="s89">(</span>u <span class="s89">+ </span>v<span class="s89">) </span><span class="p">1n addition, and 1n subtraction.</span></p><p class="s15" style="text-indent: 0pt;line-height: 19pt;text-align: left;">T <span class="s9">(</span>n<span class="s9">) = 3</span>T <span class="s12">(</span><span class="s13"> ) </span><span class="s9">+ 4</span>αn, T <span class="s9">(1) = </span>µ<span class="p">.</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 1pt;padding-left: 6pt;text-indent: 0pt;text-align: justify;"><span class="p">By the same logic as the earlier multiplication algorithm, </span>ac <span class="p">and </span>bd <span class="p">are shifted by n bits, and can be concatenated. Let </span>w <span class="s9">= (</span>a <span class="s9">+ </span>b<span class="s9">)(</span>c <span class="s9">+ </span>d<span class="s9">)</span><span class="p">, and </span>z <span class="s9">= </span>w <span class="s9">(</span>ac <span class="s9">+ </span>bd<span class="s9">) = (</span>ad <span class="s9">+ </span>bc<span class="s9">) </span><span class="p">so to calculate </span>z <span class="p">takes 3 Multiplications, 3 additions and 1 subtraction. Let’s treat the subtraction as an addition, 4 additions. As such, the recursion for this algorithm is</span></p><p class="s55" style="padding-left: 60pt;text-indent: 0pt;line-height: 6pt;text-align: left;">n</p><p class="s14" style="padding-left: 61pt;text-indent: 0pt;line-height: 9pt;text-align: left;">2</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="padding-top: 1pt;text-indent: 0pt;line-height: 12pt;text-align: right;">lg <span class="s11">n</span><span class="s24">−</span>1</p><p class="s71" style="text-indent: 0pt;line-height: 58%;text-align: right;">3<span class="s11">i</span></p><p class="s11" style="padding-top: 4pt;text-indent: 0pt;text-align: right;">i<span class="s14">=0</span></p><p class="s9" style="padding-top: 6pt;text-indent: 0pt;line-height: 16pt;text-align: right;">4<span class="s15">α </span><span class="s32">n</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">(</p><p style="text-indent: 0pt;text-align: left;"/><p class="s70" style="text-indent: 0pt;line-height: 45%;text-align: right;">2<span class="s11">i</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;text-align: left;">+ 3<span class="s16">lg </span><span class="s15">nµ </span>= 4<span class="s15">αn</span></p><p class="s70" style="padding-top: 5pt;padding-left: 16pt;text-indent: 0pt;line-height: 113%;text-align: left;">3<span class="s11">i </span>2<span class="s11">i</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="11" height="1" alt="image" src="cmsc351/Image_066.png"/></span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s94" style="padding-top: 3pt;padding-left: 6pt;text-indent: 0pt;line-height: 29%;text-align: left;">( <span class="s61">3 </span>)<span class="s14">lg </span><span class="s11">n</span><span class="s24">−</span><span class="s14">1+1 </span><span class="s45">− </span><span class="s9">1</span></p><p style="padding-left: 12pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_067.png"/></span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">\</p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="padding-left: 12pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">3</p><p style="padding-left: 28pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s71" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">+<span class="s15">n</span><span class="s14">lg 3</span><span class="s95">µ</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;line-height: 4pt;text-align: center;">.</p><p style="text-indent: 0pt;text-align: left;"><span><img width="88" height="1" alt="image" src="cmsc351/Image_068.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_069.png"/></span></p><p class="s9" style="text-indent: 0pt;line-height: 17pt;text-align: right;">= 4<span class="s15">αn </span><span class="s3">·</span></p><p style="padding-left: 43pt;text-indent: 0pt;line-height: 8pt;text-align: center;">.</p><p class="s13" style="text-indent: 0pt;line-height: 64%;text-align: left;">( ) <span class="s96">− </span><span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s59" style="padding-left: 10pt;text-indent: 0pt;line-height: 15pt;text-align: left;">2 <span class="s3">− </span><span class="s9">1</span></p><p class="s9" style="padding-top: 6pt;text-indent: 0pt;text-align: right;">= 4<span class="s15">αn </span><span class="s3">·</span></p><p class="s61" style="padding-left: 7pt;text-indent: 0pt;line-height: 74%;text-align: left;">3 <span class="s14">lg </span><span class="s11">n</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_070.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="61" height="1" alt="image" src="cmsc351/Image_071.png"/></span></p><p style="text-indent: 0pt;line-height: 12pt;text-align: left;">.</p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="padding-left: 7pt;text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_072.png"/></span></p><p class="s14" style="padding-left: 22pt;text-indent: 0pt;line-height: 7pt;text-align: left;">1</p><p class="s15" style="padding-top: 5pt;text-indent: 0pt;text-align: left;"><span class="s9">= 8</span>αn<span class="s97"> </span>n<span class="s16">lg</span><span class="s21">( </span><span class="s98">3 </span><span class="s21">) </span><span class="s3">− </span><span class="s9">1</span><span class="s99"> </span><span class="s82">.</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="padding-left: 22pt;text-indent: 0pt;line-height: 9pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"><span><img width="5" height="0" alt="image" src="cmsc351/Image_073.png"/></span></p><p class="s62" style="padding-top: 6pt;padding-left: 252pt;text-indent: 0pt;text-align: left;">2 <span class="s100">.</span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">= 8<span class="s15">αn</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s86" style="text-indent: 0pt;text-align: left;">n<span class="s14">lg 2 </span><span class="s90">−</span><span class="s3"> </span><span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"/><p style="text-indent: 0pt;line-height: 12pt;text-align: left;">.</p><p style="text-indent: 0pt;text-align: left;"/><p style="text-indent: 0pt;line-height: 12pt;text-align: left;">.</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 5pt;padding-left: 201pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s9">= 8</span>αn<span class="s101"> </span>n<span class="s16">lg 3</span><span class="s3">−</span><span class="s16">lg 2 </span><span class="s3">− </span><span class="s9">1</span><span class="s12">l</span><span class="s13"> </span><span class="p">.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 237pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="24" height="1" alt="image" src="cmsc351/Image_074.png"/></span></p><p class="s102" style="padding-left: 230pt;text-indent: 0pt;text-align: left;"> <span class="s13"> </span><span class="s86">n</span><span class="s14">lg 3 </span>7 <span class="s31">.</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="24" height="1" alt="image" src="cmsc351/Image_075.png"/></span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">= 8<span class="s15">αn</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s103" style="text-indent: 0pt;line-height: 64%;text-align: left;">n <span class="s3">− </span><span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"/><p style="text-indent: 0pt;line-height: 12pt;text-align: left;">.</p><p style="text-indent: 0pt;text-align: left;"/><p class="s102" style="padding-top: 4pt;padding-left: 230pt;text-indent: 0pt;text-align: left;"> <span class="s13"> </span><span class="s86">n</span><span class="s14">lg 3 </span>7 <span class="s31">.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> l</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 2pt;padding-left: 62pt;text-indent: 0pt;line-height: 18pt;text-align: center;"><span class="s9">= 8</span>α n<span class="s16">lg 3 </span><span class="s3">− </span>n <span class="s9">+ </span>n<span class="s16">lg 3</span>µ</p><p class="s14" style="padding-left: 29pt;text-indent: 0pt;line-height: 2pt;text-align: center;">lg 3</p><p class="s15" style="padding-left: 50pt;text-indent: 0pt;line-height: 14pt;text-align: center;"><span class="s3">≈ </span>n <span class="s9">[8</span>α <span class="s9">+ </span>µ<span class="s9">]</span></p><p class="s15" style="padding-left: 52pt;text-indent: 0pt;line-height: 18pt;text-align: center;"><span class="s3">≈ </span>n<span class="s16">1</span>.<span class="s16">57 </span><span class="s9">[8</span>α <span class="s9">+ </span>µ<span class="s9">]</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-top: 4pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><span class="p">This is </span>O<span class="s9">(</span>n<span class="s16">1</span>.<span class="s16">57</span><span class="s9">)</span><span class="p">, a better result than the previous algorithm.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><ol id="l6"><li style="padding-left: 30pt;text-indent: -23pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark80">Recursion Master Formula</a><a name="bookmark86">‌</a></h2><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_076.png"/></span></p><p class="s15" style="padding-top: 8pt;text-indent: 0pt;text-align: right;">T <span class="s9">(</span>n<span class="s9">) = </span>aT <span class="s9">(</span></p><p class="s9" style="padding-top: 6pt;text-indent: 0pt;line-height: 56%;text-align: left;"><span class="s34">n </span>) + <span class="s15">cnd, T </span>(1) = <span class="s15">f b</span></p><p style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Kruskal claims this is a better formula than the master theorem in the book, easier to use and more applicable. Let’s solve using tree method.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 10pt;text-indent: 0pt;text-align: left;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-left: 4pt;text-indent: 0pt;text-align: left;">cnd</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="160" height="21" alt="image" src="cmsc351/Image_077.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="168" height="25" alt="image" src="cmsc351/Image_078.png"/></span></p><p class="s3" style="padding-top: 6pt;padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s55" style="padding-left: 7pt;text-indent: 0pt;line-height: 90%;text-align: left;">n<span class="s11"> d b</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="144" height="21" alt="image" src="cmsc351/Image_079.png"/></span></p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">c</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s104" style="text-indent: 0pt;line-height: 59%;text-align: left;">b<span class="s64">n</span><span class="s105">−</span><span class="s62">1</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s58" style="padding-left: 21pt;text-indent: 0pt;line-height: 81%;text-align: left;"> <span class="s55">n</span><span class="s11"> d </span><span class="s104">b</span><span class="s62">2</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="113" height="25" alt="image" src="cmsc351/Image_080.png"/></span></p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">c</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p class="s3" style="padding-top: 10pt;text-indent: 0pt;text-align: right;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="24" height="18" alt="image" src="cmsc351/Image_081.png"/></span></p><p class="s86" style="padding-left: 3pt;text-indent: 0pt;text-align: left;">f<span class="s15"> a</span><span class="s14">log</span><span class="s106">b </span><span class="s11">n</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="padding-left: 6pt;text-indent: 0pt;text-align: left;">· · ·</p><p class="s3" style="padding-top: 10pt;padding-left: 8pt;text-indent: 0pt;text-align: left;">· · ·</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="59" height="17" alt="image" src="cmsc351/Image_082.png"/></span></p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">c</p><p style="text-indent: 0pt;text-align: left;"/><p class="s58" style="padding-left: 10pt;text-indent: 0pt;line-height: 81%;text-align: left;"> <span class="s55">n </span><span class="s11"> d </span><span class="s104">b</span><span class="s64">n</span><span class="s105">−</span><span class="s62">1</span></p><p style="text-indent: 0pt;line-height: 11pt;text-align: left;">num rows sum</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="16" height="18" alt="image" src="cmsc351/Image_083.png"/></span></p><p class="s15" style="padding-top: 2pt;padding-left: 3pt;text-indent: 0pt;text-align: left;">cnd</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 18pt;text-indent: 0pt;text-align: left;">1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="16" height="15" alt="image" src="cmsc351/Image_084.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="22" height="20" alt="image" src="cmsc351/Image_085.png"/></span></p><p class="s104" style="text-indent: 0pt;line-height: 56%;text-align: left;">b<span class="s62">2</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="text-indent: 0pt;line-height: 13pt;text-align: left;">a<span class="s16">2</span>c<span class="s9">(</span><span class="s10"> </span><u>n</u> <span class="s9">)</span>d</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">b</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="text-indent: 0pt;line-height: 12pt;text-align: left;">ac<span class="s9">( </span><u>n</u> <span class="s9">)</span>d</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 16pt;text-indent: 2pt;line-height: 150%;text-align: left;">a <span><img width="49" height="25" alt="image" src="cmsc351/Image_086.png"/></span><span class="s65"> </span><span class="s86">a</span><span class="s14">2 </span><span><img width="58" height="25" alt="image" src="cmsc351/Image_087.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="85" height="25" alt="image" src="cmsc351/Image_088.png"/></span></p><p style="padding-top: 7pt;padding-left: 47pt;text-indent: 0pt;text-align: left;">.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s86" style="padding-left: 3pt;text-indent: 0pt;line-height: 13pt;text-align: left;">a<span class="s11">n</span><span class="s24">−</span><span class="s14">1</span></p><p class="s11" style="text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s86">a</span>n<span class="s24">−</span><span class="s14">1</span><span class="s86">c</span><span class="s9">(</span><span class="s10"> </span><u>n</u> <span class="s70">)</span>d</p><p style="padding-left: 6pt;text-indent: 0pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 6pt;text-indent: 0pt;text-align: left;">You will get <span class="s9">log</span><span class="s104">b </span><span class="s15">n </span>levels, the branching factor is a.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-left: 6pt;text-indent: 0pt;text-align: left;">f f f</p><p class="s107" style="padding-top: 7pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">f <span class="s86">a</span><span class="s11">n</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="padding-top: 2pt;text-indent: 0pt;text-align: right;">log<span class="s106">b </span><span class="s11">n</span><span class="s24">−</span>1</p><p class="s15" style="padding-top: 7pt;text-indent: 0pt;line-height: 14pt;text-align: left;">aic<span class="s9">( </span><u>n</u> <span class="s9">)</span><span class="s108">d</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 1pt;text-indent: 0pt;line-height: 8pt;text-align: left;">= <span class="s15">cnd</span></p><p class="s14" style="padding-top: 2pt;text-indent: 0pt;text-align: left;">log<span class="s106">b </span><span class="s11">n</span><span class="s24">−</span>1 <span class="s109">a</span><span class="s39">i</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s71" style="padding-left: 62pt;text-indent: 0pt;line-height: 10pt;text-align: center;">+<span class="s15">f n</span><span class="s14">log</span><span class="s106">b </span><span class="s11">a</span></p><p class="s11" style="padding-top: 6pt;text-indent: 0pt;text-align: right;">i<span class="s14">=0</span></p><p class="s86" style="padding-top: 1pt;padding-left: 62pt;text-indent: 0pt;line-height: 57%;text-align: center;">b<span class="s11">i</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-top: 7pt;padding-left: 46pt;text-indent: 0pt;text-align: left;">= <span class="s15">cnd</span></p><p class="s11" style="padding-top: 6pt;text-indent: 8pt;text-align: left;">i<span class="s14">=0 log</span><span class="s106">b </span>n<span class="s24">−</span><span class="s14">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 8pt;text-indent: 0pt;text-align: left;">i<span class="s14">=0</span></p><p class="s110" style="text-indent: 0pt;line-height: 55%;text-align: left;">b<span class="s104">i</span><span class="s11">d</span></p><p class="s111" style="padding-top: 10pt;padding-left: 2pt;text-indent: 0pt;line-height: 10pt;text-align: left;">a<span class="s11">i </span><span class="s100">.</span></p><p class="s9" style="padding-left: 201pt;text-indent: 0pt;line-height: 7pt;text-align: center;">+<span class="p">.</span></p><p class="s110" style="text-indent: 0pt;line-height: 38%;text-align: left;">b<span class="s104">d</span><span class="s11">i</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="text-indent: 0pt;text-align: right;">= <span class="s15">cnd</span></p><p class="s14" style="padding-top: 1pt;text-indent: 0pt;text-align: left;">log<span class="s106">b </span><span class="s11">n</span><span class="s24">−</span>1 <span class="s109">a</span><span class="s15"> </span><span class="s48">i</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">( \</p><p style="text-indent: 0pt;text-align: left;"/><p class="s86" style="padding-top: 1pt;padding-left: 39pt;text-indent: 0pt;line-height: 10pt;text-align: left;">b<span class="s11">d</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="74" height="1" alt="image" src="cmsc351/Image_089.png"/></span></p><p class="s104" style="padding-top: 1pt;text-indent: 0pt;line-height: 56%;text-align: left;">b<span class="s64">d</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s112" style="padding-top: 6pt;text-indent: 0pt;text-align: left;"> <span class="s13"> </span><span class="s14">log ( )</span><span class="s106">b</span><span class="s110">n</span><span class="s15"> </span><span class="s3">− </span><span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 8pt;text-indent: 0pt;line-height: 2pt;text-align: left;">i<span class="s14">=0</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="text-indent: 0pt;line-height: 9pt;text-align: right;">= <span class="s15">cnd</span></p><p class="s114" style="padding-top: 8pt;padding-bottom: 1pt;text-indent: 0pt;line-height: 58%;text-align: left;"><span class="s113"> </span><span class="s13"> </span>(<u> </u><span class="s55">a</span><span class="s11"> </span>)<span class="s14">log</span><span class="s106">b </span><span class="s11">n </span><span class="s116">− </span><span class="s9">1 </span><span class="s113"> </span></p><p class="s58" style="text-indent: 0pt;line-height: 8pt;text-align: left;"> <span class="s55">a </span></p><p style="padding-left: 24pt;text-indent: 0pt;line-height: 8pt;text-align: left;"/><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="text-indent: 0pt;text-align: right;">= <span class="s15">cnd</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-top: 7pt;text-indent: 0pt;text-align: right;">= <span class="s15">cnd</span></p><p class="s39" style="padding-left: 24pt;text-indent: 0pt;line-height: 15pt;text-align: left;">b<span class="s85">d </span><span class="s3">− </span><span class="s9">1</span></p><p class="s64" style="padding-top: 1pt;padding-left: 33pt;text-indent: 0pt;line-height: 84%;text-align: center;"><span class="s117"> </span><u>a</u> <span class="s85">b</span>d</p><p style="text-indent: 0pt;text-align: left;"><span><img width="72" height="1" alt="image" src="cmsc351/Image_090.png"/></span></p><p class="s58" style="text-indent: 0pt;line-height: 8pt;text-align: left;"> <span class="s55">a </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s39" style="padding-top: 1pt;padding-left: 23pt;text-indent: 0pt;text-align: left;">b<span class="s85">d </span><span class="s3">− </span><span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="96" height="1" alt="image" src="cmsc351/Image_091.png"/></span></p><p class="s58" style="text-indent: 0pt;line-height: 8pt;text-align: left;"> <span class="s55">a </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="padding-left: 50pt;text-indent: 0pt;line-height: 17pt;text-align: center;"><span class="s86">n</span>log<span class="s106">b </span><span class="s11">a</span><span class="s24">−</span>log<span class="s106">b </span><span class="s11">bd </span><span class="s76">−</span><span class="s3"> </span><span class="s9">1</span></p><p class="s11" style="text-indent: 0pt;text-align: left;"><span class="s118">d</span> <span class="s102">(</span><span class="s13"> </span><span class="s86">n</span><span class="s14">log</span><span class="s106">b</span><span class="s64"> </span>a<span class="s24">−</span>d <span class="s76">−</span><span class="s3"> </span><span class="s9">1 </span><span class="s102">\</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s39" style="padding-left: 33pt;text-indent: 0pt;line-height: 17pt;text-align: left;">b<span class="s85">d </span><span class="s3">− </span><span class="s9">1</span></p><p class="s9" style="padding-top: 7pt;text-indent: 0pt;text-align: right;">= <span class="s15">cn</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 12pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="72" height="1" alt="image" src="cmsc351/Image_092.png"/></span></p><p class="s39" style="padding-left: 27pt;text-indent: 0pt;line-height: 16pt;text-align: left;">b<span class="s85">d </span><span class="s3">− </span><span class="s9">1</span></p><p class="s58" style="text-indent: 0pt;line-height: 8pt;text-align: left;"> <span class="s55">a </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s86" style="padding-left: 62pt;text-indent: 0pt;line-height: 55%;text-align: center;">cn<span class="s14">log</span><span class="s106">b </span><span class="s11">a </span>cn<span class="s11">d</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="77" height="1" alt="image" src="cmsc351/Image_093.png"/></span></p><p class="s58" style="text-indent: 0pt;line-height: 8pt;text-align: left;"> <span class="s55">a </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 6pt;text-align: center;">= + <span class="p">.</span></p><p class="s39" style="padding-left: 62pt;text-indent: 0pt;line-height: 15pt;text-align: center;">b<span class="s85">d </span><span class="s3">− </span><span class="s9">1</span></p><p class="s86" style="text-indent: 0pt;line-height: 55%;text-align: right;">cn<span class="s14">log</span><span class="s106">b </span><span class="s11">a</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="41" height="1" alt="image" src="cmsc351/Image_094.png"/></span></p><p class="s58" style="text-indent: 0pt;line-height: 8pt;text-align: left;"> <span class="s55">a </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 6pt;text-align: right;">=</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">(</p><p style="text-indent: 0pt;text-align: left;"/><p class="s39" style="text-indent: 0pt;line-height: 9pt;text-align: right;">b<span class="s85">d </span><span class="s3">− </span><span class="s9">1</span></p><p class="s15" style="padding-left: 18pt;text-indent: 0pt;line-height: 7pt;text-align: left;">cnd</p><p style="text-indent: 0pt;text-align: left;"><span><img width="36" height="1" alt="image" src="cmsc351/Image_095.png"/></span></p><p class="s104" style="padding-top: 1pt;text-indent: 0pt;line-height: 56%;text-align: left;">b<span class="s64">d</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s119" style="padding-left: 1pt;text-indent: 0pt;line-height: 42%;text-align: left;">−<u> </u><span class="s55">a</span><span class="s11"> </span><span class="s120">− </span><span class="s9">1</span></p><p class="s71" style="padding-top: 4pt;padding-left: 1pt;text-indent: 0pt;text-align: left;">+ <span class="s15">f n</span><span class="s14">log</span><span class="s106">b </span><span class="s11">a</span></p><p class="s75" style="padding-top: 5pt;text-indent: 0pt;line-height: 10pt;text-align: right;"> <span class="s26">c </span></p><p class="s58" style="text-indent: 0pt;line-height: 8pt;text-align: left;"> <span class="s55">a </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 5pt;text-align: right;">=</p><p class="s39" style="text-indent: 0pt;line-height: 16pt;text-align: right;">b<span class="s85">d </span><span class="s3">− </span><span class="s9">1</span></p><p class="s9" style="padding-left: 1pt;text-indent: 0pt;line-height: 24pt;text-align: left;">+ <span class="s15">f </span><span class="s121">\</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><ul id="l7"><li style="padding-left: 4pt;text-indent: -4pt;line-height: 15pt;text-align: left;"><p class="s15" style="display: inline;">n</p></li></ul><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="padding-left: 11pt;text-indent: 0pt;text-align: left;">log<span class="s106">b </span><span class="s11">a</span></p><p class="s15" style="padding-top: 5pt;padding-left: 18pt;text-indent: 0pt;line-height: 8pt;text-align: left;">cnd</p><p style="text-indent: 0pt;text-align: left;"><span><img width="36" height="1" alt="image" src="cmsc351/Image_096.png"/></span></p><p class="s104" style="padding-top: 1pt;text-indent: 0pt;line-height: 56%;text-align: left;">b<span class="s64">d</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s119" style="text-indent: 0pt;line-height: 93%;text-align: left;">−<u> </u><span class="s55">a</span><span class="s11"> </span><span class="s120">− </span><span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-top: 5pt;padding-left: 7pt;text-indent: 0pt;line-height: 93%;text-align: justify;"><span class="p">This formula can’t apply to the situation when the value of a geometric sum would be 1. The geometric sum isn’t applicable in that case. SO this equation isn’t applicable when </span>a <span class="s9">= </span>bd<span class="p">, we need a special case. When the r term = 1, a geometric series becomes a simple summation of 1, thus in this case if </span>a <span class="s9">= </span>bd <span class="p">the formula becomes </span>cnd <span class="s9">log</span><span class="s104">b </span>n <span class="s9">+ </span>f n<span class="s16">log</span><span class="s122">b </span><span class="s68">a</span><span class="p">. In the special case of merge sort, we drop the constant -1 from the non recursion part of the term, and apply the special case, then we repeat the process with the n dropped, and add the two results.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-top: 14pt;text-indent: 0pt;text-align: right;">a <span class="s3">/</span><span class="s9">= </span>b</p><p class="s104" style="padding-top: 10pt;text-indent: 0pt;line-height: 12pt;text-align: right;">d<u> </u><span class="s26">c </span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">(</p><p style="text-indent: 0pt;text-align: left;"/><p class="s58" style="text-indent: 0pt;line-height: 8pt;text-align: left;"> <span class="s55">a </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s39" style="text-indent: 0pt;line-height: 18pt;text-align: right;">b<span class="s85">d </span><span class="s3">− </span><span class="s9">1</span></p><p class="s9" style="padding-top: 3pt;padding-left: 1pt;text-indent: 0pt;text-align: left;">+ <span class="s15">f </span><span class="s121">\</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><ul id="l8"><li style="padding-left: 4pt;text-indent: -4pt;line-height: 15pt;text-align: left;"><p class="s15" style="display: inline;">n</p></li></ul><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="padding-top: 6pt;padding-left: 11pt;text-indent: 0pt;text-align: left;">log<span class="s106">b </span><span class="s11">a</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-left: 18pt;text-indent: 0pt;line-height: 8pt;text-align: left;">cnd</p><p style="text-indent: 0pt;text-align: left;"><span><img width="36" height="1" alt="image" src="cmsc351/Image_097.png"/></span></p><p class="s104" style="padding-top: 1pt;text-indent: 0pt;line-height: 56%;text-align: left;">b<span class="s64">d</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s119" style="text-indent: 0pt;line-height: 93%;text-align: left;">−<u> </u><span class="s55">a</span><span class="s11"> </span><span class="s120">− </span><span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-top: 3pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">a <span class="s9">= </span>bd cnd <span class="s9">log</span><span class="s104">b </span>n <span class="s9">+ </span>f n<span class="s16">log</span><span class="s122">b </span><span class="s123">a</span></p><p style="padding-top: 8pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">The relative sizes of these constant factors will overwhelm in differing circumstances.</p><p class="s58" style="text-indent: 0pt;line-height: 8pt;text-align: left;"> <span class="s55">a </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">− <span class="s9">1</span><span class="s85">d</span><span class="s39">b</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 1pt;text-indent: 0pt;text-align: center;">a > bd <span class="s3">→</span>T <span class="s9">(</span>n<span class="s9">) </span><span class="s3">≈ </span><span class="s121">(</span><span class="s124"> </span><u>c </u> <span class="s9">+ </span>f <span class="s121">\ </span><span class="s3">· </span>n<span class="s16">log</span><span class="s122">b </span><span class="s123">a </span><span class="s9">= Θ(</span>n<span class="s16">log</span><span class="s122">b </span><span class="s123">a</span><span class="s9">)</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="text-indent: 0pt;text-align: right;">a < bd</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="text-indent: 0pt;line-height: 8pt;text-align: right;">cnd</p><p style="text-indent: 0pt;text-align: left;"><span><img width="36" height="1" alt="image" src="cmsc351/Image_098.png"/></span></p><p class="s104" style="padding-top: 1pt;text-indent: 0pt;line-height: 56%;text-align: left;">b<span class="s64">d</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="padding-left: 1pt;text-indent: 0pt;line-height: 68%;text-align: left;">→<span class="s15">T </span><span class="s9">(</span><span class="s15">n</span><span class="s9">) </span>≈ <span class="s30">1 </span>−<u> </u><span class="s55">a </span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">= Θ(<span class="s15">nd</span>)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-top: 2pt;padding-left: 83pt;text-indent: 0pt;text-align: left;">a <span class="s9">= </span>bd <span class="s3">→</span>T <span class="s9">(</span>n<span class="s9">) </span><span class="s3">≈ </span>cnd <span class="s9">log</span><span class="s104">b </span>n <span class="p">because </span>d <span class="s9">= log</span><span class="s104">b </span>a <span class="s9">= Θ(</span>nd<span class="s9">(log</span><span class="s104">b </span>n<span class="s9">))</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark81">Applying to known algorithms</a><a name="bookmark87">‌</a></h3><h4 style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark82">Multiplication</a><a name="bookmark88">‌</a></h4><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="text-indent: 0pt;text-align: right;">T <span class="s9">(</span>n<span class="s9">) = 4</span>T <span class="s9">(</span></p><p class="s15" style="padding-top: 3pt;text-indent: 0pt;line-height: 9pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_099.png"/></span></p><p class="s9" style="padding-left: 6pt;text-indent: 0pt;line-height: 7pt;text-align: left;">) + 2<span class="s15">αn, T </span>(1) = <span class="s15">µ</span></p><p class="s9" style="text-indent: 0pt;line-height: 9pt;text-align: left;">2</p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">a <span class="s9">= 4</span>, b <span class="s9">= 2</span>, c <span class="s9">= 2</span>α, d <span class="s9">= 1</span>, f <span class="s9">= </span>µ</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">(</p><p style="text-indent: 0pt;text-align: left;"/><p class="s75" style="padding-top: 9pt;text-indent: 0pt;line-height: 12pt;text-align: right;"> <span class="s10">2</span><span class="s26">α</span></p><p class="s9" style="text-indent: 0pt;line-height: 17pt;text-align: right;">2 <span class="s3">− </span>1</p><p class="s25" style="padding-top: 10pt;padding-left: 1pt;text-indent: 0pt;line-height: 59%;text-align: left;">+ <span class="s15">µ n</span><span class="s61">lg 4</span><span class="s57"> </span><u>2</u><span class="s26">αn</span></p><p class="s13" style="text-indent: 0pt;line-height: 64%;text-align: left;">\ <span class="s126">−</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 57pt;text-indent: 0pt;line-height: 14pt;text-align: left;">2 <span class="s3">− </span>1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark83">Better Multiplication</a><a name="bookmark89">‌</a></h4><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 15pt;text-align: left;">= (2<span class="s15">α </span>+ <span class="s15">µ</span>) <span class="s15">n</span><span class="s16">2 </span><span class="s3">− </span>2<span class="s15">αn </span><span class="s3">≈ </span>Θ(<span class="s15">n</span><span class="s16">2</span>)</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">( )</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 16pt;text-align: left;"><span class="s9">= 2</span>α n<span class="s16">2 </span><span class="s3">− </span>n <span class="s9">+ </span>µn<span class="s16">2</span></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s3">≈ </span>Θ(<span class="s15">n </span>)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="text-indent: 0pt;text-align: right;">T <span class="s9">(</span>n<span class="s9">) = 3</span>T <span class="s9">(</span></p><p class="s15" style="padding-top: 3pt;text-indent: 0pt;line-height: 9pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_100.png"/></span></p><p class="s9" style="padding-left: 6pt;text-indent: 0pt;line-height: 7pt;text-align: left;">) + 4<span class="s15">αn, T </span>(1) = <span class="s15">µ</span></p><p class="s9" style="text-indent: 0pt;line-height: 9pt;text-align: left;">2</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">(</p><p style="text-indent: 0pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 64%;text-align: left;">\ <span class="s126">−</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">a <span class="s9">= 3</span>, b <span class="s9">= 2</span>, c <span class="s9">= 4</span>α, d <span class="s9">= 1</span>, f <span class="s9">= </span>µ</p><p class="s75" style="padding-top: 3pt;text-indent: 0pt;line-height: 12pt;text-align: right;"> <span class="s10">4</span><span class="s26">α</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_101.png"/></span></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">3</p><p style="text-indent: 0pt;text-align: left;"/><p class="s59" style="text-indent: 0pt;line-height: 18pt;text-align: right;">2 <span class="s3">− </span><span class="s9">1</span></p><p class="s25" style="padding-top: 4pt;padding-left: 1pt;text-indent: 0pt;line-height: 61%;text-align: left;">+ <span class="s15">µ n</span><span class="s61">lg 3</span><span class="s57"> </span><u>4</u><span class="s26">αn</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_102.png"/></span></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">3</p><p style="text-indent: 0pt;text-align: left;"/><p class="s59" style="padding-left: 59pt;text-indent: 0pt;line-height: 15pt;text-align: left;">2 <span class="s3">− </span><span class="s9">1</span></p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 17pt;text-align: center;"><span class="s9">= (8</span>α <span class="s9">+ </span>µ<span class="s9">) </span>n<span class="s16">1</span>.<span class="s16">57 </span><span class="s3">− </span><span class="s9">8</span>αn <span class="s3">≈ </span><span class="s9">Θ(</span>n<span class="s16">1</span>.<span class="s16">57</span><span class="s9">)</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark84">Mergesort</a><a name="bookmark90">‌</a></h4><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">When we get</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 6pt;text-indent: 0pt;text-align: left;">T <span class="s9">(</span>n<span class="s9">) = 2</span>T <span class="s9">( </span><u>n</u> <span class="s9">) + </span>n <span class="s3">− </span><span class="s9">1</span>, T <span class="s9">(1) = 0</span></p><p style="padding-left: 80pt;text-indent: 0pt;text-align: left;"><span><img width="269" height="35" alt="image" src="cmsc351/Image_103.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="36" alt="image" src="cmsc351/Image_104.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="35" alt="image" src="cmsc351/Image_105.png"/></span></p><p class="s15" style="padding-left: 10pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="p">n term: </span>a <span class="s9">= 2</span>, b <span class="s9">= 2</span>, c <span class="s9">= 1</span>, d <span class="s9">= 1</span></p><p class="s9" style="padding-left: 10pt;text-indent: 0pt;line-height: 17pt;text-align: left;"><span class="p">-1 term: </span><span class="s15">a </span>= 2<span class="s15">, b </span>= 2<span class="s15">, c </span>= <span class="s3">−</span>1<span class="s15">, d </span>= 0</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-top: 5pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">a <span class="s9">= </span>bd</p><p style="padding-left: 80pt;text-indent: 0pt;text-align: left;"><span><img width="1" height="35" alt="image" src="cmsc351/Image_106.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="33" alt="image" src="cmsc351/Image_107.png"/></span></p><p class="s15" style="padding-top: 2pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">cnd <span class="s9">log</span><span class="s104">b </span>n</p><p class="s15" style="padding-top: 1pt;text-indent: 0pt;text-align: right;">a <span class="s3">/</span><span class="s9">= </span>bd</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="28" alt="image" src="cmsc351/Image_108.png"/></span></p><p class="s117" style="text-indent: 0pt;line-height: 6pt;text-align: left;"> <span class="s77">a </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 64%;text-align: left;">( \ <span class="s127">·</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s58" style="padding-left: 59pt;text-indent: 0pt;line-height: 10pt;text-align: left;"> <span class="s55">c</span><span class="s11"> </span><span class="s70">+ </span><span class="s15">f n</span><span class="s14">log</span><span class="s106">b</span></p><p class="s128" style="padding-left: 62pt;text-indent: 0pt;line-height: 10pt;text-align: center;">b<span class="s106">d </span><span class="s24">−</span><span class="s14">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-top: 6pt;text-indent: 0pt;line-height: 7pt;text-align: left;">a cnd</p><p style="padding-left: 18pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="27" height="1" alt="image" src="cmsc351/Image_109.png"/></span></p><p class="s128" style="padding-left: 19pt;text-indent: 0pt;line-height: 10pt;text-align: left;">b<span class="s106">d </span><span class="s24">−</span><span class="s14">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 279pt;text-indent: 0pt;text-align: left;"><span><img width="1" height="23" alt="image" src="cmsc351/Image_110.png"/></span></p><p class="s62" style="text-indent: 0pt;line-height: 5pt;text-align: left;">0</p><p style="text-indent: 0pt;text-align: left;"/><ul id="l9"><li style="padding-top: 1pt;padding-bottom: 2pt;padding-left: 55pt;text-indent: -11pt;line-height: 7pt;text-align: left;"><p class="s14" style="display: inline;"><span class="s61">1</span> <span class="s129">2</span><span class="s24">−</span>1</p></li></ul><p style="padding-left: 238pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="38" height="1" alt="image" src="cmsc351/Image_111.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 239pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="21" height="0" alt="image" src="cmsc351/Image_112.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s117" style="text-indent: 0pt;line-height: 6pt;text-align: left;"> <span class="s77">a </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s56" style="padding-top: 1pt;padding-bottom: 3pt;text-indent: 0pt;line-height: 7pt;text-align: left;"><span class="s86">n</span><span class="s14">lg 2 </span><span class="s76">− </span>−<span class="s57">1</span>·<span class="s55">n </span></p><p class="s62" style="text-indent: 0pt;line-height: 5pt;text-align: left;">2</p><p style="padding-left: 34pt;text-indent: 0pt;line-height: 5pt;text-align: left;"/><p class="s9" style="padding-left: 37pt;text-indent: 0pt;line-height: 79%;text-align: left;">1 <span class="s15">n </span>log<span class="s61">2 </span><span class="s15">n </span>= <span class="s15">n </span>lg <span class="s15">n</span></p><p class="s62" style="padding-top: 1pt;padding-left: 37pt;text-indent: 0pt;text-align: left;">2<span class="s78">0</span><span class="s105">−</span>1 <span class="s130">−</span><span class="s14">1</span></p><p class="s131" style="padding-top: 1pt;padding-left: 19pt;text-indent: 0pt;text-align: left;">2<span class="s132">0 </span><span class="s24">−</span><span class="s14">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 279pt;text-indent: 0pt;text-align: left;"><span><img width="1" height="31" alt="image" src="cmsc351/Image_113.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark85">Implementation details</a><a name="bookmark91">‌</a></h4><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 17pt;text-align: left;">= <span class="s3">−</span><span class="s15">n </span>+ 1</p><p class="s9" style="padding-top: 7pt;padding-left: 6pt;text-indent: 0pt;text-align: justify;"><span class="p">This gives us the incredible ability to use the constants of the recurrence into a running time and determine if it will be greater than another algorithm in constant time. There’s also the Schonhage Strassen algorithm, which is </span>Θ(<span class="s15">n </span>log <span class="s15">n </span>log log <span class="s15">n</span>)<span class="p">.</span></p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 93%;text-align: justify;">In real life, the size of T (1) is the word size of your machine, because the atomic multiplication is implemented at that level. So our atomic base is <span class="s9">2</span><span class="s16">64 </span>for most machines.</p><p style="text-indent: 0pt;text-align: left;"><br/></p></li><li style="padding-left: 38pt;text-indent: -31pt;text-align: justify;"><h2 style="display: inline;"><a name="bookmark92">Heapsort</a><a name="bookmark99">‌</a></h2><p style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Created by J.W.J. Williams Improved by Robert Floyd</p><ul id="l10"><li style="padding-top: 7pt;padding-left: 31pt;text-indent: -10pt;text-align: left;"><p style="display: inline;">Create Heap</p></li><li style="padding-left: 31pt;text-indent: -10pt;text-align: left;"><p style="display: inline;">Finish</p><p style="text-indent: 0pt;text-align: left;"><span><img width="294" height="258" alt="image" src="cmsc351/Image_114.png"/></span></p><h4 style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Definition 10.1 <span class="p">(Heap)</span>. <span class="p">A binary tree where every value is larger than its children. Equivalently its descendants. In this class we require that all binary trees are full binary trees.</span></h4><p class="s9" style="padding-top: 7pt;padding-left: 128pt;text-indent: 0pt;text-align: left;">100</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 74pt;text-indent: 0pt;text-align: left;">90 70</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 37pt;text-indent: 0pt;text-align: left;">80 50 60 10</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 12pt;text-indent: 0pt;text-align: left;">20 30 40</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-top: 5pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark93">Create Heap</a><a name="bookmark100">‌</a></h3><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Turn a tree into a heap.</p><p style="padding-left: 6pt;text-indent: 0pt;text-align: justify;">The traditional way to create a heap is to insert at the end of the array and sift up. Robert Floyd created a better way to create the heap. Treat the tree as a recursive heap: each parent is the parent to 2 heaps, and sift it from the bottom up. Create heap in left, create heap on right, then sift root down, and move up a level.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark94">Heap Creation Analysis</a><a name="bookmark101">‌</a></h4><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">In a binary tree, most nodes are near bottom, so when doing bottom up technique, most work is done near bottom, and because you’re near the bottom you don’t have far to go down. So we take advantage of that fact: Most elements are near the bottom and don’t have far to go.</p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 6pt;text-indent: 0pt;line-height: 11pt;text-align: justify;">There are <span class="s84">n</span><span class="s11"> </span>leaves. Each doing 0 comparisons.</p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">4</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">There are <span class="s84">n</span><span class="s11"> </span>parents of leaves. Each doing 2 comparisons.</p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">8</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">There are <span class="s84">n</span><span class="s11"> </span>grandparents of leaves. Each doing 4 comparisons (2 per level).</p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">16</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 6pt;text-indent: 0pt;line-height: 13pt;text-align: left;">There are<u> </u><span class="s55">n</span><span class="s11"> </span>greatgrandparents of leaves. Each doing 6 comparisons (2 per level).</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-top: 3pt;padding-left: 116pt;text-indent: 0pt;line-height: 8pt;text-align: left;">n n n n n n</p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_115.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_116.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_117.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_118.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_119.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_120.png"/></span></p><p class="s3" style="padding-top: 2pt;padding-left: 117pt;text-indent: 0pt;line-height: 36%;text-align: left;"><span class="s30">2 </span>· <span class="s9">0 + </span><span class="s30">4 </span>· <span class="s9">2 + </span><span class="s30">8 </span>· <span class="s9">4 + </span><span class="s30">16 </span>· <span class="s9">6 + </span><span class="s30">32 </span>· <span class="s9">8 + </span><span class="s30">64 </span>· <span class="s9">10 + </span>· · ·</p><p class="s9" style="padding-left: 185pt;text-indent: 0pt;line-height: 21pt;text-align: left;">= <span class="s15">n </span><span class="s3">·</span><span class="s134"> </span><u>1</u> + <u>2</u> + <u>3</u> +<u> 4</u> +<u> 5</u> + <span class="s3">· · · </span><span class="s121">7 </span><span class="p">This sum is:</span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 10pt;text-align: center;">2 4 6 16 32</p><p class="s9" style="padding-top: 1pt;padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">1 1 1 1 1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_121.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_122.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_123.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_124.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_125.png"/></span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 65%;text-align: center;">= <span class="s30">2 </span>+ <span class="s30">4 </span>+ <span class="s30">8 </span>+ <span class="s30">16 </span>+ <span class="s30">32 </span>+ <span class="s3">· · · </span>= 1</p><p class="s9" style="padding-top: 1pt;padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">1 1 1 1 1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_126.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_127.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_128.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_129.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_130.png"/></span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 64%;text-align: center;">+ <span class="s30">4 </span>+ <span class="s30">8 </span>+ <span class="s30">16 </span>+ <span class="s30">32 </span>+ <span class="s3">· · · </span>= <span class="s30">2</span></p><p class="s9" style="padding-top: 1pt;padding-left: 201pt;text-indent: 0pt;line-height: 8pt;text-align: center;">1 1 1 1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_131.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_132.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_133.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_134.png"/></span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 64%;text-align: center;">+ <span class="s30">8 </span>+ <span class="s30">16 </span>+ <span class="s30">32 </span>+ <span class="s3">· · · </span>= <span class="s30">4</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_135.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_136.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_137.png"/></span></p><p class="s9" style="padding-top: 1pt;padding-left: 201pt;text-indent: 0pt;line-height: 8pt;text-align: center;">1 1 1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">So Heap creation does </span>Θ(2<span class="s15">n</span>) <span class="p">comparisons</span></p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 64%;text-align: left;">+ <span class="s30">16 </span>+ <span class="s30">32 </span>+ <span class="s3">· · · </span>= <span class="s30">8</span></p><p class="s9" style="padding-top: 9pt;padding-left: 77pt;text-indent: 0pt;text-align: left;">+ <span class="p">.</span></p><p class="s9" style="padding-top: 2pt;padding-left: 78pt;text-indent: 0pt;text-align: left;">= 2<span class="s15">n</span></p><h3 style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark95">Finish</a><a name="bookmark102">‌</a></h3><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">•</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 6pt;padding-left: 31pt;text-indent: 0pt;text-align: left;">Put root node at the bottom of the array, as it must be the largest element, so it will go at the end of the sorted array.</p></li><li style="padding-top: 4pt;padding-left: 31pt;text-indent: -10pt;line-height: 19pt;text-align: left;"><p style="display: inline;">Then take the bottom right hand leaf and move to a tmp space.</p></li><li style="padding-left: 31pt;text-indent: -10pt;line-height: 19pt;text-align: left;"><p style="display: inline;">Then sift, reordering the tree and put the tmp leaf in its proper spot.</p></li><li style="padding-left: 31pt;text-indent: -10pt;line-height: 19pt;text-align: left;"><p style="display: inline;">Repeat.</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">≈</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">≈ ≈</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">Sift comparisons: each level has 2 comparisons, child and tmp. There are </span>lg <span class="s15">n </span><span class="p">levels. Total for a sift </span>2 lg <span class="s15">n </span><span class="p">This must be done for each element in the tree, so our heap has an upper bound of </span>2<span class="s15">n </span>lg <span class="s15">n</span><span class="p">.</span></p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">But the heap shrinks, each iteration removes an element. So let’s sum 0 to n-1 (because we remove an element first before sifting).</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-top: 2pt;padding-left: 50pt;text-indent: 0pt;line-height: 4pt;text-align: left;">n<span class="s24">−</span><span class="s14">1 </span>n</p><p class="s9" style="padding-top: 5pt;padding-left: 50pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s22"> </span><span class="s13"> </span>2 lg(<span class="s15">i </span>+ 1) <span class="s3">≈ </span>2<span class="s23"> </span>lg <span class="s15">i</span></p><p class="s11" style="text-indent: 0pt;line-height: 8pt;text-align: right;">i<span class="s14">=0</span></p><p class="s11" style="padding-left: 64pt;text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p class="s9" style="padding-left: 46pt;text-indent: 0pt;line-height: 17pt;text-align: left;">= 2 [lg 1 + lg 2 + lg 3 + <span class="s3">· · · </span>+ lg <span class="s15">n</span>]</p><p class="s13" style="text-indent: 0pt;line-height: 64%;text-align: left;">( \<span class="s15">n</span><span class="s127">≈</span><span class="s3"> ·</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 46pt;text-indent: 0pt;line-height: 13pt;text-align: left;">= 2 lg(1 <span class="s3">· </span>2 <span class="s3">· </span>3 <span class="s3">· · · · </span><span class="s15">n</span>)</p><p style="text-indent: 0pt;text-align: left;"><span><img width="23" height="1" alt="image" src="cmsc351/Image_138.png"/></span></p><p class="s9" style="padding-left: 46pt;text-indent: 0pt;line-height: 16pt;text-align: left;">= 2 lg(<span class="s15">n</span>!) <span class="p">Stirling’s Formula </span><span class="s15">n</span>! <span class="s32">n</span><span class="s15"> </span><span class="s135">√</span>2<span class="s15">πn</span></p><p class="s15" style="text-indent: 0pt;line-height: 4pt;text-align: right;">e</p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">e</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 113pt;text-indent: 0pt;text-align: left;">= 2 lg<span class="s99"> </span><span class="s13">( </span><span class="s32">n</span><span class="s15"> </span><span class="s72">\</span><span class="s136">n </span><span class="s3">· </span><span class="s135">√</span>2<span class="s15">πn</span><span class="s72"> </span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 216pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="5" height="0" alt="image" src="cmsc351/Image_139.png"/></span></p><p class="s15" style="text-indent: 0pt;line-height: 5pt;text-align: right;">n</p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_140.png"/></span></p><p class="s9" style="padding-top: 2pt;text-indent: 0pt;line-height: 37%;text-align: right;"><span class="s3">≈ </span>2 <span class="s15">n </span>lg( <span class="s103">e</span></p><p class="s62" style="padding-left: 52pt;text-indent: 0pt;line-height: 5pt;text-align: left;">1</p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">) + lg((2<span class="s15">πn</span>) <span class="s137">2 </span>)</p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 113pt;text-indent: 0pt;text-align: left;">= 2<span class="s138"> </span><span class="s15">n </span>[lg <span class="s15">n </span><span class="s3">− </span>lg <span class="s15">e</span>] + <u>1</u> lg(2<span class="s15">πn</span>)<span class="s121">7</span></p><p class="s9" style="padding-left: 113pt;text-indent: 0pt;line-height: 18pt;text-align: left;">= 2<span class="s15">n </span>lg <span class="s15">n </span><span class="s3">− </span>2<span class="s15">n </span>lg <span class="s15">e </span>+ lg <span class="s15">n </span>+ lg(2<span class="s15">π</span>)</p><p class="s9" style="padding-left: 113pt;text-indent: 0pt;line-height: 11pt;text-align: left;">= 2<span class="s15">n </span>lg <span class="s15">n </span>+ <span class="s15">O</span>(<span class="s15">n</span>)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><span class="p">This isn’t much better, it makes sense that it’s not much better than our conservative guess, because in a full binary tree, half the elements are leaves. So while the tree shrinks, it doesn’t shrink very fast, asymptotically you’re still doing </span>Θ(2<span class="s15">n </span>lg <span class="s15">n</span>) <span class="p">comparisons, plus some linear term.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark96">Implementation Details</a><a name="bookmark103">‌</a></h3><p style="text-indent: 0pt;text-align: left;"><span><img width="294" height="255" alt="image" src="cmsc351/Image_141.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_142.png"/></span></p><table style="border-collapse:collapse" cellspacing="0"><tr style="height:19pt"><td style="width:22pt;border-top-style:solid;border-top-width:1pt;border-left-style:solid;border-left-width:1pt;border-bottom-style:solid;border-bottom-width:1pt;border-right-style:solid;border-right-width:1pt"><p class="s139" style="padding-top: 2pt;padding-left: 2pt;padding-right: 1pt;text-indent: 0pt;text-align: center;">60</p></td></tr><tr style="height:19pt"><td style="width:22pt;border-top-style:solid;border-top-width:1pt;border-left-style:solid;border-left-width:1pt;border-bottom-style:solid;border-bottom-width:1pt;border-right-style:solid;border-right-width:1pt"><p class="s139" style="padding-top: 2pt;padding-left: 2pt;padding-right: 1pt;text-indent: 0pt;text-align: center;">30</p></td></tr><tr style="height:19pt"><td style="width:22pt;border-top-style:solid;border-top-width:1pt;border-left-style:solid;border-left-width:1pt;border-bottom-style:solid;border-bottom-width:1pt;border-right-style:solid;border-right-width:1pt"><p class="s139" style="padding-top: 2pt;padding-left: 2pt;padding-right: 1pt;text-indent: 0pt;text-align: center;">100</p></td></tr><tr style="height:19pt"><td style="width:22pt;border-top-style:solid;border-top-width:1pt;border-left-style:solid;border-left-width:1pt;border-bottom-style:solid;border-bottom-width:1pt;border-right-style:solid;border-right-width:1pt"><p class="s139" style="padding-top: 2pt;padding-left: 2pt;padding-right: 1pt;text-indent: 0pt;text-align: center;">50</p></td></tr><tr style="height:19pt"><td style="width:22pt;border-top-style:solid;border-top-width:1pt;border-left-style:solid;border-left-width:1pt;border-bottom-style:solid;border-bottom-width:1pt;border-right-style:solid;border-right-width:1pt"><p class="s139" style="padding-top: 2pt;padding-left: 2pt;padding-right: 1pt;text-indent: 0pt;text-align: center;">10</p></td></tr><tr style="height:19pt"><td style="width:22pt;border-top-style:solid;border-top-width:1pt;border-left-style:solid;border-left-width:1pt;border-bottom-style:solid;border-bottom-width:1pt;border-right-style:solid;border-right-width:1pt"><p class="s139" style="padding-top: 2pt;padding-left: 2pt;padding-right: 1pt;text-indent: 0pt;text-align: center;">70</p></td></tr><tr style="height:19pt"><td style="width:22pt;border-top-style:solid;border-top-width:1pt;border-left-style:solid;border-left-width:1pt;border-bottom-style:solid;border-bottom-width:1pt;border-right-style:solid;border-right-width:1pt"><p class="s139" style="padding-top: 2pt;padding-left: 2pt;padding-right: 1pt;text-indent: 0pt;text-align: center;">90</p></td></tr><tr style="height:19pt"><td style="width:22pt;border-top-style:solid;border-top-width:1pt;border-left-style:solid;border-left-width:1pt;border-bottom-style:solid;border-bottom-width:1pt;border-right-style:solid;border-right-width:1pt"><p class="s139" style="padding-top: 2pt;padding-left: 2pt;padding-right: 1pt;text-indent: 0pt;text-align: center;">20</p></td></tr><tr style="height:19pt"><td style="width:22pt;border-top-style:solid;border-top-width:1pt;border-left-style:solid;border-left-width:1pt;border-bottom-style:solid;border-bottom-width:1pt;border-right-style:solid;border-right-width:1pt"><p class="s139" style="padding-top: 2pt;padding-left: 2pt;padding-right: 1pt;text-indent: 0pt;text-align: center;">80</p></td></tr><tr style="height:19pt"><td style="width:22pt;border-top-style:solid;border-top-width:1pt;border-left-style:solid;border-left-width:1pt;border-bottom-style:solid;border-bottom-width:1pt;border-right-style:solid;border-right-width:1pt"><p class="s139" style="padding-top: 2pt;padding-left: 2pt;padding-right: 1pt;text-indent: 0pt;text-align: center;">40</p></td></tr></table><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Use array to implement tree structure.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: right;">30</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 62pt;text-indent: 0pt;text-align: center;">50</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 62pt;text-indent: 0pt;text-align: center;">20 80</p><p style="padding-top: 4pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">60</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 12pt;text-indent: 0pt;text-align: left;">10 70</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 12pt;text-indent: 0pt;text-align: left;">40</p><p style="padding-top: 4pt;text-indent: 0pt;text-align: right;">1</p><p style="padding-left: 3pt;text-indent: 0pt;line-height: 12pt;text-align: left;">tmp</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 6pt;text-indent: 0pt;text-align: right;">2</p><p style="padding-top: 6pt;text-indent: 0pt;text-align: right;">3</p><p style="padding-top: 6pt;text-indent: 0pt;text-align: right;">100 4</p><p style="padding-top: 6pt;text-indent: 0pt;text-align: right;">5</p><p style="padding-top: 6pt;text-indent: 0pt;text-align: right;">6</p><p style="padding-top: 6pt;text-indent: 0pt;text-align: right;">90 7</p><p style="padding-top: 6pt;text-indent: 0pt;text-align: right;">8</p><p style="padding-top: 6pt;text-indent: 0pt;text-align: right;">9</p><p style="padding-top: 6pt;text-indent: 0pt;text-align: right;">10</p><p style="padding-top: 4pt;padding-left: 12pt;text-indent: 0pt;line-height: 220%;text-align: center;">Node has index <span class="s15">i </span>Left child: <span class="s9">2</span><span class="s15">i </span>Right child: <span class="s9">2</span><span class="s15">i </span><span class="s9">+ 1 </span>Parent: <span class="s3">l </span><span class="s123">i </span><span class="s3">J</span></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">l J</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="h4">CREATE </span>The First parent is at index <span class="s84">n</span><span class="s11"> </span>. Start there and sift down during heap creation. Siblings can be reached by adding or subtracting 1. Result is a created heap.</p><h4 style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">FINISH <span class="p">Pop bottom into tmp first, then move heap root into bottom spot.</span></h4><h3 style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark97">Optimization</a><a name="bookmark104">‌</a></h3><p class="s9" style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;"><span class="p">Why is this result still worse than merge sort? </span>Θ(2<span class="s15">n </span>lg <span class="s15">n</span>) <span class="p">vs </span>Θ(<span class="s15">n </span>lg <span class="s15">n</span>)<span class="p">. We’re comparing tmp against both children and this doubles our number of comparisons. Instead let’s sift the hole left by the root down to the bottom in </span>lg <span class="s15">n </span><span class="p">comparisons (1 per level) then put tmp in the hole an sift it back up into position.</span></p><p style="padding-left: 7pt;text-indent: 0pt;text-align: justify;">How far will tmp need to go to sift back up and re-form the heap? Not far, since 1/2 the nodes are in the bottom layer, and 1/4 of the nodes are in the 2nd, etc. It takes 1 comparison to confirm tmp belongs in the bottom layer, 2 to check the 2nd layer up. . .</p><p class="s9" style="padding-top: 8pt;padding-left: 179pt;text-indent: 0pt;line-height: 8pt;text-align: left;">1 1 1 1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_143.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_144.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_145.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_146.png"/></span></p><p class="s3" style="padding-left: 62pt;text-indent: 0pt;line-height: 64%;text-align: center;"><span class="s30">2 </span>· <span class="s9">1 + </span><span class="s30">4 </span>· <span class="s9">2 + </span><span class="s30">8 </span>· <span class="s9">3 + </span><span class="s30">16 </span>· <span class="s9">4 + </span>· · · <span class="s9">= 2</span></p><p class="s15" style="padding-top: 4pt;padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="p">Giving 2n comparisons on average. We can further optimize by binary searching up. This gives Heapsort </span>n <span class="s9">lg </span>n <span class="s9">+</span></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">n <span class="s9">lg lg </span>n <span class="s9">= Θ(</span>n <span class="s9">lg </span>n<span class="s9">) </span><span class="p">performance.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark98">Pseudocode</a><a name="bookmark105">‌</a></h3><p class="s140" style="padding-top: 6pt;padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">1 </span><span class="h4">Function </span>Heap_Sort(<span class="s18">A,n</span>)<span class="h4">is</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="161" alt="image" src="cmsc351/Image_147.png"/></span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">2 <span class="s141">// Create Heap</span></p><h4 style="text-indent: 0pt;line-height: 17pt;text-align: left;"><span class="s17">3 </span>for <span class="s15">r </span><span class="s9">= </span><span class="s3">l J </span><span class="p">to 1 </span>do</h4><p style="text-indent: 0pt;text-align: left;"/><p class="s55" style="text-indent: 0pt;line-height: 7pt;text-align: center;">n</p><p style="text-indent: 0pt;text-align: left;"><span><img width="74" height="1" alt="image" src="cmsc351/Image_148.png"/></span></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: center;">2</p><p class="s141" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;"><span class="s17">4 </span><span><img width="1" height="16" alt="image" src="cmsc351/Image_149.png"/></span><span class="s33"> </span>Sift(<span class="s18">r,n,A[r]</span>)</p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">5 <span class="h4">end</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">6 <span class="s141">// Finish Sort</span></p><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">7 </span><span class="h4">for </span>m <span class="s10">= </span>n <span class="s18">To 2</span><span class="p"> </span><span class="h4">do</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="48" alt="image" src="cmsc351/Image_150.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">8 </span>s A<span class="s9">[</span>m<span class="s9">]</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">9 </span>A<span class="s9">[</span>m<span class="s9">] </span>A<span class="s9">[1]</span></p><p class="s141" style="padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">10 </span>Sift(<span class="s18">1,m-1,s</span>)</p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;text-align: left;">11 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">12 <span class="h4">end</span></p><p class="s140" style="padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">13 </span><span class="h4">Function </span>Sift(<span class="s18">r,n,s</span>)<span class="h4">is</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="323" alt="image" src="cmsc351/Image_151.png"/></span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: left;">14 <span class="s141">// r:root index, n:size index, s:sift value, p:parent index, c:child index</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">15 <span class="s15">p r</span></p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">≤</p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">16 </span><span class="h4">while </span><span class="s10">2</span>p<span class="s15"> </span>n<span class="s15"> </span><span class="h4">do</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="242" alt="image" src="cmsc351/Image_152.png"/></span></p><h4 style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">17 </span>if <span class="s10">2</span><span class="s26">p < n</span><span class="s15"> </span>then</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="80" alt="image" src="cmsc351/Image_153.png"/></span></p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">≥ </p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">18 </span><span class="h4">if </span>A<span class="s10">[2</span>p<span class="s10">]</span><span class="s9"> </span>A<span class="s10">[2</span>p <span class="s10">+ 1]</span><span class="s9"> </span><span class="h4">then</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">19 </span><span><img width="1" height="16" alt="image" src="cmsc351/Image_154.png"/></span><span class="s33"> </span>c <span class="s9">2</span>p</p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">20 <span class="h4">else</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">21 </span><span><img width="1" height="16" alt="image" src="cmsc351/Image_155.png"/></span><span class="s33"> </span>c <span class="s9">2</span>p <span class="s9">+ 1</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">22 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">23 <span class="h4">else</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">24 </span><span><img width="1" height="16" alt="image" src="cmsc351/Image_156.png"/></span><span class="s33"> </span>c <span class="s9">2</span>p</p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">25 <span class="h4">end</span></p><p class="s26" style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;"><span class="s17">26 </span><span class="h4">if </span>A<span class="s10">[</span>c<span class="s10">] </span>> s<span class="s15"> </span><span class="h4">then</span></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s17">27 </span><span><img width="1" height="32" alt="image" src="cmsc351/Image_157.png"/></span><span class="s33"> </span>A<span class="s9">[</span>p<span class="s9">] </span><span class="s3">← </span>A<span class="s9">[</span>c<span class="s9">]</span></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 10pt;text-align: left;"><span class="s17">28 </span>p <span class="s3">← </span>c</p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 10pt;text-align: left;">29 <span class="h4">else</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: left;">30 <span><img width="1" height="16" alt="image" src="cmsc351/Image_158.png"/></span><span class="s33"> </span><span class="p">Break</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">31 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;line-height: 10pt;text-align: left;">32 <span class="h4">end</span></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 16pt;text-align: left;"><span class="s17">33 </span>A<span class="s9">[</span>p<span class="s9">] </span><span class="s3">← </span>s</p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 9pt;text-align: left;">34 <span class="h4">end</span></p><h4 style="padding-left: 62pt;text-indent: 0pt;line-height: 12pt;text-align: center;">Algorithm 9: <span class="p">Heap Sort</span></h4></li></ul></li><li style="padding-top: 3pt;padding-left: 38pt;text-indent: -31pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark106">Finding Bounds to summation functions</a><a name="bookmark114">‌</a></h2></li></ol><h3 style="padding-top: 9pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark107">Mathematical Preliminaries</a><a name="bookmark115">‌</a></h3><h4 style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark108">Geometric Series</a><a name="bookmark116">‌</a></h4><p class="s3" style="padding-top: 4pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">For </span>|<span class="s15">r</span>| ≤ <span class="s9">1 </span><span class="p">recall:</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s24" style="text-indent: 0pt;line-height: 11pt;text-align: left;">∞</p><p style="text-indent: 0pt;text-align: left;"/><p class="s94" style="padding-top: 7pt;padding-left: 102pt;text-indent: 0pt;line-height: 64%;text-align: left;"> <span class="s13"> </span><span class="s142">r</span><span class="s104">i </span><span class="s25">=</span><span class="s10"> 1 </span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 102pt;text-indent: 0pt;line-height: 9pt;text-align: left;">Infinite Geometric Series</p><p class="s11" style="padding-top: 5pt;text-indent: 0pt;line-height: 9pt;text-align: right;">i<span class="s14">=0</span></p><p class="s9" style="text-indent: 0pt;line-height: 15pt;text-align: left;">1 <span class="s3">− </span><span class="s15">r</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 3pt;text-align: right;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s9" style="padding-left: 22pt;text-indent: 0pt;line-height: 15pt;text-align: left;">1 <span class="s3">− </span><span class="s15">r</span></p><p class="s11" style="padding-top: 3pt;padding-left: 44pt;text-indent: 0pt;line-height: 0pt;text-align: left;">n n</p><p class="s94" style="padding-left: 102pt;text-indent: 0pt;line-height: 85%;text-align: left;"> <span class="s13"> </span><span class="s142">r</span><span class="s104">i </span><span class="s25">= </span><span class="s10">1 </span><span class="s27">− </span><span class="s26">r</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=0</span></p><p style="padding-left: 103pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s15" style="text-indent: 0pt;line-height: 15pt;text-align: left;">r <span class="s3">− </span><span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s25" style="padding-left: 7pt;text-indent: 0pt;line-height: 85%;text-align: left;">= <span class="s26">r </span><span class="s27">−</span><span class="s3"> </span><u>1</u></p><p style="padding-top: 7pt;padding-left: 99pt;text-indent: 0pt;text-align: left;">Finite Geometric Series</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=0</span></p><p style="padding-left: 103pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">How do we solve this? Or at least get a reasonable estimate?</p><p class="s24" style="padding-top: 5pt;padding-left: 68pt;text-indent: 0pt;line-height: 4pt;text-align: left;">∞ ∞</p><p class="s15" style="padding-top: 5pt;padding-left: 65pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s22"> </span><span class="s13"> </span>i <span class="s3">· </span>ri <span class="s9">=</span><span class="s23"> </span>i <span class="s3">· </span>ri</p><p class="s11" style="text-indent: 0pt;line-height: 8pt;text-align: right;">i<span class="s14">=0</span></p><p class="s11" style="padding-left: 33pt;text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s24" style="padding-left: 47pt;text-indent: 0pt;line-height: 10pt;text-align: left;">∞</p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 16pt;text-align: center;"><span class="s9">= </span>r <span class="s3">· </span>i <span class="s3">· </span>ri<span class="s3">−</span><span class="s16">1</span></p><p class="s11" style="padding-left: 62pt;text-indent: 0pt;line-height: 6pt;text-align: center;">i<span class="s14">=1</span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 103pt;text-indent: 0pt;text-align: left;"><span class="s9">= </span>r <span class="s3">· </span><span class="s22"> </span><span class="s143">∞</span><span class="s24"> </span><span class="s121">(</span><span class="s144">r</span><span class="s13"> </span>iri<span class="s3">−</span><span class="s16">1</span><span class="s121">\</span><span class="s143"> </span><span class="s24"> </span><span class="p">sum of derivatives is the derivative of the sum</span></p><p class="s145" style="text-indent: 0pt;line-height: 11pt;text-align: left;"> <span class="s13"> ( )</span><span class="s15">i</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s24" style="padding-top: 2pt;text-indent: 0pt;line-height: 11pt;text-align: center;">∞</p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 16pt;text-align: center;"><span class="s9">= </span>r <span class="s3">· </span>r <span class="s146"> </span></p><p class="s13" style="padding-top: 5pt;text-indent: 0pt;text-align: left;"> <span class="s36"> </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 64%;text-align: left;">( \<span class="s126">−</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 62pt;text-indent: 0pt;line-height: 5pt;text-align: center;">i<span class="s14">=1</span></p><p class="s24" style="padding-top: 3pt;text-indent: 0pt;line-height: 13pt;text-align: right;">∞</p><p class="s9" style="text-indent: 0pt;line-height: 11pt;text-align: right;">= <span class="s15">r</span></p><p class="s11" style="padding-top: 2pt;text-indent: 0pt;text-align: right;">i<span class="s14">=1</span></p><p class="s147" style="padding-top: 7pt;padding-left: 5pt;text-indent: 0pt;text-align: left;">i<span class="s13"> </span><span class="s3"> </span></p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">r</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 2pt;padding-left: 103pt;text-indent: 0pt;line-height: 14pt;text-align: left;">= <span class="s15">r</span><span class="s32"> </span><u>1</u> 1 <span class="s143"> </span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 127pt;text-indent: 0pt;line-height: 16pt;text-align: left;">1 <span class="s3">− </span><span class="s15">r</span></p><p class="s25" style="padding-top: 2pt;padding-left: 103pt;text-indent: 0pt;line-height: 67%;text-align: left;">= <span class="s15">r</span><span class="s26"> </span><u>1 </u></p><p class="s9" style="padding-left: 129pt;text-indent: 0pt;line-height: 14pt;text-align: left;">(1 <span class="s3">− </span><span class="s15">r</span>)<span class="s16">2</span></p><p class="s15" style="padding-left: 129pt;text-indent: 0pt;line-height: 7pt;text-align: left;">r</p><p style="text-indent: 0pt;text-align: left;"><span><img width="46" height="1" alt="image" src="cmsc351/Image_159.png"/></span></p><p class="s9" style="padding-left: 103pt;text-indent: 0pt;text-align: left;"><span class="s148">= </span>(1 <span class="s3">− </span><span class="s15">r</span>)<span class="s16">2</span></p><p class="s15" style="padding-top: 1pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><span class="p">How can we check to confirm? We’ve already calculated the </span>r <span class="s9">= 1</span>/<span class="s9">2 </span><span class="p">case, where the infinite sum is 2.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 6pt;text-indent: 0pt;text-align: left;">Now for the finite series.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s14" style="padding-left: 23pt;text-indent: 0pt;line-height: 9pt;text-align: left;">1</p><p style="padding-left: 23pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_160.png"/></span></p><p class="s13" style="text-indent: 0pt;line-height: 64%;text-align: left;">( )<span class="s16">2</span><span class="s149">1 </span><span class="s3">−</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s58" style="text-indent: 0pt;line-height: 67%;text-align: center;"> <span class="s57">2 </span><span class="s14"> </span><span class="s71">= 2</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_161.png"/></span></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: center;">1</p><p class="s14" style="text-indent: 0pt;line-height: 9pt;text-align: center;">2</p><p class="s11" style="padding-top: 5pt;padding-left: 50pt;text-indent: 0pt;line-height: 4pt;text-align: left;">n<span class="s24">−</span><span class="s14">1 </span>n<span class="s24">−</span><span class="s14">1</span></p><p class="s15" style="padding-top: 5pt;padding-left: 50pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s22"> </span><span class="s13"> </span>i <span class="s3">· </span>ri <span class="s9">=</span><span class="s23"> </span>i <span class="s3">· </span>ri</p><p class="s11" style="text-indent: 0pt;line-height: 8pt;text-align: right;">i<span class="s14">=0</span></p><p class="s11" style="padding-left: 33pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=1</span></p><p class="s112" style="padding-top: 6pt;text-indent: 0pt;text-align: left;"> <span class="s13"> </span><span class="s11">i </span><span class="s14">1</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 44pt;text-indent: 0pt;line-height: 11pt;text-align: left;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s15" style="text-indent: 0pt;line-height: 16pt;text-align: center;"><span class="s9">= </span>r <span class="s3">· </span>i <span class="s3">· </span>r <span class="s3">−</span></p><p class="s11" style="padding-left: 45pt;text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p class="s94" style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s11">n</span><span class="s104"> </span><span class="s24">−</span><span class="s14">1 </span>(<span class="s145">r </span>\<span class="s24"> </span></p><p class="s9" style="text-indent: 0pt;line-height: 17pt;text-align: right;">= <span class="s15">r </span><span class="s3">·</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-left: 1pt;text-indent: 0pt;line-height: 9pt;text-align: left;">i<span class="s14">=1</span></p><p class="s145" style="text-indent: 0pt;line-height: 11pt;text-align: left;"> <span class="s13"> ( )</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 9pt;text-align: left;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s95" style="padding-left: 18pt;text-indent: 0pt;line-height: 57%;text-align: left;">ir<span class="s11">i</span><span class="s24">−</span><span class="s14">1</span></p><p style="padding-left: 88pt;text-indent: 0pt;line-height: 12pt;text-align: left;">sum of derivatives is the derivative of the sum</p><p class="s15" style="padding-left: 59pt;text-indent: 0pt;line-height: 18pt;text-align: center;"><span class="s9">= </span>r <span class="s3">· </span>ri <span class="s146"> </span></p><p class="s11" style="padding-left: 61pt;text-indent: 0pt;line-height: 8pt;text-align: center;">i<span class="s14">=1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="padding-top: 5pt;text-indent: 0pt;text-align: left;"> <span class="s36"> </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 2pt;padding-left: 111pt;text-indent: 0pt;line-height: 13pt;text-align: left;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s9" style="padding-left: 88pt;text-indent: 0pt;line-height: 11pt;text-align: left;">= <span class="s15">r ri</span></p><p class="s13" style="padding-top: 1pt;text-indent: 0pt;text-align: left;"> <span class="s150">( </span><span class="s151">−</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 2pt;padding-left: 112pt;text-indent: 0pt;line-height: 5pt;text-align: left;">i<span class="s14">=1</span></p><p class="s15" style="padding-top: 8pt;text-indent: 0pt;line-height: 8pt;text-align: right;">rn <span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="37" height="1" alt="image" src="cmsc351/Image_162.png"/></span></p><p class="s9" style="padding-left: 88pt;text-indent: 0pt;line-height: 67%;text-align: left;">= <span class="s15">r </span><span class="s103">r </span><span class="s3">− </span>1 <span class="s3">− </span>1</p><p class="s150" style="padding-top: 1pt;text-indent: 0pt;text-align: left;">\<span class="s152"> </span><span class="s13"> </span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="138" height="1" alt="image" src="cmsc351/Image_163.png"/></span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">= <span class="s15">r</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="padding-top: 3pt;padding-left: 62pt;text-indent: 0pt;line-height: 17pt;text-align: center;"><span class="s15">nrn</span>−<span class="s16">1</span><span class="s9">(</span><span class="s15">r </span>− <span class="s9">1) </span>− <span class="s9">(</span><span class="s15">rn </span>− <span class="s9">1)</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 17pt;text-align: center;">(<span class="s15">r </span><span class="s3">− </span>1)<span class="s16">2</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">− −</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 14pt;text-align: center;">nrn nrn<span class="s3">−</span><span class="s16">1 </span>rn <span class="s9">+ 1</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="126" height="1" alt="image" src="cmsc351/Image_164.png"/></span></p><p class="s9" style="padding-left: 88pt;text-indent: 0pt;line-height: 4pt;text-align: left;">= <span class="s15">r</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 16pt;text-align: center;">(<span class="s15">r </span><span class="s3">− </span>1)<span class="s16">2</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">− −</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 14pt;text-align: center;">(<span class="s15">n </span>1)<span class="s15">rn nrn</span><span class="s3">−</span><span class="s16">1 </span>+ 1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="129" height="1" alt="image" src="cmsc351/Image_165.png"/></span></p><p class="s9" style="padding-left: 88pt;text-indent: 0pt;line-height: 4pt;text-align: left;">= <span class="s15">r</span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 16pt;text-align: center;">(<span class="s15">r </span><span class="s3">− </span>1)<span class="s16">2</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="129" height="1" alt="image" src="cmsc351/Image_166.png"/></span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">=</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 14pt;text-align: center;"><span class="s9">(</span>n <span class="s3">− </span><span class="s9">1)</span>rn<span class="s16">+1 </span><span class="s3">− </span>nrn <span class="s9">+ </span>r</p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 17pt;text-align: center;">(<span class="s15">r </span><span class="s3">− </span>1)<span class="s16">2</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-top: 5pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark109">Gauss’s Sum</a><a name="bookmark117">‌</a></h4><p class="s26" style="padding-top: 1pt;text-indent: 0pt;text-align: left;"><span class="s94"> </span><span class="s13"> </span>n<span class="s10">(</span>n <span class="s10">+ 1)</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 2pt;text-indent: 0pt;text-align: center;">n</p><p class="s15" style="padding-top: 1pt;padding-left: 62pt;text-indent: 0pt;line-height: 10pt;text-align: center;">i <span class="s9">=</span></p><p class="s9" style="text-indent: 0pt;line-height: 6pt;text-align: center;">2</p><p class="s11" style="padding-left: 223pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=1</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">≤ ≤</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;line-height: 89%;text-align: justify;">Without knowing the answer already, we can see an easy upper bound. If every term is bound by it’s largest element it can’t be larger than <span class="s15">n</span><span class="s16">2</span>. We can also get a lower bound by flooring everything to the lowest value of 1, since there are n of them we know that the result must be larger than n. <span class="s15">n sum n</span><span class="s16">2</span>.</p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: justify;">Next we can try to split the sum in half and floor both to the lowest term in that series.</p><p class="s15" style="padding-top: 4pt;padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">n n</p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_167.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_168.png"/></span></p><p class="s9" style="padding-left: 133pt;text-indent: 0pt;line-height: 65%;text-align: left;"><span class="s15">SU M </span>= 1 + 2 + 3 + 4 + <span class="s3">· · · </span>+ <span class="s30">2 </span>+ <span class="s30">2 </span>+ 1 + <span class="s3">· · · </span>+ <span class="s15">n</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_169.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_170.png"/></span></p><p class="s15" style="padding-left: 201pt;text-indent: 0pt;line-height: 8pt;text-align: center;">n n</p><p class="s3" style="padding-left: 161pt;text-indent: 0pt;line-height: 12pt;text-align: left;">≥ <span class="s9">1 + 1 + 1 + 1 + </span>· · · <span class="s9">+ 1 +</span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s32" style="padding-top: 3pt;padding-left: 161pt;text-indent: 0pt;line-height: 47%;text-align: left;"><span class="s3">≥ </span>n<span class="s15"> </span><span class="s9">+ </span>n<span class="s15"> </span><span class="s72">(</span><span class="s13"> </span>n<span class="s15"> </span><span class="s9">+ 1</span><span class="s72">\</span></p><p class="s9" style="padding-left: 10pt;text-indent: 0pt;line-height: 58%;text-align: left;"><span class="s30">2 </span>+ 1 + <span class="s3">· · · </span>+ <span class="s30">2 </span>+ 1</p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s32" style="padding-top: 2pt;padding-left: 161pt;text-indent: 0pt;line-height: 19pt;text-align: left;"><span class="s3">≥ </span>n<span class="s97"> </span><span class="s9">1 + </span>n<span class="s15"> </span><span class="s9">+ 1</span><span class="s72"> </span></p><p class="s26" style="padding-top: 1pt;padding-left: 161pt;text-indent: 0pt;line-height: 43%;text-align: left;"><span class="s45">≥ </span>n<span class="s153"> </span>n <span class="s10">+ 4</span><span class="s9"> </span><span class="s19">7</span></p><p class="s9" style="padding-left: 173pt;text-indent: 0pt;line-height: 10pt;text-align: left;">2 2</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">≥</p><p style="text-indent: 0pt;text-align: left;"/><p class="s86" style="padding-top: 1pt;padding-left: 172pt;text-indent: 0pt;line-height: 10pt;text-align: left;">n<span class="s14">2</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="14" height="1" alt="image" src="cmsc351/Image_171.png"/></span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">+ <span class="s15">n</span></p><p class="s9" style="padding-left: 175pt;text-indent: 0pt;line-height: 9pt;text-align: left;">4</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-top: 5pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark110">Harmonic Sum</a><a name="bookmark118">‌</a></h4><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s22" style="padding-top: 2pt;text-indent: 0pt;text-align: left;"> <span class="s13"> </span><span class="s28">1</span><span class="s9"> </span><span class="s3">· · ·</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 3pt;text-indent: 0pt;text-align: center;">n</p><p class="s15" style="padding-top: 1pt;padding-left: 62pt;text-indent: 0pt;line-height: 9pt;text-align: left;">Hn <span class="s9">= = 1 + 1</span>/<span class="s9">2 + 1</span>/<span class="s9">3 + 1</span>/<span class="s9">4 + 1</span>/<span class="s9">5 + + 1</span>/n</p><p class="s15" style="text-indent: 0pt;line-height: 7pt;text-align: center;">i</p><p class="s11" style="padding-left: 17pt;text-indent: 0pt;line-height: 7pt;text-align: center;">i<span class="s14">=1</span></p><p class="s3" style="padding-left: 79pt;text-indent: 0pt;line-height: 18pt;text-align: left;">≈ <span class="s9">ln </span><span class="s15">n</span></p><p style="padding-left: 76pt;text-indent: 0pt;line-height: 11pt;text-align: left;">We can approximate it using the same</p><p style="padding-top: 2pt;padding-left: 76pt;text-indent: 0pt;text-align: left;">technique we applied to the Gaussian Sum</p><p class="s9" style="padding-left: 79pt;text-indent: 0pt;line-height: 17pt;text-align: left;"><span class="s3">≤ </span>1 + [1<span class="s15">/</span>2 + 1<span class="s15">/</span>2] + [1<span class="s15">/</span>4 + 1<span class="s15">/</span>4 + 1<span class="s15">/</span>4 + 1<span class="s15">/</span>4] + <span class="s3">· · ·</span></p><p class="s9" style="padding-left: 79pt;text-indent: 0pt;line-height: 16pt;text-align: left;">= 1 + 1 + 1 + <span class="s3">· · · </span>+ 1 <span class="p">num ones = num groups</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> <span class="s15">i</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 18pt;text-indent: 0pt;line-height: 11pt;text-align: center;">k<span class="s24">−</span><span class="s14">1</span></p><p class="s9" style="padding-left: 79pt;text-indent: 0pt;line-height: 11pt;text-align: left;">= 2 = <span class="s15">n</span></p><p class="s11" style="padding-top: 2pt;padding-left: 18pt;text-indent: 0pt;text-align: center;">i<span class="s14">=0</span></p><p style="padding-left: 76pt;text-indent: 0pt;text-align: left;">k is the number of groups. The number of</p><p style="padding-top: 3pt;padding-left: 76pt;text-indent: 0pt;text-align: left;">items per group, summed, which must sum to n</p><p class="s9" style="padding-top: 1pt;padding-left: 79pt;text-indent: 0pt;line-height: 19pt;text-align: left;">= 2<span class="s15">k </span><span class="s3">− </span>1 = <span class="s15">n</span></p><p class="s9" style="padding-left: 79pt;text-indent: 0pt;line-height: 12pt;text-align: left;">= 2<span class="s15">k </span>= <span class="s15">n </span>+ 1</p><p class="s9" style="padding-top: 2pt;padding-left: 79pt;text-indent: 0pt;text-align: left;">= <span class="s15">k </span>= lg(<span class="s15">n </span>+ 1)</p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;text-align: left;">Hn <span class="s3">≤ </span><span class="s9">lg(</span>n <span class="s9">+ 1)</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark111">Using continuous math to solve discrete math</a><a name="bookmark119">‌</a></h3><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">r</p><p style="text-indent: 0pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">r</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Assume a function that’s bounded from m to n. The Riemann sum of areas in discrete terms is bounded by the integral of some function.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">Provided </span>f <span class="s9">(</span>x<span class="s9">) </span><span class="p">is increasing.</span></p><p class="s11" style="padding-left: 11pt;text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-left: 7pt;text-indent: 0pt;text-align: left;">m<span class="s24">−</span><span class="s14">1</span></p><p class="s15" style="padding-top: 4pt;text-indent: 0pt;text-align: left;">f <span class="s9">(</span>x<span class="s9">)</span>dx <span class="s3">≤</span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="padding-left: 6pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s11" style="padding-top: 14pt;text-indent: 0pt;text-align: left;">i<span class="s154"> </span><span class="s14">=</span>m</p><p class="s15" style="padding-top: 4pt;text-indent: 0pt;text-align: left;">f <span class="s9">(</span>i<span class="s9">) </span><span class="s3">≤</span></p><p class="s11" style="padding-left: 10pt;text-indent: 0pt;line-height: 8pt;text-align: left;">n<span class="s14">+1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-left: 6pt;text-indent: 0pt;text-align: left;">m</p><p class="s15" style="padding-top: 7pt;text-indent: 0pt;text-align: left;">f <span class="s9">(</span>x<span class="s9">)</span>dx</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">r</p><p style="text-indent: 0pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">r</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">Provided </span>f <span class="s9">(</span>x<span class="s9">) </span><span class="p">is decreasing.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-left: 7pt;text-indent: 4pt;line-height: 210%;text-align: left;">n<span class="s14">+1 </span>m</p><p class="s15" style="padding-top: 14pt;text-indent: 0pt;text-align: left;">f <span class="s9">(</span>x<span class="s9">)</span>dx <span class="s3">≤</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="padding-left: 6pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s11" style="padding-top: 15pt;text-indent: 0pt;text-align: left;">i<span class="s154"> </span><span class="s14">=</span>m</p><p class="s15" style="padding-top: 14pt;text-indent: 0pt;text-align: left;">f <span class="s9">(</span>i<span class="s9">) </span><span class="s3">≤</span></p><p class="s11" style="padding-top: 8pt;padding-left: 6pt;text-indent: 4pt;line-height: 224%;text-align: left;">n m<span class="s24">−</span><span class="s14">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="text-indent: 0pt;text-align: left;">f <span class="s9">(</span>x<span class="s9">)</span>dx</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-top: 5pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark112">Gauss’s Sum</a><a name="bookmark120">‌</a></h4><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">r</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 7pt;text-indent: 4pt;line-height: 24pt;text-align: left;">n m<span class="s24">−</span><span class="s14">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-top: 12pt;text-indent: 0pt;text-align: left;">xdx <span class="s3">≤</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="padding-left: 6pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 18pt;text-indent: 0pt;line-height: 17pt;text-align: left;">i <span class="s3">≤</span></p><p class="s11" style="text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=</span>m</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-top: 4pt;padding-left: 6pt;text-indent: 4pt;line-height: 19pt;text-align: left;">n<span class="s14">+1 </span>m</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="text-indent: 0pt;text-align: left;">xdx</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">r</p><p style="text-indent: 0pt;text-align: left;"/><p class="s155" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s75" style="text-indent: 0pt;line-height: 9pt;text-align: right;"> <span class="s65"> </span><span class="s15">x</span><span class="s16">2 </span><span class="s156">n</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="14" height="1" alt="image" src="cmsc351/Image_172.png"/></span></p><p class="s25" style="text-indent: 0pt;line-height: 65%;text-align: right;">2<span class="s9"> </span><span class="s16">0 </span><span class="s3">≤ ≤</span></p><p class="s92" style="padding-bottom: 1pt;padding-left: 1pt;text-indent: 0pt;line-height: 13pt;text-align: left;">n<span class="s157">2 </span><span class="s11">n</span><span class="s14">+1 </span><span class="s58"> </span></p><p style="padding-left: 1pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="14" height="1" alt="image" src="cmsc351/Image_173.png"/></span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 4pt;text-indent: 0pt;text-align: left;">2<span class="s158"> </span><span class="s11">i</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 1pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="47" height="1" alt="image" src="cmsc351/Image_174.png"/></span></p><p class="s159" style="text-indent: 0pt;line-height: 9pt;text-align: right;"><span class="s15">n</span>2<span class="s14"> </span><span class="s9">0</span>2</p><p class="s30" style="text-indent: 0pt;line-height: 67%;text-align: right;">2 <span class="s3">− </span>2 <span class="s3">≤ ≤</span></p><p class="s9" style="padding-left: 1pt;text-indent: 0pt;line-height: 9pt;text-align: left;">(<span class="s15">n </span>+ 1)<span class="s16">2 </span>1<span class="s16">2</span></p><p class="s9" style="padding-left: 17pt;text-indent: 0pt;line-height: 17pt;text-align: left;">2 <span class="s160">− </span>2</p><p style="text-indent: 0pt;text-align: left;"><span><img width="14" height="1" alt="image" src="cmsc351/Image_175.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="68" height="1" alt="image" src="cmsc351/Image_176.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_177.png"/></span></p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 9pt;text-align: center;">n<span class="s16">2 </span>n<span class="s16">2 </span><span class="s9">+ 2</span>n <span class="s9">+ 1 1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark113">Harmonic Sum</a><a name="bookmark121">‌</a></h4><p class="s3" style="padding-left: 9pt;text-indent: 0pt;line-height: 64%;text-align: left;"><span class="s30">2 </span>− <span class="s9">0 </span>≤ ≤</p><p class="s86" style="padding-top: 1pt;padding-left: 24pt;text-indent: 0pt;line-height: 9pt;text-align: left;">n<span class="s14">2</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="14" height="1" alt="image" src="cmsc351/Image_178.png"/></span></p><p class="s30" style="padding-left: 26pt;text-indent: 0pt;line-height: 69%;text-align: left;">2 <span class="s3">≤ ≤</span></p><p class="s86" style="padding-top: 1pt;padding-left: 24pt;text-indent: 0pt;line-height: 9pt;text-align: left;">n<span class="s14">2</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="14" height="1" alt="image" src="cmsc351/Image_179.png"/></span></p><p class="s30" style="padding-left: 26pt;text-indent: 0pt;line-height: 69%;text-align: left;">2 <span class="s3">≤ ≤</span></p><p class="s9" style="padding-left: 24pt;text-indent: 0pt;line-height: 17pt;text-align: left;">2 <span class="s160">− </span>2</p><p style="text-indent: 0pt;text-align: left;"><span><img width="45" height="1" alt="image" src="cmsc351/Image_180.png"/></span></p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 107%;text-align: center;">n<span class="s16">2 </span><span class="s9">+ 2</span>n <span class="s9">2</span></p><p class="s15" style="padding-bottom: 1pt;padding-left: 62pt;text-indent: 0pt;line-height: 11pt;text-align: center;">n<span class="s9">(</span>n <span class="s9">+ 2)</span></p><p style="padding-left: 1pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="49" height="1" alt="image" src="cmsc351/Image_181.png"/></span></p><p class="s9" style="text-indent: 0pt;text-align: center;">2</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">r</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 6pt;text-indent: 0pt;line-height: 44%;text-align: right;">n<span class="s14">+1 </span><span class="s161">1</span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">m</p><p style="text-indent: 0pt;text-align: left;"/><p class="s103" style="text-indent: 0pt;line-height: 66%;text-align: right;">x <span class="s15">dx </span><span class="s3">≤</span></p><p class="s10" style="padding-top: 6pt;padding-left: 19pt;text-indent: 0pt;line-height: 7pt;text-align: left;">1</p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s103" style="padding-left: 20pt;text-indent: 0pt;line-height: 67%;text-align: left;">i <span class="s3">≤</span></p><p class="s11" style="text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=</span>m</p><p class="s11" style="padding-top: 6pt;padding-left: 10pt;text-indent: 0pt;line-height: 61%;text-align: left;">n <span class="s161">1</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">r</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 33pt;text-indent: 0pt;line-height: 7pt;text-align: left;">dx</p><p class="s11" style="padding-left: 6pt;text-indent: 0pt;text-align: left;">m<span class="s24">−</span><span class="s14">1 </span><span class="s162">x</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 15pt;text-align: left;">ln <span class="s15">x </span><span class="s3">≤ ≤ </span>ln(<span class="s15">x</span>)</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 62pt;text-indent: 0pt;line-height: 7pt;text-align: center;">n<span class="s14">+1 </span>n</p><p class="s13" style="text-indent: 0pt;line-height: 12pt;text-align: center;"> <span class="s16">1 0</span></p><p class="s9" style="padding-top: 5pt;padding-left: 180pt;text-indent: -16pt;line-height: 77%;text-align: left;">ln(<span class="s15">n </span>+ 1) <span class="s3">− </span>ln(1) <span class="s3">≤ ≤ </span>ln(<span class="s15">n</span>) <span class="s3">− </span>ln 0 ln(<span class="s15">n </span>+ 1) <span class="s3">− </span>0 <span class="s3">≤ ≤ </span>ln(<span class="s15">n</span>) <span class="s3">− </span>(<span class="s3">−∞</span>)</p><p class="s9" style="padding-left: 197pt;text-indent: 0pt;line-height: 14pt;text-align: left;">ln(<span class="s15">n </span>+ 1) <span class="s3">≤ ≤ </span>ln <span class="s15">n </span>+ <span class="s3">∞</span></p><p class="s3" style="padding-left: 278pt;text-indent: 0pt;line-height: 17pt;text-align: left;">≤ <span class="s9">+</span>∞</p><p style="padding-top: 4pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Less than infinity isn’t helpful. Let’s avoid it by removing the 1 term from the sum, so we don’t integrate 0 to 1 for ln x</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="text-indent: 0pt;text-align: right;">≤ <span class="s9">1 +</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-left: 10pt;text-indent: 0pt;text-align: left;">n</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">r</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 17pt;text-indent: 0pt;line-height: 12pt;text-align: left;">f <span class="s9">(</span>x<span class="s9">)</span>dx</p><p class="s14" style="padding-left: 5pt;text-indent: 0pt;line-height: 10pt;text-align: left;">1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="padding-top: 4pt;text-indent: 0pt;text-align: left;"> <span class="s163"> </span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 113pt;text-indent: 0pt;line-height: 6pt;text-align: center;">n</p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 80%;text-align: center;"><span class="s3">≤ </span>1 + ln(<span class="s15">x</span>) <span class="s164">1</span></p><p class="s3" style="padding-left: 201pt;text-indent: 0pt;line-height: 17pt;text-align: center;">≤ <span class="s9">1 + ln </span><span class="s15">n </span>− <span class="s9">ln 1</span></p><p class="s3" style="padding-left: 199pt;text-indent: 0pt;line-height: 15pt;text-align: center;">≤ <span class="s9">1 + ln </span><span class="s15">n </span>− <span class="s9">0</span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 17pt;text-align: center;"><span class="s3">≤ </span>ln(<span class="s15">n</span>) + 1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><ol id="l11"><li style="padding-left: 38pt;text-indent: -31pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark122">Order Notation</a><a name="bookmark123">‌</a></h2><p style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Did you know that some algorithms can be faster than others? It’s true!</p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><a href="https://en.wikipedia.org/wiki/Time_complexity" class="s4">https://en.wikipedia.org/wiki/Time_complexity</a></p><p style="text-indent: 0pt;text-align: left;"><br/></p><table style="border-collapse:collapse;margin-left:54.788pt" cellspacing="0"><tr style="height:13pt"><td style="width:134pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-left: 5pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Name</p></td><td style="width:138pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s165" style="padding-left: 40pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s139">Running time </span>T <span class="s166">(</span>n<span class="s166">)</span></p></td><td style="width:136pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-left: 13pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Examples of running times</p></td></tr><tr style="height:17pt"><td style="width:134pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-top: 1pt;padding-left: 5pt;text-indent: 0pt;text-align: left;">Constant</p></td><td style="width:138pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s165" style="padding-top: 1pt;padding-left: 40pt;text-indent: 0pt;text-align: left;">O<span class="s166">(1)</span></p></td><td style="width:136pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-top: 1pt;padding-left: 13pt;text-indent: 0pt;text-align: left;">10</p></td></tr><tr style="height:17pt"><td style="width:134pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-top: 1pt;padding-left: 5pt;text-indent: 0pt;text-align: left;">Iterated logarithmic</p></td><td style="width:138pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s165" style="padding-left: 40pt;text-indent: 0pt;line-height: 15pt;text-align: left;">O<span class="s166">(log</span><span class="s167">∗ </span>n<span class="s166">)</span></p></td><td style="width:136pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p style="text-indent: 0pt;text-align: left;"><br/></p></td></tr><tr style="height:17pt"><td style="width:134pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-top: 1pt;padding-left: 5pt;text-indent: 0pt;text-align: left;">Log-logarithmic</p></td><td style="width:138pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s165" style="padding-top: 1pt;padding-left: 40pt;text-indent: 0pt;text-align: left;">O<span class="s166">(log log </span>n<span class="s166">)</span></p></td><td style="width:136pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p style="text-indent: 0pt;text-align: left;"><br/></p></td></tr><tr style="height:17pt"><td style="width:134pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-top: 1pt;padding-left: 5pt;text-indent: 0pt;text-align: left;">Logarithmic</p></td><td style="width:138pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s165" style="padding-top: 1pt;padding-left: 40pt;text-indent: 0pt;text-align: left;">O<span class="s166">(log </span>n<span class="s166">)</span></p></td><td style="width:136pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s166" style="padding-top: 1pt;padding-left: 13pt;text-indent: 0pt;text-align: left;">log <span class="s165">n, </span>log(<span class="s165">n</span><span class="s168">2</span>)</p></td></tr><tr style="height:18pt"><td style="width:134pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-top: 2pt;padding-left: 5pt;text-indent: 0pt;text-align: left;">Polylogarithmic</p></td><td style="width:138pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s165" style="padding-top: 2pt;padding-left: 40pt;text-indent: 0pt;text-align: left;">poly<span class="s166">(log </span>n<span class="s166">)</span></p></td><td style="width:136pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s166" style="padding-top: 2pt;padding-left: 13pt;text-indent: 0pt;text-align: left;">(log <span class="s165">n</span>)<span class="s168">2</span></p></td></tr><tr style="height:17pt"><td style="width:134pt"><p class="s139" style="padding-top: 2pt;padding-left: 5pt;text-indent: 0pt;text-align: left;">Fractional power</p></td><td style="width:138pt"><p class="s166" style="padding-top: 2pt;padding-left: 40pt;text-indent: 0pt;text-align: left;"><span class="s165">O</span>(<span class="s165">nc</span>) <span class="s139">where </span>0 <span class="s165">< c < </span>1</p></td><td style="width:136pt"><p class="s170" style="padding-top: 1pt;padding-left: 13pt;text-indent: 0pt;text-align: left;"><span class="s169">n</span>1<span class="s171">/</span>2<span class="s169">, n</span>2<span class="s171">/</span>3</p></td></tr><tr style="height:17pt"><td style="width:134pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-top: 1pt;padding-left: 5pt;text-indent: 0pt;text-align: left;">Linear</p></td><td style="width:138pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s165" style="padding-top: 1pt;padding-left: 40pt;text-indent: 0pt;text-align: left;">O<span class="s166">(</span>n<span class="s166">)</span></p></td><td style="width:136pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s165" style="padding-top: 1pt;padding-left: 13pt;text-indent: 0pt;text-align: left;">n</p></td></tr><tr style="height:17pt"><td style="width:134pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-top: 1pt;padding-left: 5pt;text-indent: 0pt;text-align: left;">N log star n</p></td><td style="width:138pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s165" style="padding-left: 40pt;text-indent: 0pt;line-height: 15pt;text-align: left;">O<span class="s166">(</span>n <span class="s166">log</span><span class="s167">∗ </span>n<span class="s166">)</span></p></td><td style="width:136pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p style="text-indent: 0pt;text-align: left;"><br/></p></td></tr><tr style="height:17pt"><td style="width:134pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-top: 1pt;padding-left: 5pt;text-indent: 0pt;text-align: left;">Linearithmic</p></td><td style="width:138pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s165" style="padding-top: 1pt;padding-left: 40pt;text-indent: 0pt;text-align: left;">O<span class="s166">(</span>n <span class="s166">log </span>n<span class="s166">)</span></p></td><td style="width:136pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s165" style="padding-top: 1pt;padding-left: 13pt;text-indent: 0pt;text-align: left;">n <span class="s166">log </span>n, <span class="s166">log </span>n<span class="s166">!</span></p></td></tr></table><p class="s15" style="padding-bottom: 1pt;padding-left: 60pt;text-indent: 0pt;text-align: left;"><span class="p">Quadratic </span>O<span class="s9">(</span>n<span class="s16">2</span><span class="s9">) </span>n<span class="s16">2</span></p><p style="padding-left: 54pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="542" height="1" alt="image" src="cmsc351/Image_182.png"/></span></p><p class="s15" style="padding-bottom: 1pt;padding-left: 60pt;text-indent: 0pt;text-align: left;"><span class="p">Cubic </span>O<span class="s9">(</span>n<span class="s16">3</span><span class="s9">) </span>n<span class="s16">3</span></p><p style="padding-left: 54pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="542" height="1" alt="image" src="cmsc351/Image_183.png"/></span></p><p class="s15" style="padding-top: 1pt;padding-bottom: 1pt;padding-left: 60pt;text-indent: 0pt;text-align: left;"><span class="p">Polynomial </span><span class="s9">2</span>O<span class="s16">(log </span>n<span class="s16">) </span><span class="s9">= </span>poly<span class="s9">(</span>n<span class="s9">) </span>n, n <span class="s9">log </span>n, n<span class="s16">10</span></p><p style="padding-left: 54pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="542" height="1" alt="image" src="cmsc351/Image_184.png"/></span></p><p class="s14" style="padding-bottom: 2pt;padding-left: 60pt;text-indent: 0pt;text-align: left;"><span class="s172">Quasi-polynomial </span><span class="s9">2</span><span class="s11">poly</span>(log <span class="s11">n</span>) <span class="s86">n</span>log log <span class="s11">n</span><span class="s86">, n</span>log <span class="s11">n</span></p><p style="padding-left: 54pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="542" height="1" alt="image" src="cmsc351/Image_185.png"/></span></p><p class="s15" style="padding-top: 1pt;padding-bottom: 1pt;padding-left: 60pt;text-indent: 0pt;text-align: left;"><span class="p">Exponential (with Linear exponent) </span><span class="s9">2</span>O<span class="s16">(</span>n<span class="s16">) </span><span class="s9">1</span>.<span class="s9">1</span>n, <span class="s9">10</span>n</p><p style="padding-left: 54pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="542" height="1" alt="image" src="cmsc351/Image_186.png"/></span></p><p class="s15" style="padding-bottom: 1pt;padding-left: 60pt;text-indent: 0pt;text-align: left;"><span class="p">Exponential </span><span class="s9">2</span>poly<span class="s16">(</span>n<span class="s16">) </span><span class="s9">2</span>n, <span class="s9">2</span>n<span class="s173">2</span></p><p style="padding-left: 54pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="542" height="1" alt="image" src="cmsc351/Image_187.png"/></span></p><p class="s15" style="padding-top: 1pt;padding-bottom: 2pt;padding-left: 60pt;text-indent: 0pt;text-align: left;"><span class="p">Factorial </span>O<span class="s9">(</span>n<span class="p">!</span><span class="s9">) </span>n<span class="p">!</span></p><p style="padding-left: 54pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="542" height="1" alt="image" src="cmsc351/Image_188.png"/></span></p><p class="s62" style="padding-top: 1pt;padding-bottom: 1pt;padding-left: 60pt;text-indent: 0pt;text-align: left;"><span class="p">Double exponential </span><span class="s9">2</span><span class="s16">2</span><span class="s174">poly</span>(<span class="s64">n</span>) <span class="s9">2</span><span class="s16">2</span><span class="s174">n</span></p><p style="padding-left: 54pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="542" height="1" alt="image" src="cmsc351/Image_189.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 19pt;text-align: center;"><span class="p">Example: </span>17<span class="s15">n</span><span class="s16">3 </span>+ 24<span class="s15">n</span><span class="s16">2 </span><span class="s3">− </span>6<span class="s15">n </span>+ 8</p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 13pt;text-align: center;">=17<span class="s15">n</span><span class="s16">3 </span>+ <span class="s15">O</span>(<span class="s15">n</span><span class="s16">2</span>)</p><p class="s9" style="padding-top: 2pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">=17<span class="s15">n</span><span class="s16">3 </span>+ <span class="s15">o</span>(<span class="s15">n</span><span class="s16">3</span>)</p><p class="s14" style="padding-top: 1pt;text-indent: 0pt;line-height: 3pt;text-align: center;">3</p><p class="s3" style="padding-left: 237pt;text-indent: 0pt;line-height: 15pt;text-align: left;">≈<span class="s9">17</span><span class="s15">n</span></p><p class="s9" style="padding-left: 237pt;text-indent: 0pt;line-height: 13pt;text-align: left;">=Θ<span class="s15">n</span><span class="s16">3</span></p><p class="s15" style="padding-top: 9pt;padding-left: 6pt;text-indent: 0pt;line-height: 91%;text-align: justify;"><span class="p">Order notation can hide simple truths like a large constant in a lower order term that can seriously affect the running time for small n. Little o means the function is always less than what’s in the bounds. </span>o<span class="s9">(</span>n<span class="s16">3</span><span class="s9">) </span><span class="p">could be </span>O<span class="s9">(</span>n<span class="s16">2</span>.<span class="s16">9998</span><span class="s9">) </span><span class="p">which could throw off all of our calculations.</span></p><p class="s75" style="padding-top: 3pt;padding-left: 179pt;text-indent: 0pt;text-align: left;"> <span class="s18">Equivalence Function Order Set </span></p><p class="s9" style="padding-top: 4pt;padding-bottom: 2pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">= Θ</p><p style="padding-left: 179pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="212" height="1" alt="image" src="cmsc351/Image_190.png"/></span></p><p class="s75" style="padding-left: 179pt;text-indent: 0pt;line-height: 17pt;text-align: left;"> <span class="s27">≤ </span><span class="s26">O </span></p><p class="s75" style="padding-left: 179pt;text-indent: 0pt;line-height: 18pt;text-align: left;"> <span class="s27">≥ </span><span class="s10">Ω </span></p><p class="s15" style="padding-bottom: 2pt;padding-left: 62pt;text-indent: 0pt;line-height: 12pt;text-align: center;">< <span class="p">o</span></p><p style="padding-left: 179pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="212" height="1" alt="image" src="cmsc351/Image_191.png"/></span></p><p class="s15" style="padding-top: 1pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">> ω</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-left: 178pt;text-indent: 0pt;text-align: left;"><span class="p">Informally </span>f <span class="s9">(</span>n<span class="s9">) = Θ(</span>g<span class="s9">(</span>n<span class="s9">))</span></p><p class="s15" style="padding-top: 2pt;padding-left: 62pt;text-indent: 0pt;line-height: 9pt;text-align: center;">f <span class="s9">(</span>n<span class="s9">)</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="26" height="1" alt="image" src="cmsc351/Image_192.png"/></span></p><p class="s9" style="text-indent: 0pt;line-height: 8pt;text-align: right;">lim</p><p class="s15" style="text-indent: 0pt;line-height: 11pt;text-align: right;"><span class="s175">n</span><span class="s24">→∞ </span>g<span class="s9">(</span>n<span class="s9">)</span></p><p class="s9" style="padding-left: 1pt;text-indent: 0pt;line-height: 10pt;text-align: left;">= <span class="s15">c > </span>0</p><p class="s9" style="padding-top: 8pt;text-indent: 0pt;line-height: 8pt;text-align: right;">lim</p><p class="s9" style="padding-bottom: 2pt;padding-left: 62pt;text-indent: 0pt;line-height: 11pt;text-align: center;">7<span class="s15">n</span><span class="s16">2 </span>+ 3<span class="s15">n </span>8 7</p><p class="s176" style="padding-left: 4pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="81" height="1" alt="image" src="cmsc351/Image_193.png"/></span> <span><img width="7" height="1" alt="image" src="cmsc351/Image_194.png"/></span></p><p class="s52" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">2 <span class="s9">=</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s175" style="text-indent: 0pt;line-height: 12pt;text-align: right;">n<span class="s24">→∞ </span><span class="s9">4</span><span class="s15">n</span></p><p class="s9" style="padding-left: 4pt;text-indent: 0pt;line-height: 10pt;text-align: left;">+ 20<span class="s15">n </span>+ 4 4</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="text-indent: 0pt;line-height: 8pt;text-align: right;">lim</p><p class="s15" style="padding-top: 3pt;padding-bottom: 1pt;padding-left: 4pt;text-indent: 0pt;text-align: left;">f <span class="s9">(</span>n<span class="s9">)</span></p><p style="padding-left: 4pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="26" height="1" alt="image" src="cmsc351/Image_195.png"/></span></p><p class="s9" style="padding-top: 7pt;padding-left: 1pt;text-indent: 0pt;line-height: 11pt;text-align: left;">= <span class="s15">c </span><span class="s3">≥ </span>0 <span class="s3">−→ </span><span class="s15">f </span>(<span class="s15">n</span>) <span class="s3">∈ </span><span class="s15">O</span>(<span class="s15">g</span>(<span class="s15">n</span>))</p><p class="s15" style="text-indent: 0pt;line-height: 12pt;text-align: right;"><span class="s175">n</span><span class="s24">→∞ </span>g<span class="s9">(</span>n<span class="s9">)</span></p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: right;">g<span class="s9">(</span>n<span class="s9">)</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="26" height="1" alt="image" src="cmsc351/Image_196.png"/></span></p><p class="s9" style="text-indent: 0pt;line-height: 6pt;text-align: right;">lim</p><p class="s15" style="text-indent: 0pt;line-height: 11pt;text-align: right;"><span class="s175">n</span><span class="s24">→∞ </span>f <span class="s9">(</span>n<span class="s9">)</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 1pt;text-indent: 0pt;text-align: left;">= <span class="s15">c </span><span class="s3">≥ </span>0 <span class="s3">−→ </span><span class="s15">f </span>(<span class="s15">n</span>) <span class="s3">∈ </span>Ω(<span class="s15">g</span>(<span class="s15">n</span>))</p><p class="s9" style="padding-top: 7pt;text-indent: 0pt;line-height: 8pt;text-align: right;">lim</p><p class="s15" style="padding-bottom: 1pt;padding-left: 4pt;text-indent: 0pt;text-align: left;">f <span class="s9">(</span>n<span class="s9">)</span></p><p style="padding-left: 4pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="26" height="1" alt="image" src="cmsc351/Image_197.png"/></span></p><p class="s9" style="padding-top: 4pt;padding-left: 1pt;text-indent: 0pt;line-height: 11pt;text-align: left;">= 0 <span class="s3">−→ </span><span class="s15">f </span>(<span class="s15">n</span>) <span class="s3">∈ </span><span class="s15">o</span>(<span class="s15">g</span>(<span class="s15">n</span>))</p><p class="s15" style="text-indent: 0pt;line-height: 12pt;text-align: right;"><span class="s175">n</span><span class="s24">→∞ </span>g<span class="s9">(</span>n<span class="s9">)</span></p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: right;">g<span class="s9">(</span>n<span class="s9">)</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="26" height="1" alt="image" src="cmsc351/Image_198.png"/></span></p><p class="s9" style="text-indent: 0pt;line-height: 6pt;text-align: right;">lim</p><p class="s15" style="text-indent: 0pt;line-height: 11pt;text-align: right;"><span class="s175">n</span><span class="s24">→∞ </span>f <span class="s9">(</span>n<span class="s9">)</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 1pt;text-indent: 0pt;text-align: left;">= 0 <span class="s3">−→ </span><span class="s15">f </span>(<span class="s15">n</span>) <span class="s3">∈ </span><span class="s15">ω</span>(<span class="s15">g</span>(<span class="s15">n</span>))</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">·</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 88%;text-align: left;"><span class="p">What about non-polynomial functions? Like </span>f <span class="s9">(</span>n<span class="s9">) = </span>n<span class="s16">2 </span><span class="s9">(10 + sin(</span>n<span class="s9">)) </span><span class="p">The book has a non-limiting approach which gives us a nice way of addressing oscillating functions.</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">·</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 6pt;text-indent: 0pt;line-height: 85%;text-align: left;"><span class="p">To a first approximation you can do plain algebra using Theta notation. </span><span class="s9">2</span><span class="s16">Θ</span>n<span class="s173">2</span><span class="s62"> </span><span class="s9">2</span><span class="s16">Θ</span>n<span class="s173">3</span><span class="s62"> </span><span class="s9">= 2</span><span class="s16">Θ</span>n<span class="s173">2</span><span class="s159">+Θ</span><span class="s11">n</span><span class="s173">3</span><span class="s62"> </span><span class="p">. What’s faster? </span>n<span class="s16">lg </span>n<span class="p">or</span><span class="s9">(lg </span>n<span class="s9">)</span>n</p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">Exponentials grow much faster than polynomials. How do we state that formally?</p><p class="s15" style="padding-top: 6pt;padding-left: 201pt;text-indent: 0pt;line-height: 126%;text-align: center;">na <span class="s9">= </span>o<span class="s9">(</span>bn<span class="s9">) </span><span class="p">for </span>a <span class="s3">≥ </span><span class="s9">0</span>, b > <span class="s9">1 (log </span>n<span class="s9">)</span>a <span class="s9">= </span>o<span class="s9">(</span>nb<span class="s9">) </span>b > <span class="s9">0</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">(log log <span class="s15">n</span>)<span class="s15">a </span>= <span class="s15">o</span>((log <span class="s15">n</span>)<span class="s15">b</span>)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">n<span class="s16">lg </span>n <span class="s9">? (lg </span>n<span class="s9">)</span>n</p><p class="s86" style="padding-top: 1pt;padding-left: 62pt;text-indent: 0pt;line-height: 10pt;text-align: center;">n<span class="s14">lg </span><span class="s11">n</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="38" height="1" alt="image" src="cmsc351/Image_199.png"/></span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">lim <span class="s15">n</span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 11pt;text-align: center;"><span class="s175">n</span><span class="s24">→∞ </span>(lg <span class="s15">n</span>)</p><p class="s9" style="padding-top: 8pt;text-indent: 0pt;line-height: 8pt;text-align: right;">= lim</p><p class="s14" style="padding-bottom: 2pt;padding-left: 6pt;text-indent: 0pt;line-height: 82%;text-align: left;"><span class="s70">2</span>lg <span class="s11">n</span><span class="s24">·</span>lg <span class="s11">n</span></p><p style="padding-left: 4pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="49" height="1" alt="image" src="cmsc351/Image_200.png"/></span></p><p class="s14" style="padding-left: 9pt;text-indent: 0pt;line-height: 1pt;text-align: left;">lg (lg <span class="s11">n</span>)<span class="s11">n</span></p><p class="s11" style="text-indent: 0pt;line-height: 12pt;text-align: right;">n<span class="s24">→∞ </span><span class="s177">2</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s70" style="text-indent: 0pt;line-height: 47%;text-align: left;">2<span class="s14">lg2 </span><span class="s11">n</span></p><p class="s9" style="text-indent: 0pt;line-height: 7pt;text-align: right;">= lim</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 4pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="49" height="1" alt="image" src="cmsc351/Image_201.png"/></span></p><p class="s11" style="padding-left: 9pt;text-indent: 0pt;line-height: 1pt;text-align: left;">n <span class="s14">lg(lg </span>n<span class="s14">)</span></p><p class="s11" style="padding-left: 62pt;text-indent: 0pt;line-height: 11pt;text-align: center;">n<span class="s24">→∞ </span><span class="s177">2</span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 11pt;text-align: center;">= 0</p><p class="s15" style="padding-top: 2pt;padding-left: 62pt;text-indent: 0pt;text-align: center;"><span class="s178">∴ </span>n<span class="s16">lg </span>n <span class="s9">= </span>o<span class="s9">((lg </span>n<span class="s9">)</span>n<span class="s9">)</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">Polylogs grow slower than polynomials, and Quasi-polynomials grow slower than exponentials with variable bases.</p></li><li style="padding-top: 3pt;padding-left: 38pt;text-indent: -31pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark124">Quicksort</a><a name="bookmark138">‌</a></h2></li></ol><p style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">An efficient sorting algorithm developed by Tony Hoare in 1959 while trying to translate Russian. Recursively partition the array, put small numbers to the left and large numbers to the right.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s140" style="padding-left: 12pt;text-indent: 0pt;text-align: left;"><span class="s17">1 </span><span class="h4">Function </span>QUICKSORT(<span class="s18">A,p,r</span>)<span class="h4">is</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="81" alt="image" src="cmsc351/Image_202.png"/></span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">2 </span>if <span class="s26">p < r</span><span class="s15"> </span>then</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="48" alt="image" src="cmsc351/Image_203.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s141" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">3 </span><span class="s15">q </span>PARTITION(<span class="s18">A,p,r</span>)</p><p class="s141" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">4 </span>QUICKSORT(<span class="s18">A,p,q-1</span>)</p><p class="s141" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">5 </span>QUICKSORT(<span class="s18">A,q+1,r</span>)</p><p class="s17" style="padding-top: 1pt;padding-left: 12pt;text-indent: 0pt;text-align: left;">6 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">7 <span class="h4">end</span></p><p class="s140" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">8 </span><span class="h4">Function </span>PARTITION(<span class="s18">A,p,r</span>)<span class="h4">is</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="178" alt="image" src="cmsc351/Image_204.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">9 </span>x A<span class="s9">[</span>r<span class="s9">]</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">← −</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">10 <span class="s15">i p </span><span class="s9">1</span></p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;"><span class="s17">11 </span><span class="h4">for </span>j <span class="s10">= </span>p <span class="s18">to </span>r<span class="s15"> </span><span class="s10">1</span><span class="s9"> </span><span class="h4">do</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="65" alt="image" src="cmsc351/Image_205.png"/></span></p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">≤</p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;"><span class="s17">12 </span><span class="h4">if </span>A<span class="s10">[</span>j<span class="s10">]</span><span class="s9"> </span>x<span class="s15"> </span><span class="h4">then</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="32" alt="image" src="cmsc351/Image_206.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">13 <span class="s15">i i </span><span class="s9">+ 1</span></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;"><span class="s17">14 </span><span class="p">Exchange</span>A<span class="s9">[</span>i<span class="s9">]</span>, A<span class="s9">[</span>j<span class="s9">]</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;text-align: justify;">15 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">16 <span class="h4">end</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">17 <span class="s15">i i </span><span class="s9">+ 1</span></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;"><span class="s17">18 </span><span class="p">Exchange</span>A<span class="s9">[</span>i<span class="s9">]</span>, A<span class="s9">[</span>r<span class="s9">]</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">19 <span class="h4">return </span><span class="p">i</span></p><p style="padding-left: 72pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="4" height="1" alt="image" src="cmsc351/Image_207.png"/></span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;text-align: justify;">20 <span class="h4">end</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 6pt;text-indent: 0pt;text-align: justify;"><a name="bookmark125">Comparison Analysis</a><a name="bookmark139">‌</a></h3><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">− −</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">First note that <span class="s141">PARTITION </span>is always linear in comparisons on <span class="s15">n </span><span class="s9">= </span><span class="s15">r p </span><span class="s9">+1 </span>terms. The FOR loop runs <span class="s15">n </span><span class="s9">1 </span>comparisons regardless of the result of the IF condition.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark126">Quicksort Worst case comparisons</a><a name="bookmark140">‌</a></h4><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">The worst case output for <span class="s141">PARTITION </span>must occur when the pivot doesn’t move, and the recursive call to <span class="s141">QUICKSORT </span>is only 1 smaller than the previous call. Thus, partitioning on n elements gets n-1 comparisons. Worst Case Comparisons Occurs when pivot is at far end of array:</p><p class="s15" style="padding-top: 7pt;padding-left: 85pt;text-indent: 0pt;line-height: 17pt;text-align: left;">T <span class="s9">(</span>n<span class="s9">) = </span>T <span class="s9">(</span>n <span class="s3">− </span><span class="s9">1) + </span>n <span class="s3">− </span><span class="s9">1 </span>, T <span class="s9">(1) = 0</span></p><p class="s9" style="padding-left: 109pt;text-indent: 0pt;line-height: 16pt;text-align: left;">= (<span class="s15">n </span><span class="s3">− </span>1) + (<span class="s15">n </span><span class="s3">− </span>2) + (<span class="s15">n </span><span class="s3">− </span>3) + <span class="s3">· · · </span>+ 3 + 2 + 1 <span class="p">pivot = 2</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 62pt;text-indent: 0pt;line-height: 11pt;text-align: center;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s9" style="padding-left: 109pt;text-indent: 0pt;line-height: 11pt;text-align: left;">= <span class="s15">i</span></p><p class="s11" style="padding-top: 2pt;padding-left: 62pt;text-indent: 0pt;line-height: 9pt;text-align: center;">i<span class="s14">=1</span></p><p class="s10" style="padding-top: 1pt;padding-left: 109pt;text-indent: 0pt;line-height: 77%;text-align: left;"><span class="s25">= </span>(<span class="s26">n </span><span class="s27">− </span>1) <span class="s27">·</span><span class="s3"> </span><span class="s26">n</span></p><p class="s9" style="padding-left: 140pt;text-indent: 0pt;line-height: 9pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark127">Quicksort Best case comparisons</a><a name="bookmark141">‌</a></h4><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;line-height: 11pt;text-align: justify;">The best case occurs when <span class="s141">PARTITION </span>moves the pivot to the middle of the array, so that the recursive calls to</p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: justify;"><span class="s141">QUICKSORT </span>are <span class="s84">n</span><span class="s56">−</span><span class="s57">1</span><span class="s14"> </span>smaller than the last call. Best Case Comparisons Occurs when pivot is right in the middle of</p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">array:</p><p class="s9" style="padding-top: 17pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="s15">T </span>(<span class="s15">n</span>) = 2 <span class="s3">· </span><span class="s15">T </span>( <span class="s32">n </span><span class="s27">−</span><span class="s3"> </span><u>1</u> ) + <span class="s15">n </span><span class="s3">− </span>1 <span class="s15">, T </span>(1) = 0</p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="text-indent: 0pt;line-height: 6pt;text-align: center;">n</p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_208.png"/></span></p><p class="s9" style="padding-left: 47pt;text-indent: 0pt;line-height: 68%;text-align: center;"><span class="s3">≤ </span>2 <span class="s3">· </span><span class="s15">T </span>( <span class="s30">2 </span>) + <span class="s15">n </span><span class="s3">− </span>1</p><p class="s9" style="padding-left: 47pt;text-indent: 0pt;text-align: center;">= <span class="s15">n </span><span class="s3">· </span>lg(<span class="s15">n</span>) <span class="s3">− </span><span class="s15">n </span>+ 1</p><p class="s9" style="padding-left: 191pt;text-indent: 0pt;text-align: left;">= <span class="s15">O</span>(<span class="s15">n </span><span class="s3">· </span>lg <span class="s15">n</span>)</p><h3 style="padding-top: 9pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark128">Proof by Constructive Induction</a><a name="bookmark142">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Mathematical Induction is great at proving an answer is true if you already know it. But if you don’t know that what the answer is for sure, you can make an educated guess, and use induction to derive the right answer. We know the answer to the worst case comparisons of quicksort is quadratic, but we don’t know the coefficients.</p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 17pt;text-align: justify;"><span class="p">For example, let’s prove </span>1 + 2 + 3 + <span class="s3">· · · </span>+ <span class="s15">n </span><span class="p">is quadratic.</span></p><p class="s11" style="padding-top: 2pt;padding-left: 27pt;text-indent: 0pt;line-height: 2pt;text-align: center;">n n</p><p class="s15" style="padding-top: 7pt;padding-bottom: 2pt;text-indent: 0pt;text-align: center;"><span class="s22"> </span><span class="s13"> </span>i <span class="p">Guess </span><span class="s179"> </span>i <span class="s9">= </span>an<span class="s16">2 </span><span class="s9">+ </span>bn <span class="s9">+ </span>c</p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 190pt;text-indent: 0pt;line-height: 7pt;text-align: left;"><span style=" color: black; font-family:"Bookman Old Style", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 6.5pt;"> </span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 190pt;text-indent: 0pt;line-height: 7pt;text-align: left;"><span style=" color: black; font-family:"Bookman Old Style", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 6.5pt;"> </span></p><p class="s9" style="padding-top: 2pt;padding-left: 7pt;text-indent: 0pt;line-height: 15pt;text-align: left;"><span class="p">Base case </span><span class="s15">i </span>= 1<span class="p">. </span><span class="s19">),</span><span class="s67">1 </span><span class="s15">i </span>= <span class="s15">a</span>(1)<span class="s16">2 </span>+ <span class="s15">b</span>(1) + <span class="s15">c </span>= <span class="s15">a </span>+ <span class="s15">b </span>+ <span class="s15">c </span>= 1</p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 91pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 116pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s9" style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">Inductive Hypothesis: </span><span class="s19">),</span><span class="s20">n</span><span class="s24">−</span><span class="s14">1 </span><span class="s15">i </span>= <span class="s15">a</span>(<span class="s15">n </span><span class="s3">− </span>1)<span class="s16">2 </span>+ <span class="s15">b</span>(<span class="s15">n </span><span class="s3">− </span>1) + <span class="s15">c</span></p><p class="s11" style="padding-top: 1pt;padding-left: 174pt;text-indent: 0pt;line-height: 4pt;text-align: left;">n n<span class="s24">−</span><span class="s14">1</span></p><p class="s15" style="padding-top: 7pt;padding-left: 169pt;text-indent: 0pt;text-align: left;"><span class="s22"> </span><span class="s13"> </span>i <span class="s9">= </span>n <span class="s9">+</span><span class="s23"> </span>i</p><p class="s11" style="padding-top: 2pt;text-indent: 0pt;text-align: right;">i<span class="s14">=1</span></p><p class="s11" style="padding-top: 2pt;padding-left: 36pt;text-indent: 0pt;line-height: 10pt;text-align: left;">i<span class="s14">=1</span></p><p class="s9" style="padding-left: 6pt;text-indent: 0pt;line-height: 18pt;text-align: left;">= <span class="s15">n </span>+ <span class="s15">a</span>(<span class="s15">n </span><span class="s3">− </span>1)<span class="s16">2 </span>+ <span class="s15">b</span>(<span class="s15">n </span><span class="s3">− </span>1) + <span class="s15">c</span></p><p class="s9" style="padding-left: 6pt;text-indent: 0pt;line-height: 16pt;text-align: left;">= <span class="s15">n </span>+ <span class="s15">a</span>(<span class="s15">n</span><span class="s16">2 </span><span class="s3">− </span>2<span class="s15">n </span>+ 1) + <span class="s15">b</span>(<span class="s15">n </span><span class="s3">− </span>1) + <span class="s15">c</span></p><p class="s9" style="padding-left: 6pt;text-indent: 0pt;line-height: 18pt;text-align: left;">= <span class="s15">an</span><span class="s16">2 </span>+ (<span class="s3">−</span>2<span class="s15">a </span>+ <span class="s15">b </span>+ 1)<span class="s15">n </span>+ <span class="s15">a </span><span class="s3">− </span><span class="s15">b </span>+ <span class="s15">c</span></p><p style="padding-top: 4pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">If our assumption was true then we should get a system of simultaneous equations matching the quadratic. Then we could solve the system for the coefficients of the result.</p><p class="s15" style="padding-top: 9pt;padding-left: 183pt;text-indent: 0pt;text-align: left;">a <span class="s9">= </span>a</p><p class="s9" style="padding-left: 21pt;text-indent: 0pt;line-height: 17pt;text-align: center;"><span class="s15">b </span>= <span class="s3">−</span>2<span class="s15">a </span>+ <span class="s15">b </span>+ 1</p><p class="s15" style="padding-left: 8pt;text-indent: 0pt;line-height: 16pt;text-align: center;">c <span class="s9">= </span>a <span class="s3">− </span>b <span class="s9">+ </span>c</p><p class="s9" style="text-indent: 0pt;line-height: 7pt;text-align: center;">1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_209.png"/></span></p><p class="s15" style="padding-top: 1pt;padding-left: 208pt;text-indent: -19pt;line-height: 61%;text-align: left;">a <span class="s9">= </span>, a <span class="s9">= </span>b, c <span class="s9">= 0 2</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 174pt;text-indent: 0pt;line-height: 5pt;text-align: left;">n</p><p class="s9" style="padding-top: 3pt;padding-left: 203pt;text-indent: -17pt;line-height: 54%;text-align: left;"><span class="s15">i </span>= <u>1</u> <span class="s15">n</span><span class="s16">2 </span>+ <u>1</u> <span class="s15">n </span>= 2 2</p><p class="s26" style="padding-left: 62pt;text-indent: 0pt;line-height: 10pt;text-align: center;">n<span class="s10">(</span>n <span class="s10">+ 1)</span></p><p class="s9" style="padding-top: 2pt;text-indent: 0pt;line-height: 8pt;text-align: center;">2</p><p class="s11" style="padding-left: 62pt;text-indent: 0pt;line-height: 6pt;text-align: center;">i<span class="s14">=1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark129">Quicksort Worst Case from Recurrence</a><a name="bookmark143">‌</a></h4><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 4pt;padding-left: 7pt;text-indent: 0pt;line-height: 17pt;text-align: left;">T <span class="s9">(</span>n<span class="s9">) = </span>T <span class="s9">(</span>n <span class="s3">− </span><span class="s9">1) + </span>n <span class="s3">− </span><span class="s9">1</span>, T <span class="s9">(1) = 0</span><span class="p">. Let’s guess that the result is quadratic: </span>an<span class="s16">2 </span><span class="s9">+ </span>bn <span class="s9">+ </span>c</p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 10pt;text-align: left;"><span class="p">Base: </span>n <span class="s9">= 1</span>, a<span class="s9">(1) + </span>b<span class="s9">(1) + </span>c <span class="s9">= 0</span></p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 19pt;text-align: left;"><span class="p">Inductive Hypothesis: Assume </span><span class="s15">T </span>(<span class="s15">n </span><span class="s3">− </span>1) = <span class="s15">a</span>(<span class="s15">n </span><span class="s3">− </span>1)<span class="s16">2 </span>+ <span class="s15">b</span>(<span class="s15">n </span><span class="s3">− </span>1) + <span class="s15">c</span></p><p class="s15" style="padding-top: 2pt;padding-left: 45pt;text-indent: 0pt;line-height: 18pt;text-align: center;">T <span class="s9">(</span>n<span class="s9">) = </span>T <span class="s9">(</span>n <span class="s3">− </span><span class="s9">1) + </span>n <span class="s3">− </span><span class="s9">1</span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 17pt;text-align: center;">= <span class="s15">a</span>(<span class="s15">n </span><span class="s3">− </span>1)<span class="s16">2 </span>+ <span class="s15">b</span>(<span class="s15">n </span><span class="s3">− </span>1) + <span class="s15">c </span>+ <span class="s15">n </span><span class="s3">− </span>1</p><p class="s9" style="padding-left: 201pt;text-indent: 0pt;line-height: 16pt;text-align: left;">= <span class="s15">a</span>(<span class="s15">n</span><span class="s16">2 </span><span class="s3">− </span>2<span class="s15">n </span>+ 1) + <span class="s15">b</span>(<span class="s15">n </span><span class="s3">− </span>1) + <span class="s15">c </span>+ <span class="s15">n </span><span class="s3">− </span>1</p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 17pt;text-align: center;">= <span class="s15">an</span><span class="s16">2</span>(<span class="s3">−</span>2<span class="s15">a </span>+ <span class="s15">b </span>+ 1)<span class="s15">n </span>+ <span class="s15">c </span><span class="s3">− </span><span class="s15">b </span><span class="s3">− </span>1 + <span class="s15">a</span></p><p style="padding-left: 50pt;text-indent: 0pt;line-height: 11pt;text-align: center;">Find coefficients</p><p class="s15" style="padding-top: 2pt;padding-left: 160pt;text-indent: 0pt;text-align: left;">a <span class="s9">+ </span>b <span class="s9">+ </span>c <span class="s9">= 0</span></p><p class="s15" style="padding-top: 2pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">a <span class="s9">= </span>a</p><p class="s15" style="padding-top: 3pt;padding-left: 143pt;text-indent: 3pt;line-height: 77%;text-align: center;"><span class="s3">−</span><span class="s9">2</span>a <span class="s9">+ </span>b <span class="s9">+ 1 = </span>b c <span class="s3">− </span><span class="s9">1 + </span>a <span class="s3">− </span>b <span class="s9">= </span>c</p><p class="s9" style="text-indent: 0pt;line-height: 8pt;text-align: center;">1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_210.png"/></span></p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 7pt;text-align: center;">a <span class="s9">=</span></p><p class="s9" style="text-indent: 0pt;line-height: 9pt;text-align: center;">2</p><p class="s9" style="text-indent: 0pt;line-height: 7pt;text-align: center;">1</p><p class="s15" style="padding-left: 11pt;text-indent: 0pt;line-height: 64%;text-align: center;">b <span class="s9">= </span><span class="s3">− </span><span class="s30">2</span></p><p class="s15" style="padding-top: 2pt;padding-left: 2pt;text-indent: 0pt;text-align: center;">c <span class="s9">= 0</span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 3pt;padding-left: 177pt;text-indent: 0pt;text-align: left;"><span class="s15">T </span>(<span class="s15">n</span>) = <u>1</u> <span class="s15">n</span><span class="s16">2 </span><span class="s3">− </span><u>1</u> <span class="s15">n</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark130">Quicksort Best Case from Recurrence</a><a name="bookmark144">‌</a></h4><p class="s26" style="padding-top: 1pt;padding-left: 2pt;text-indent: 0pt;line-height: 77%;text-align: left;"><span class="s25">= </span>n<span class="s10">(</span>n <span class="s27">− </span><span class="s10">1)</span></p><p class="s9" style="padding-left: 30pt;text-indent: 0pt;line-height: 9pt;text-align: left;">2</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">T <span class="s9">(</span>n<span class="s9">) = 2</span>T <span class="s9">(</span>n/<span class="s9">2) + </span>n <span class="s9">1</span>, T <span class="s9">(1) = 0</span><span class="p">. Guess upper bound: </span>T <span class="s9">(</span>n<span class="s9">) = </span>an <span class="s9">lg </span>n</p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="p">Base: </span>n <span class="s9">= 1</span>, a<span class="s9">(1) lg(1) = 0</span></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="p">Inductive Hypothesis: By strong induction, assume </span>T <span class="s9">(</span>k<span class="s9">) = </span>ak <span class="s9">lg </span>k <span class="p">for all </span>k < n</p><p class="s15" style="padding-top: 7pt;padding-left: 62pt;text-indent: 0pt;line-height: 12pt;text-align: center;">T <span class="s9">(</span>n<span class="s9">) = 2</span>T <span class="s9">(</span>n/<span class="s9">2) + </span>n <span class="s3">− </span><span class="s9">1</span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="padding-top: 2pt;padding-left: 62pt;text-indent: 0pt;line-height: 19pt;text-align: center;">≤ <span class="s9">2 </span><span class="s99"> </span><span class="s15">a </span>· <span class="s32">n</span><span class="s15"> </span>· <span class="s9">lg </span><span class="s32">n</span><span class="s97"> </span><span class="s9">+ </span><span class="s15">n </span>− <span class="s9">1</span></p><p class="s9" style="padding-left: 2pt;text-indent: 0pt;line-height: 7pt;text-align: center;">2</p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 15pt;text-align: center;">= <span class="s15">an</span>[lg <span class="s15">n </span><span class="s3">− </span>lg 2] + <span class="s15">n </span><span class="s3">− </span>1</p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 15pt;text-align: center;">= <span class="s15">an</span>[lg <span class="s15">n </span><span class="s3">− </span>1] + <span class="s15">n </span><span class="s3">− </span>1</p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 15pt;text-align: center;"><span class="s9">= </span>an <span class="s9">lg </span>n <span class="s3">− </span>an <span class="s9">+ </span>n <span class="s3">− </span><span class="s9">1</span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 15pt;text-align: center;">= <span class="s15">an </span>lg <span class="s15">n </span>+ (<span class="s3">−</span><span class="s15">a </span>+ 1)<span class="s15">n </span><span class="s3">− </span>1</p><p class="s15" style="padding-left: 149pt;text-indent: 0pt;line-height: 16pt;text-align: left;"><span class="p">To be true, must be </span><span class="s3">≤ </span>an <span class="s9">lg </span>n</p><p style="padding-left: 62pt;text-indent: 0pt;line-height: 11pt;text-align: center;">drop -1 because <</p><p class="s3" style="padding-left: 62pt;text-indent: 0pt;text-align: center;"><span class="s9">(</span>−<span class="s15">a </span><span class="s9">+ 1)</span><span class="p">must be </span>≤ <span class="s9">0</span><span class="s15">, </span>→ <span class="s15">a </span>≥ <span class="s9">1</span></p><p style="padding-top: 4pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">So a constant a greater than or equal to 1 solves the recurrence, but the best case value occurs when a is 1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 18pt;text-align: center;"><span class="s15">T </span>(<span class="s15">n</span>) <span class="s3">≤ </span>1 <span class="s3">· </span><span class="s15">n </span>lg <span class="s15">n</span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 11pt;text-align: center;">= <span class="s15">n </span>lg <span class="s15">n</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark131">Average case analysis of quicksort from approximate recurrence.</a><a name="bookmark145">‌</a></h4><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Best case occurs when pivot is in the middle, while worst case occurs when pivot is at the end. Let’s approximate the average case happening when the pivot is at the one and three quarter marks.</p><p class="s9" style="padding-top: 7pt;padding-left: 55pt;text-indent: 0pt;line-height: 8pt;text-align: center;">3<span class="s15">n n</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="15" height="1" alt="image" src="cmsc351/Image_211.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_212.png"/></span></p><p class="s9" style="padding-left: 166pt;text-indent: 0pt;line-height: 64%;text-align: left;"><span class="s15">T </span>(<span class="s15">n</span>) = <span class="s15">T </span>( <span class="s30">4 </span>) + <span class="s15">T </span>( <span class="s30">4 </span>) + <span class="s15">n </span><span class="s3">− </span>1 <span class="s15">, T </span>(1) = 0</p><p class="s15" style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;line-height: 16pt;text-align: left;"><span class="p">Let’s guess optimistically that our upper bound is </span>T <span class="s9">(</span>n<span class="s9">) </span><span class="s3">≤ </span>an <span class="s9">lg </span>n</p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="p">Base case n=1: </span><span class="s15">a</span>(1) lg(1) = 0 <span class="s3">≤ </span>0<span class="s178">v'</span></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 16pt;text-align: left;"><span class="p">Inductive Hypothesis: By strong induction, assume true for </span>k < n T <span class="s9">(</span>k<span class="s9">) </span><span class="s3">≤ </span>ak <span class="s9">lg </span>k</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-top: 3pt;padding-left: 48pt;text-indent: 0pt;line-height: 8pt;text-align: center;">3<span class="s15">n n</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="15" height="1" alt="image" src="cmsc351/Image_213.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_214.png"/></span></p><p class="s9" style="padding-left: 163pt;text-indent: 0pt;line-height: 59%;text-align: left;"><span class="s15">T </span>(<span class="s15">n</span>) = <span class="s15">T </span>( <span class="s30">4 </span>) + <span class="s15">T </span>( <span class="s30">4 </span>) + <span class="s15">n </span><span class="s3">− </span>1</p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 19pt;text-align: center;"><span class="s3">≤ </span>a <u>n</u> <span class="s9">lg </span><span class="s72">(</span><span class="s13"> </span><u>n</u> <span class="s72">\</span><span class="s13"> </span><span class="s9">+ </span>a <span class="s28">3</span><u>n</u> <span class="s9">lg </span><span class="s121">(</span><span class="s13"> </span><span class="s28">3</span><u>n</u> <span class="s121">\</span><span class="s13"> </span><span class="s9">+ </span>n <span class="s3">− </span><span class="s9">1</span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 10pt;text-align: center;">4 4 4 4</p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">n <span class="s9">3</span>an</p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_215.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="22" height="1" alt="image" src="cmsc351/Image_216.png"/></span></p><p class="s9" style="padding-left: 186pt;text-indent: 0pt;line-height: 65%;text-align: left;">= <span class="s15">a </span><span class="s30">4 </span>(lg <span class="s15">n </span><span class="s3">− </span>lg 4) + <span class="s30">4 </span>(lg <span class="s15">n </span><span class="s3">− </span>lg 4 + lg 3) + <span class="s15">n </span><span class="s3">− </span>1</p><p class="s15" style="text-indent: 0pt;line-height: 8pt;text-align: right;">n an</p><p style="text-indent: 0pt;text-align: left;"><span><img width="15" height="1" alt="image" src="cmsc351/Image_217.png"/></span></p><p class="s9" style="padding-top: 2pt;text-indent: 0pt;line-height: 36%;text-align: right;">= <span class="s15">a </span><span class="s30">4 </span>lg <span class="s15">n </span><span class="s3">− </span><span class="s30">2 </span>+</p><p class="s9" style="padding-left: 1pt;text-indent: 0pt;line-height: 8pt;text-align: left;">3<span class="s15">an</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="22" height="1" alt="image" src="cmsc351/Image_218.png"/></span></p><p class="s30" style="padding-top: 2pt;padding-left: 7pt;text-indent: 0pt;line-height: 36%;text-align: left;">4 <span class="s9">lg </span><span class="s15">n </span><span class="s3">−</span></p><p class="s9" style="padding-left: 1pt;text-indent: 0pt;line-height: 8pt;text-align: left;">3<span class="s15">an</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="22" height="1" alt="image" src="cmsc351/Image_219.png"/></span></p><p class="s30" style="padding-top: 2pt;padding-left: 7pt;text-indent: 0pt;line-height: 36%;text-align: left;">2 <span class="s9">+ lg 3 </span><span class="s3">·</span></p><p class="s9" style="padding-left: 1pt;text-indent: 0pt;line-height: 8pt;text-align: left;">3<span class="s15">an</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="22" height="1" alt="image" src="cmsc351/Image_220.png"/></span></p><p class="s9" style="padding-top: 2pt;padding-left: 7pt;text-indent: 0pt;line-height: 36%;text-align: left;"><span class="s30">4 </span>+ <span class="s15">n </span><span class="s3">− </span>1</p><p class="s3" style="text-indent: 0pt;line-height: 64%;text-align: left;">− <span class="s30">2</span><span class="s9"> </span>−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 24pt;text-align: right;">= <span class="s15">an </span>lg <span class="s15">n </span>+ <span class="s121">( </span><span class="s32">a</span></p><p class="s9" style="padding-left: 12pt;text-indent: 0pt;line-height: 92%;text-align: left;"><u>3</u><span class="s26">a</span><span class="s15"> </span><span class="s25">+</span> <span class="s26">a </span><u>lg 3</u> <span class="s25">+</span> 1<span class="s19">\</span><span class="s13"> </span><span class="s142">n</span><span class="s15"> </span><span class="s3">− </span>1</p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">4</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">4</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">= <span class="s15">an </span>lg <span class="s15">n </span>+ <span class="s72">(</span><span class="s3">−</span>2<span class="s15">a </span>+ <span class="s32">a</span><span class="s15"> </span>lg 3 + 1<span class="s72">\</span><span class="s13"> </span><span class="s15">n </span><span class="s3">− </span>1</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">≤</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 97pt;text-indent: 0pt;line-height: 11pt;text-align: left;"><span class="p">To be true, must be </span>an <span class="s9">lg </span>n</p><p class="s15" style="text-indent: 0pt;line-height: 8pt;text-align: center;">a</p><p class="s9" style="padding-left: 47pt;text-indent: 0pt;line-height: 68%;text-align: center;"><span class="s3">− </span>2<span class="s15">a </span>+ <span class="s30">4 </span>lg 3 + 1 <span class="s3">≤ </span>0</p><p class="s9" style="padding-top: 3pt;padding-left: 62pt;text-indent: 0pt;line-height: 7pt;text-align: center;">lg 3</p><p style="text-indent: 0pt;text-align: left;"><span><img width="19" height="1" alt="image" src="cmsc351/Image_221.png"/></span></p><p class="s9" style="padding-left: 184pt;text-indent: 0pt;line-height: 67%;text-align: left;">( <span class="s30">4 </span><span class="s3">− </span>2)<span class="s15">a </span><span class="s3">≥ </span>1</p><p class="s9" style="padding-top: 1pt;text-indent: 0pt;line-height: 8pt;text-align: center;">1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="49" height="1" alt="image" src="cmsc351/Image_222.png"/></span></p><p class="s13" style="padding-top: 7pt;text-indent: 0pt;text-align: left;"> <span class="s180">≥</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">4</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="padding-left: 184pt;text-indent: 0pt;text-align: left;"><span class="s181">a </span>≥ <span class="s71">2 </span>− <span class="s57">3 lg 3</span></p><p class="s9" style="padding-left: 22pt;text-indent: 0pt;line-height: 15pt;text-align: center;"><span class="s15">T </span>(<span class="s15">n</span>) <u> 1 </u> <span class="s15">n </span>lg <span class="s15">n</span></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">4</p><p style="text-indent: 0pt;text-align: left;"/><p class="s71" style="padding-left: 31pt;text-indent: 0pt;line-height: 15pt;text-align: center;">2 <span class="s3">− </span><span class="s57">3 lg 3</span></p><p class="s9" style="padding-left: 163pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s15">T </span>(<span class="s15">n</span>) <span class="s3">≈ </span>1<span class="s15">.</span>23 <span class="s3">· </span><span class="s15">n </span>lg <span class="s15">n</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark132">Average case analysis of quicksort from exact recurrence.</a><a name="bookmark146">‌</a></h4><p style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">When we choose a pivot element, the pivot will end up at some index q. We don’t know where q is yet. Since we will be iterating over the whole array, the probability of choosing a particular index is 1/n. Then you have to do the group on the left and the group on the right. And do it for all n indices. Solving this will require everything we know to do.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s22" style="padding-top: 2pt;text-indent: 0pt;text-align: left;"> <span class="s13"> </span><span class="s28">1</span><span class="s9"> </span><span class="s3">− − −</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 167pt;text-indent: 0pt;text-align: left;">n</p><p class="s15" style="padding-top: 1pt;padding-left: 128pt;text-indent: 0pt;line-height: 9pt;text-align: left;">T <span class="s9">(</span>n<span class="s9">) = (</span>T <span class="s9">(</span>q <span class="s9">1) + </span>T <span class="s9">(</span>n q<span class="s9">)) + </span>n <span class="s9">1</span></p><p class="s15" style="padding-left: 179pt;text-indent: 0pt;line-height: 6pt;text-align: left;">n</p><p class="s11" style="padding-left: 162pt;text-indent: 0pt;line-height: 8pt;text-align: left;">q<span class="s14">=1</span></p><p class="s11" style="padding-left: 177pt;text-indent: 0pt;line-height: 2pt;text-align: left;">n</p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 3pt;padding-left: 151pt;text-indent: 0pt;line-height: 85%;text-align: left;">= <u>1</u><span class="s23"> </span>(<span class="s15">T </span>(<span class="s15">q </span><span class="s3">− </span>1) + <span class="s15">T </span>(<span class="s15">n </span><span class="s3">− </span><span class="s15">q</span>)) + <span class="s15">n </span><span class="s3">− </span>1</p><p class="s11" style="padding-left: 172pt;text-indent: 0pt;line-height: 8pt;text-align: left;">q<span class="s14">=1</span></p><p class="s11" style="padding-left: 177pt;text-indent: 0pt;line-height: 2pt;text-align: left;">n n</p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">q<span class="s14">=1</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">q<span class="s14">=1</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 2pt;padding-left: 151pt;text-indent: 0pt;text-align: left;">= <u>1</u><span class="s23"> </span>(<span class="s15">T </span>(<span class="s15">q </span><span class="s3">− </span>1)) + ( <u>1</u><span class="s23"> </span><span class="s15">T </span>(<span class="s15">n </span><span class="s3">− </span><span class="s15">q</span>)) + <span class="s15">n </span><span class="s3">− </span>1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 4pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">first is sum of Ts from 0 to n-1 and the other is the downward sum from n-1 to 0. So we get two sums of T</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="padding-top: 1pt;text-indent: 0pt;text-align: left;"> <span class="s42">2</span><span class="s9"> </span><span class="s182">−</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 2pt;padding-left: 172pt;text-indent: 0pt;line-height: 13pt;text-align: left;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s9" style="padding-left: 151pt;text-indent: 0pt;line-height: 8pt;text-align: left;">= <span class="s15">T </span>(<span class="s15">q</span>) + <span class="s15">n </span>1</p><p class="s15" style="padding-left: 163pt;text-indent: 0pt;line-height: 6pt;text-align: left;">n</p><p class="s11" style="padding-left: 172pt;text-indent: 0pt;line-height: 8pt;text-align: left;">q<span class="s14">=0</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">now apply strong constructive induction, guess </span>an <span class="s9">lg </span>n</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 8pt;padding-left: 103pt;text-indent: 0pt;line-height: 15pt;text-align: left;">Base n =1<span class="s15">a</span><span class="s9">(1) lg(1) = 0</span><span class="s178">v'</span></p><p class="s9" style="padding-left: 111pt;text-indent: 0pt;line-height: 17pt;text-align: left;"><span class="p">I.H. For </span>1 <span class="s3">≤ </span><span class="s15">k < n T </span>(<span class="s15">k</span>) <span class="s3">≤ </span><span class="s15">ak </span>lg <span class="s15">k</span></p><p class="s13" style="padding-top: 1pt;text-indent: 0pt;text-align: left;"> <span class="s42">2</span><span class="s9"> </span><span class="s182">−</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 172pt;text-indent: 0pt;line-height: 11pt;text-align: left;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s15" style="padding-left: 128pt;text-indent: 0pt;line-height: 8pt;text-align: left;">T <span class="s9">(</span>n<span class="s9">) = </span>T <span class="s9">(</span>q<span class="s9">) + </span>n <span class="s9">1</span></p><p class="s15" style="padding-left: 163pt;text-indent: 0pt;line-height: 6pt;text-align: left;">n</p><p class="s11" style="padding-left: 172pt;text-indent: 0pt;line-height: 8pt;text-align: left;">q<span class="s14">=1</span></p><p class="s22" style="padding-top: 2pt;text-indent: 0pt;text-align: left;"> <span class="s28">2</span><span class="s3">≤ −</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 172pt;text-indent: 0pt;line-height: 13pt;text-align: left;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s15" style="padding-left: 22pt;text-indent: 0pt;line-height: 8pt;text-align: center;">aq <span class="s9">lg </span>q <span class="s9">+ </span>n <span class="s9">1</span></p><p class="s15" style="padding-left: 163pt;text-indent: 0pt;line-height: 6pt;text-align: left;">n</p><p class="s11" style="padding-left: 172pt;text-indent: 0pt;line-height: 8pt;text-align: left;">q<span class="s14">=1</span></p><p class="s94" style="padding-top: 1pt;text-indent: 0pt;text-align: left;"> <span class="s10">2</span><span class="s26">a</span><span class="s15"> </span><span class="s45">−</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 176pt;text-indent: 0pt;line-height: 13pt;text-align: left;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s9" style="padding-left: 151pt;text-indent: 0pt;line-height: 8pt;text-align: left;">= <span class="s15">q </span>lg <span class="s15">q </span>+ <span class="s15">n </span>1</p><p class="s15" style="padding-left: 165pt;text-indent: 0pt;line-height: 6pt;text-align: left;">n</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">r</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 8pt;text-align: right;">q<span class="s14">=1</span></p><p class="s10" style="padding-top: 1pt;text-indent: 0pt;line-height: 8pt;text-align: right;">2<span class="s26">a</span><span class="s15"> n</span></p><p class="s3" style="text-indent: 0pt;line-height: 52%;text-align: right;">≈ <span class="s103">n </span><span class="s183">1</span></p><p class="s15" style="padding-top: 13pt;text-indent: 0pt;line-height: 18pt;text-align: left;">x <span class="s9">lg </span>xdx <span class="s9">+ </span>n <span class="s3">− </span><span class="s9">1</span></p><p class="s15" style="padding-top: 4pt;padding-left: 163pt;text-indent: 0pt;line-height: 9pt;text-align: left;"><span class="s10">2</span><u>a</u><span class="s153"> </span>x<span class="s16">2 </span><span class="s9">lg </span>x x<span class="s16">2 </span><span class="s9">lg </span>e</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s184" style="padding-left: 183pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="36" height="1" alt="image" src="cmsc351/Image_223.png"/></span> <span><img width="35" height="1" alt="image" src="cmsc351/Image_224.png"/></span></p><p class="s13" style="padding-left: 15pt;text-indent: 0pt;line-height: 80%;text-align: left;">7<span class="s185"> </span><span class="s186">n</span></p><p class="s9" style="text-indent: 0pt;line-height: 64%;text-align: left;"><span class="s30">4 </span>+ <span class="s15">c </span><span class="s3">− </span>(</p><p style="text-indent: 0pt;text-align: left;"/><p class="s30" style="text-indent: 0pt;line-height: 64%;text-align: left;">2 <span class="s3">−</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 18pt;text-indent: 0pt;line-height: 8pt;text-align: left;">+ <span class="s15">c</span>)</p><p class="s9" style="text-indent: 0pt;line-height: 9pt;text-align: left;">4</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 15pt;text-align: left;">+ <span class="s15">n </span><span class="s3">− </span>1</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 151pt;text-indent: 0pt;line-height: 65%;text-align: left;">= <span class="s103">n </span>2 <span class="s3">− </span><span class="s30">4 </span>+ <span class="s15">c</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">=</p><p class="s184" style="padding-left: 151pt;text-indent: 0pt;line-height: 10pt;text-align: left;"><span style=" color: black; font-family:"Bookman Old Style", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 9.5pt;"> </span><span><img width="37" height="1" alt="image" src="cmsc351/Image_225.png"/></span> <span><img width="36" height="1" alt="image" src="cmsc351/Image_226.png"/></span></p><p class="s9" style="padding-left: 4pt;text-indent: 0pt;line-height: 14pt;text-align: left;"><span class="s13"> </span><span class="s16">1 </span>+ <span class="s15">n </span><span class="s3">− </span>1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s176" style="padding-left: 16pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="35" height="1" alt="image" src="cmsc351/Image_227.png"/></span> <span><img width="34" height="1" alt="image" src="cmsc351/Image_228.png"/></span></p><p class="s15" style="padding-top: 4pt;padding-bottom: 2pt;padding-left: 163pt;text-indent: 0pt;text-align: left;"><span class="s10">2</span><u>a</u><span class="s153"> </span>n<span class="s16">2 </span><span class="s9">lg </span>n n<span class="s16">2 </span><span class="s9">lg </span>e</p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">n</p><p style="padding-left: 165pt;text-indent: 0pt;line-height: 10pt;text-align: left;"/><p class="s9" style="padding-left: 32pt;text-indent: 0pt;text-align: left;">1<span class="s16">2 </span>lg 1 1<span class="s16">2 </span>lg <span class="s15">e</span><span class="s153"> </span><span class="s13">7</span></p><p class="s30" style="text-indent: 0pt;line-height: 64%;text-align: left;">2 <span class="s3">−</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 11pt;padding-left: 163pt;text-indent: 0pt;line-height: 9pt;text-align: left;"><span class="s10">2</span><u>a</u><span class="s153"> </span>n<span class="s16">2 </span><span class="s9">lg </span>n n<span class="s16">2 </span><span class="s9">lg </span>e</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s184" style="padding-left: 183pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="37" height="1" alt="image" src="cmsc351/Image_229.png"/></span> <span><img width="35" height="1" alt="image" src="cmsc351/Image_230.png"/></span></p><p class="s10" style="padding-top: 5pt;padding-left: 12pt;text-indent: 0pt;line-height: 16pt;text-align: left;">lg <span class="s26">e</span><span class="s15"> </span><span class="s19">7</span></p><p class="s9" style="padding-left: 151pt;text-indent: 0pt;line-height: 64%;text-align: left;">= <span class="s103">n </span>2 <span class="s3">−</span></p><p class="s15" style="padding-top: 3pt;text-indent: 0pt;line-height: 8pt;text-align: right;">an <span class="s9">lg </span>e</p><p class="s9" style="padding-left: 8pt;text-indent: 0pt;line-height: 8pt;text-align: center;">+</p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 9pt;text-align: center;">4 4</p><p class="s15" style="padding-top: 1pt;padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">a <span class="s9">lg </span>e</p><p class="s9" style="padding-left: 11pt;text-indent: 0pt;line-height: 15pt;text-align: left;">+ <span class="s15">n </span><span class="s3">− </span>1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="36" height="1" alt="image" src="cmsc351/Image_231.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="28" height="1" alt="image" src="cmsc351/Image_232.png"/></span></p><p class="s9" style="padding-left: 151pt;text-indent: 0pt;line-height: 64%;text-align: left;">= <span class="s15">an </span>lg <span class="s15">n </span><span class="s3">− </span><span class="s30">2 </span>+ <span class="s30">2</span><span class="s15">n </span>+ <span class="s15">n </span><span class="s3">− </span>1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="text-indent: 0pt;text-align: right;">= <span class="s15">an </span>lg <span class="s15">n </span>+ (</p><p class="s15" style="padding-top: 2pt;text-indent: 0pt;line-height: 8pt;text-align: left;">a <span class="s9">lg </span>e</p><p style="text-indent: 0pt;text-align: left;"><span><img width="28" height="1" alt="image" src="cmsc351/Image_233.png"/></span></p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 67%;text-align: left;"><span class="s30">2 </span>+ 1)<span class="s15">n </span><span class="s3">− </span>1 +</p><p class="s15" style="padding-top: 2pt;padding-bottom: 1pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">a <span class="s9">lg </span>e</p><p style="padding-left: 1pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="28" height="1" alt="image" src="cmsc351/Image_234.png"/></span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">2<span class="s15">n</span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="padding-left: 62pt;text-indent: 0pt;text-align: center;"><span class="p">need </span>− <span class="s32">a </span><span class="s10">lg </span><span class="s26">e</span><span class="s15"> </span><span class="s9">+ 1 </span>≤ <span class="s9">0</span></p><p class="s9" style="text-indent: 0pt;line-height: 7pt;text-align: center;">2</p><p style="text-indent: 0pt;text-align: left;"><span><img width="19" height="1" alt="image" src="cmsc351/Image_235.png"/></span></p><p class="s15" style="padding-left: 149pt;text-indent: 0pt;line-height: 67%;text-align: left;">a <span class="s3">≥ </span><span class="s30">lg </span>e <span class="s9">= 2 ln 2 </span><span class="s3">≈ </span><span class="s9">1</span>.<span class="s9">39</span></p><p style="padding-top: 9pt;text-indent: 0pt;text-align: center;">choose a = 1.39 and the last term becomes a number always less than or equal to 1, which is dominated by minus 1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-top: 9pt;padding-left: 149pt;text-indent: 0pt;text-align: left;">and the second highest term becomes 1 minus 1=0</p><p class="s9" style="padding-left: 128pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s15">T </span>(<span class="s15">n</span>) <span class="s3">≤ </span>1<span class="s15">.</span>39<span class="s15">n </span>lg <span class="s15">n</span></p><p class="s9" style="text-indent: 0pt;line-height: 7pt;text-align: center;">2</p><p style="text-indent: 0pt;text-align: left;"><span><img width="19" height="1" alt="image" src="cmsc351/Image_236.png"/></span></p><p class="s9" style="text-indent: 0pt;line-height: 8pt;text-align: right;">=</p><p class="s9" style="text-indent: 0pt;line-height: 9pt;text-align: right;">lg <span class="s15">e</span></p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">n <span class="s9">lg </span>n</p><p class="s9" style="padding-top: 2pt;padding-left: 151pt;text-indent: 0pt;text-align: left;">= 2<span class="s15">n </span>ln <span class="s15">n</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-top: 5pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark133">New Book method</a><a name="bookmark147">‌</a></h4><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="p">Given What is the probability that the smallest and largest elements are compared? </span><span class="s9">(</span>x<span class="s16">1</span>, xn<span class="s9">)? </span><span class="s35">2</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 3pt;text-indent: 0pt;line-height: 12pt;text-align: left;">If you pick the</p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 6pt;text-indent: 0pt;line-height: 91%;text-align: justify;">largest or smallest as the pivot, then it will compare against every other element including the other extreme. But if you don’t pick an extreme the two will be partitioned away and never be compared. So on average the number of comparisons you get from comparing the smallest and largest is also <span class="s187">2</span><span class="s14"> </span>.</p><p class="s24" style="text-indent: 0pt;line-height: 11pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">j i<span class="s14">+1</span></p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 7pt;text-indent: 0pt;line-height: 91%;text-align: justify;">What is the probability that <span class="s15">xi, xj </span><span class="s9">: (</span><span class="s15">i < j</span><span class="s9">) </span>will be compared? If you choose a pivot less than i, the two will end up on the same pivot together on the large side. If you choose a pivot greater than j, the two will end up on the small side together. The only way not to compare the two is to choose a pivot in between i and j. That probability is<u> </u><span class="s57">2</span><span class="s14"> </span>If you have 2 elements next to one another in the sorted array, they will always be compared. Otherwise how will you know?<u> </u><span class="s57">2</span><span class="s14"> </span><span class="s9">= 1</span></p><p class="s14" style="padding-bottom: 4pt;padding-left: 40pt;text-indent: 0pt;line-height: 6pt;text-align: left;">(<span class="s11">i</span>+1)<span class="s24">−</span><span class="s11">i</span>+1</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="padding-left: 237pt;text-indent: 0pt;line-height: 7pt;text-align: left;"><span style=" color: black; font-family:PMingLiU, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 6.5pt;"> </span></p><p class="s15" style="padding-top: 1pt;padding-bottom: 3pt;padding-left: 48pt;text-indent: 0pt;text-align: center;">T <span class="s9">(</span>n<span class="s9">) = </span><span class="s22"> </span><span class="s13"> </span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1 </span>j<span class="s14">=</span>i<span class="s14">+1</span></p><p style="padding-left: 233pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1 </span>j<span class="s14">=</span>i<span class="s14">+1</span></p><p style="padding-left: 233pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 15pt;text-align: left;">i<span class="s14">=1 </span>j<span class="s14">=</span>i<span class="s14">+1 </span><span class="s188">j </span><span class="s3">− </span><span class="s15">i </span><span class="s9">+ 1</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s41" style="padding-top: 5pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">= <span class="s9"> </span><u> 2</u><u> </u></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s41" style="padding-top: 6pt;padding-left: 62pt;text-indent: 0pt;line-height: 70%;text-align: center;">= 2 <span class="s9"> </span><u> 1</u><u> </u></p><p class="s11" style="padding-left: 62pt;text-indent: 0pt;line-height: 15pt;text-align: center;">i<span class="s14">=1 </span>j<span class="s14">=</span>i<span class="s14">+1 </span><span class="s188">j </span><span class="s3">− </span><span class="s15">i </span><span class="s9">+ 1</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 8pt;text-align: center;">n</p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 18pt;text-align: center;"><span class="s9">= 2 (</span>Hn<span class="s3">−</span>i<span class="s16">+1 </span><span class="s3">− </span><span class="s9">1)</span></p><p class="s11" style="padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">i<span class="s14">=1</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: center;">n</p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 18pt;text-align: center;">= 2 (<span class="s15">Hi </span><span class="s3">− </span>1)</p><p class="s11" style="padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">i<span class="s14">=1</span></p><p class="s11" style="padding-left: 62pt;text-indent: 0pt;line-height: 2pt;text-align: center;">n n</p><p class="s9" style="padding-top: 5pt;padding-left: 222pt;text-indent: 0pt;text-align: left;">= 2<span class="s23"> </span><span class="s15">Hi </span><span class="s3">− </span>2<span class="s23"> </span>1</p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 240pt;text-indent: 0pt;line-height: 7pt;text-align: left;"><span style=" color: black; font-family:Garamond, serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 6.5pt;"> </span></p><p style="padding-top: 23pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Big important insight, that you can calculate the probability that any 2 arbitrary elements can be compared.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark134">Is Quicksort In place?</a><a name="bookmark148">‌</a></h3><p class="s9" style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;"><span class="p">In place algorithms use a constant amount of extra space, it isn’t a function of the number of elements n. Because Quick sort is recursive it can add more variables to the stack (multiple versions of q, and r). So to be in place you use extra memory </span>Θ(1) <span class="p">for algorithm variables + </span>Θ(log <span class="s15">n</span>) <span class="p">stack average. There isn’t really a formal definition of In place. Informally it’s that an algorithm doesn’t use a lot of extra space.</span></p><p style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">One way to avoid using much extra space is to check which side of a partition is smaller and do that side of the partition first.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark135">Randomized pivot selection</a><a name="bookmark149">‌</a></h3><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">You can use a random pivot element as seen in the book.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark136">3 Median Pivot</a><a name="bookmark150">‌</a></h3><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">You can make sure that you’ve got a good pivot by picking 3 elements randomly and using their median as the pivot. This gives you a much better chance of pivoting near the middle.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark137">Small Size Optimization</a><a name="bookmark151">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">In practice when qucksort gets down to 10 to 20 elements many implementations use a more efficient algorithm like insertion sort to sort the small groups of elements.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><ol id="l12"><li style="padding-left: 38pt;text-indent: -31pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark152">Algorithm Strengths and Weaknesses</a><a name="bookmark154">‌</a></h2><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 202pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_237.png"/></span></p><table style="border-collapse:collapse" cellspacing="0"><tr style="height:13pt"><td style="width:60pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Algorithm</p></td><td style="width:68pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-left: 3pt;padding-right: 3pt;text-indent: 0pt;line-height: 12pt;text-align: center;">Comparisons</p></td><td style="width:52pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-left: 3pt;padding-right: 3pt;text-indent: 0pt;line-height: 12pt;text-align: center;">Moves</p></td><td style="width:81pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-left: 5pt;padding-right: 5pt;text-indent: 0pt;line-height: 12pt;text-align: center;">Spatial Locality</p></td><td style="width:48pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-left: 5pt;padding-right: 5pt;text-indent: 0pt;line-height: 12pt;text-align: center;">In Place</p></td><td style="width:89pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-left: 4pt;padding-right: 4pt;text-indent: 0pt;line-height: 12pt;text-align: center;">Good Worst Case</p></td></tr><tr style="height:17pt"><td style="width:60pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-top: 1pt;padding-left: 5pt;text-indent: 0pt;text-align: left;">Merge Sort</p></td><td style="width:68pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s165" style="padding-top: 1pt;padding-left: 3pt;text-indent: 0pt;text-align: center;">n <span class="s166">lg </span>n</p></td><td style="width:52pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-top: 1pt;padding-left: 3pt;padding-right: 3pt;text-indent: 0pt;text-align: center;">unknown</p></td><td style="width:81pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s189" style="padding-left: 5pt;padding-right: 5pt;text-indent: 0pt;line-height: 15pt;text-align: center;">v'</p></td><td style="width:48pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-top: 1pt;text-indent: 0pt;text-align: center;">X</p></td><td style="width:89pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s189" style="padding-left: 4pt;padding-right: 4pt;text-indent: 0pt;line-height: 15pt;text-align: center;">v'</p></td></tr><tr style="height:17pt"><td style="width:60pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-top: 1pt;padding-left: 8pt;text-indent: 0pt;text-align: left;">Heap Sort</p></td><td style="width:68pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s165" style="padding-top: 1pt;padding-left: 3pt;text-indent: 0pt;text-align: center;">n <span class="s166">lg </span>n</p></td><td style="width:52pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s165" style="padding-top: 1pt;padding-left: 6pt;padding-right: 3pt;text-indent: 0pt;text-align: center;">n <span class="s166">lg </span>n</p></td><td style="width:81pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s139" style="padding-top: 1pt;text-indent: 0pt;text-align: center;">X</p></td><td style="width:48pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s189" style="padding-left: 5pt;padding-right: 5pt;text-indent: 0pt;line-height: 15pt;text-align: center;">v'</p></td><td style="width:89pt;border-top-style:solid;border-top-width:1pt;border-bottom-style:solid;border-bottom-width:1pt"><p class="s189" style="padding-left: 4pt;padding-right: 4pt;text-indent: 0pt;line-height: 15pt;text-align: center;">v'</p></td></tr><tr style="height:16pt"><td style="width:60pt;border-top-style:solid;border-top-width:1pt"><p class="s139" style="padding-top: 1pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Quick Sort</p></td><td style="width:68pt;border-top-style:solid;border-top-width:1pt"><p class="s166" style="padding-top: 1pt;padding-left: 3pt;text-indent: 0pt;text-align: center;">1<span class="s165">.</span>39<span class="s165">n </span>lg <span class="s165">n</span></p></td><td style="width:52pt;border-top-style:solid;border-top-width:1pt"><p class="s165" style="padding-left: 7pt;padding-right: 3pt;text-indent: 0pt;text-align: center;"><span class="s190">1 </span>n <span class="s166">lg </span>n</p></td><td style="width:81pt;border-top-style:solid;border-top-width:1pt"><p class="s189" style="padding-left: 5pt;padding-right: 5pt;text-indent: 0pt;line-height: 15pt;text-align: center;">v'</p></td><td style="width:48pt;border-top-style:solid;border-top-width:1pt"><p class="s189" style="padding-left: 5pt;padding-right: 5pt;text-indent: 0pt;line-height: 15pt;text-align: center;">v'</p></td><td style="width:89pt;border-top-style:solid;border-top-width:1pt"><p class="s139" style="padding-top: 1pt;text-indent: 0pt;text-align: center;">X</p></td></tr></table><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="text-indent: 0pt;line-height: 8pt;text-align: center;">2</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark153">Memory Hierarchy</a><a name="bookmark155">‌</a></h3><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: justify;">Memory Hierarchy allows further, machine specific optimizations. Doing a lot of work in fast memory is preferable to waiting to grab data from slower memories Merge sort and quick sort both take advantage of this spacial locality of fast memory. It sub sorts the array in pieces that fit into caches. Heap sort doesn’t as it’s sorting mechanism jumps all over the tree. It lacks spatial locality. Merge Sort also has the problem that it isn’t In-place, so it uses a lot of extra memory.</p><p style="text-indent: 0pt;text-align: left;"><br/></p></li><li style="padding-left: 38pt;text-indent: -31pt;text-align: justify;"><h2 style="display: inline;"><a name="bookmark156">Linear Sorting Algorithms</a><a name="bookmark163">‌</a></h2><h3 style="padding-top: 9pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark157">Re-evaluating Sort</a><a name="bookmark164">‌</a></h3><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: justify;">All of our algorithms have thus far been strongly dependent upon comparisons. Let’s take a closer look at that.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark158">Find biggest element in array</a><a name="bookmark165">‌</a></h4><p style="padding-top: 4pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Run one instance of selection sort, find biggest element. <span class="s15">n </span><span class="s3">− </span><span class="s9">1 </span>comparisons.</p><h4 style="padding-top: 9pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark159">Find second largest element in array</a><a name="bookmark166">‌</a></h4><p class="s15" style="padding-top: 4pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;"><span class="p">First idea: form max heap and pull two off the top. Create Heap + sift: </span><span class="s3">≈ </span>n <span class="s9">+ lg </span>n</p><h4 style="padding-top: 9pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark160">Find k largest elements in array</a><a name="bookmark167">‌</a></h4><p class="s15" style="padding-top: 4pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;"><span class="p">Sift again: </span>n <span class="s9">+ (</span>k <span class="s3">− </span><span class="s9">1) lg </span>n</p><h4 style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark161">Natural approach: Hold a Tournament</a><a name="bookmark168">‌</a></h4><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Comparisons are like playing games in a sportsball match. You need to eliminate <span class="s15">n </span><span class="s9">1 </span>teams to find the best, so you must at least run <span class="s15">n </span><span class="s9">1 </span>comparisons. This gives us a lower bound. In a double elimination tournament when one of the playing groups loses it must lose again to be eliminated. The superior team will never lose. All other teams must lose at most twice. If you lose to someone and they lose to someone else, you’re no longer second best. So you don’t</p><p class="s9" style="padding-top: 2pt;padding-left: 7pt;text-indent: 0pt;line-height: 70%;text-align: justify;"><span class="p">need to incur an extra comparison. If you keep track of who lost to whom you’ll conserve comparisons and be bound by the height of the tournament bracket, </span>lg <span class="s15">n </span><span class="s3">− </span>1<span class="p">. When you run the tournament you incur </span><span class="s15">n </span><span class="s3">− </span>1 <span class="p">to find the best player. Then another </span>lg <span class="s15">n </span><span class="s3">− </span>1 <span class="p">to order everyone else, giving </span><span class="s15">n </span>+ lg <span class="s15">n </span><span class="p">comparisons.</span></p><h4 style="padding-top: 11pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark162">Finding Best and Worst</a><a name="bookmark169">‌</a></h4><p class="s9" style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: justify;"><span class="p">Run tournament to find best, then take all teams who lost both matches </span>(<span class="s15">n/</span>2)<span class="p">, and run again in reverse. There are</span></p><p class="s9" style="padding-left: 8pt;text-indent: 0pt;line-height: 9pt;text-align: justify;"><span class="s84">n</span><span class="s11"> </span><span class="s3">− </span>1 <span class="p">following comparisons to find the worst team. </span><span class="s15">n </span><span class="s3">− </span>1 + <span class="s26">n</span><span class="s15"> </span><span class="s3">− </span>1 = <span class="s15">n </span>+ <span class="s26">n</span><span class="s15"> </span><span class="s3">− </span>2 = <span class="s16">3 </span><span class="s15">n </span><span class="s3">− </span>2<span class="p">.</span></p><p style="padding-left: 368pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_238.png"/></span></p><p class="s14" style="padding-left: 8pt;text-indent: 0pt;line-height: 8pt;text-align: left;">2 2 2 2</p><p style="text-indent: 0pt;text-align: left;"><br/></p></li><li style="padding-left: 38pt;text-indent: -31pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark170">Counting Sort</a><a name="bookmark171">‌</a></h2><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Say you have a list of duplicate integers in a range and you want to sort them. <span class="s15">n </span>integers in the range <span class="s9">0</span><span class="s15">, . . . , k </span><span class="s9">1</span>. Sort A into B. So simply count the number of integers of each size, and dole them out in order.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">1 </span><span class="h4">for </span>i <span class="s10">= 0 </span><span class="s191">to </span>k<span class="s15"> </span><span class="s10">1</span><span class="s9"> </span><span class="h4">do</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">2 </span><span><img width="1" height="16" alt="image" src="cmsc351/Image_239.png"/></span><span class="s33"> </span>C<span class="s9">[</span>i<span class="s9">] 0</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">3 <span class="h4">end</span></p><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">4 </span><span class="h4">for </span>j <span class="s10">= 1 </span><span class="s191">to </span>n<span class="s15"> </span><span class="h4">do</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">5 </span><span><img width="1" height="16" alt="image" src="cmsc351/Image_240.png"/></span><span class="s33"> </span>C<span class="s9">[</span>A<span class="s9">[</span>j<span class="s9">]] </span>C<span class="s9">[</span>A<span class="s9">[</span>j<span class="s9">]] + 1</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">6 <span class="h4">end</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">7 <span class="s15">t </span><span class="s9">0</span><span class="p">;</span></p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">8 </span><span class="h4">for </span>i <span class="s10">= 0 </span><span class="s191">to </span>k<span class="s15"> </span><span class="s10">1</span><span class="s9"> </span><span class="h4">do</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="65" alt="image" src="cmsc351/Image_241.png"/></span></p><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;"><span class="s17">9 </span><span class="h4">for </span>j <span class="s10">= 0 </span><span class="s191">to </span>C<span class="s10">[</span>i<span class="s10">]</span><span class="s9"> </span><span class="h4">do</span></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s17">10 </span><span><img width="1" height="32" alt="image" src="cmsc351/Image_242.png"/></span><span class="s33"> </span>t <span class="s3">← </span>t <span class="s9">+ 1</span><span class="p">;</span></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 10pt;text-align: left;"><span class="s17">11 </span>B<span class="s9">[</span>t<span class="s9">] </span><span class="s3">← </span>i<span class="p">;</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 10pt;text-align: left;">12 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">13 <span class="h4">end</span></p><h4 style="padding-left: 187pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Algorithm 10: <span class="p">Counting Sort</span></h4><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 6pt;text-indent: 0pt;text-align: justify;"><span class="p">The running time is the number of numbers plus the range of the numbers. </span>Θ(<span class="s15">n </span>+ <span class="s15">k</span>)<span class="p">. If you’re sorting a lot of numbers in a small range, it’s the numbers that will dominate. If it’s a large range with sparse numbers, the range will dominate.</span></p><p style="padding-left: 7pt;text-indent: 0pt;text-align: justify;">An alternative method is to form the partial sums of C. Where each value in C is the number of elements less than or equal to the index. Then iterate backwards through the original array. When you encounter an element in A, lookup that index in C, then assign an element into B, then decrement the value in C. This has the added value of treating each element as a unique entity, instead of as simply an integer. So you could do this on comparable objects.</p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-top: 2pt;padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">1 </span><span class="h4">for </span>i <span class="s10">= 0 </span><span class="s191">to </span>k<span class="s15"> </span><span class="s10">1</span><span class="s9"> </span><span class="h4">do</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">2 </span><span><img width="1" height="16" alt="image" src="cmsc351/Image_243.png"/></span><span class="s33"> </span>C<span class="s9">[</span>i<span class="s9">] 0</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">3 <span class="h4">end</span></p><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">4 </span><span class="h4">for </span>j <span class="s10">= 1 </span><span class="s191">to </span>n<span class="s15"> </span><span class="h4">do</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">5 </span><span><img width="1" height="16" alt="image" src="cmsc351/Image_244.png"/></span><span class="s33"> </span>C<span class="s9">[</span>A<span class="s9">[</span>j<span class="s9">]] </span>C<span class="s9">[</span>A<span class="s9">[</span>j<span class="s9">]] + 1</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">6 <span class="h4">end</span></p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">7 </span><span class="h4">for </span>i <span class="s10">= 1 </span><span class="s191">to </span>k<span class="s15"> </span><span class="s10">1</span><span class="s9"> </span><span class="h4">do</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">8 </span><span><img width="1" height="16" alt="image" src="cmsc351/Image_245.png"/></span><span class="s33"> </span>C<span class="s9">[</span>i<span class="s9">] </span>C<span class="s9">[</span>A<span class="s9">[</span>i<span class="s9">]] + 1</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">9 <span class="h4">end</span></p><p class="s26" style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: justify;"><span class="s17">10 </span><span class="h4">for </span>j <span class="s10">= </span>n <span class="s18">down to </span><span class="s10">1</span><span class="s9"> </span><span class="h4">do</span></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 18pt;text-align: justify;"><span class="s17">11 </span><span><img width="1" height="32" alt="image" src="cmsc351/Image_246.png"/></span><span class="s33"> </span>B<span class="s9">[</span>C<span class="s9">[</span>A<span class="s9">[</span>j<span class="s9">]]] </span><span class="s3">← </span>A<span class="s9">[</span>j<span class="s9">]</span><span class="p">;</span></p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 10pt;text-align: justify;"><span class="s17">12 </span><span class="s15">C</span>[<span class="s15">A</span>[<span class="s15">j</span>]] <span class="s3">← </span><span class="s15">C</span>[<span class="s15">A</span>[<span class="s15">j</span>]] <span class="s3">− </span>1<span class="p">;</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 9pt;text-align: justify;">13 <span class="h4">end</span></p><h4 style="padding-left: 159pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Algorithm 11: <span class="p">Partial Sum Counting Sort</span></h4><p class="s9" style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="p">Running time </span>Θ(<span class="s15">n </span>+ <span class="s15">k</span>)<span class="p">.</span></p><p style="padding-left: 6pt;text-indent: 0pt;text-align: left;">Now the C array represents the number of numbers less than the value of the index. Why do we go through A backwards? To maintain stability.</p><p style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;">We can use counting sort when <span class="s15">k < </span>nlogn and mergesort when <span class="s15">k > </span>nlogn</p><p style="text-indent: 0pt;text-align: left;"><br/></p></li><li style="padding-left: 38pt;text-indent: -31pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark172">Radix Sort</a><a name="bookmark174">‌</a></h2><p style="padding-top: 8pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Sort on the least significant digit, then the 2nd least significant digit, etcetera until the largest digit arrives. This only works if a stable sort is used for each intermittent pass over a digit.</p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Proved by example in lecture. Proved by induction on the intermittent sorts.</p><p style="text-indent: 0pt;text-align: left;"><span><img width="183" height="1" alt="image" src="cmsc351/Image_247.png"/></span></p><p class="s75" style="padding-left: 12pt;text-indent: -6pt;line-height: 125%;text-align: left;"> <span class="s18">Attribute Value Variable</span><span class="p"> Size 10 n</span></p><p style="padding-bottom: 2pt;padding-left: 12pt;text-indent: 0pt;text-align: left;">Radix 9 r</p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="182" height="1" alt="image" src="cmsc351/Image_248.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="183" height="1" alt="image" src="cmsc351/Image_249.png"/></span></p><p class="s9" style="padding-top: 1pt;padding-left: 7pt;text-indent: 5pt;line-height: 137%;text-align: left;"><span class="p">Digits 3 d Running Time: </span>Θ(<span class="s15">d</span>(<span class="s15">n </span>+ <span class="s15">r</span>))</p><h3 style="padding-top: 9pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark173">Analysis of running time</a><a name="bookmark175">‌</a></h3><p class="s15" style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;line-height: 91%;text-align: justify;"><span class="p">First let’s decide which radix is best for generic input. Let’s introduce a new parameter: Size of Values: </span>s<span class="p">. This is the total range of numbers. </span>s, d, r <span class="p">are all related by </span>s <span class="s9">= </span>rd<span class="p">. If given 6 digit numbers in base 10, </span>s <span class="s9">= 10</span><span class="s16">6</span><span class="p">. Taking logs we get </span><span class="s9">log</span><span class="s104">r </span>s <span class="s9">= </span>d <span class="p">This gives us the new Running time of </span><span class="s9">Θ((log</span><span class="s104">r </span>s<span class="s9">)(</span>n <span class="s9">+ </span>r<span class="s9">))</span><span class="p">. Taking out the r is trickier. Let’s think about optimizing this function. We can optimize by trying to find a minimum with respect to r. We can do that by taking the derivative and solving for 0.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 183pt;text-indent: 0pt;line-height: 112%;text-align: right;"><span class="s10">ln </span><u>s</u> <span class="s9">ln </span>r</p><p class="s9" style="padding-top: 3pt;text-indent: 0pt;text-align: left;">(<span class="s15">n </span>+ <span class="s15">r</span>)<span class="s121">7</span><span class="s143"> </span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 1pt;text-indent: 0pt;text-align: left;">= (ln <span class="s15">s</span>)</p><p class="s9" style="padding-top: 8pt;padding-left: 17pt;text-indent: -17pt;line-height: 90%;text-align: left;">ln <span class="s15">r </span><span class="s3">− </span><span class="s40">1 </span>(<span class="s15">n </span>+ <span class="s15">r</span>) (ln <span class="s15">r</span>)<span class="s16">2</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_250.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="85" height="1" alt="image" src="cmsc351/Image_251.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="46" height="1" alt="image" src="cmsc351/Image_252.png"/></span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">r</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 8pt;text-align: left;">ln <span class="s15">r </span><span class="s3">− </span><span class="s84">n</span></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">r</p><p style="padding-left: 27pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 12pt;text-align: right;">= (ln <span class="s15">s</span>)</p><p class="s9" style="padding-left: 2pt;text-indent: 0pt;line-height: 20pt;text-align: left;">(ln <span class="s15">r</span>)<span class="s16">2 </span><span class="s148">= 0</span></p><p class="s15" style="padding-left: 3pt;text-indent: 0pt;line-height: 7pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_253.png"/></span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 64%;text-align: center;">0 = ln <span class="s15">r </span><span class="s3">− </span><span class="s103">r</span></p><p class="s15" style="text-indent: 0pt;line-height: 8pt;text-align: center;">n</p><p style="text-indent: 0pt;text-align: left;"><span><img width="20" height="1" alt="image" src="cmsc351/Image_254.png"/></span></p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 7pt;text-align: center;">r <span class="s9">=</span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">ln <span class="s15">r</span></p><p class="s15" style="text-indent: 0pt;line-height: 7pt;text-align: center;">n</p><p style="text-indent: 0pt;text-align: left;"><span><img width="42" height="1" alt="image" src="cmsc351/Image_255.png"/></span></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">ln <span class="s11">n</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 17pt;text-align: center;"><span class="s153">r </span>= ln(<u> </u><span class="s26">n</span><span class="s15"> </span>)</p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 9pt;text-align: center;">n</p><p style="text-indent: 0pt;text-align: left;"><span><img width="72" height="1" alt="image" src="cmsc351/Image_256.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 8pt;text-align: center;">=</p><p class="s9" style="padding-left: 258pt;text-indent: -5pt;line-height: 76%;text-align: left;">ln <span class="s15">n </span>ln ln <span class="s15">n n</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="21" height="1" alt="image" src="cmsc351/Image_257.png"/></span></p><p class="s160" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">≈ <span class="s9">ln </span><span class="s15">n</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;line-height: 12pt;text-align: center;">So surprisingly the running time of radix sort can depend entirely on the input size, and not on the range of values.</p><p class="s9" style="padding-left: 6pt;text-indent: 0pt;line-height: 6pt;text-align: left;">Θ(<u> </u><span class="s35">ln </span><span class="s26">s</span><span class="s15"> </span>(<span class="s15">n </span>+<u> </u><span class="s26">n</span><span class="s15"> </span>))</p><p class="s62" style="text-indent: 0pt;line-height: 5pt;text-align: left;">ln <span class="s64">n</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="padding-left: 19pt;text-indent: 0pt;line-height: 9pt;text-align: left;">ln(<u> </u><span class="s55">n</span><span class="s11"> </span>)</p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">Θ( )</p><p style="text-indent: 0pt;text-align: left;"/><p class="s55" style="padding-top: 1pt;padding-left: 21pt;text-indent: -2pt;line-height: 75%;text-align: left;">n <span class="s57">ln </span>s<span class="s11"> </span><span class="s14">ln </span><span class="s11">n</span></p><p class="s14" style="padding-left: 19pt;text-indent: 0pt;text-align: left;">ln <span class="s11">n</span></p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 9pt;text-align: left;">But that’s not a great number, so in real life pick the closest power of 2. It’s nicest for the computer, and a digit</p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">looks like a set of bits. Take every group of r bits and compare based on those bits and return them. So we want to use Radix sort when it’s running time is less than Quicksort.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="text-indent: 0pt;line-height: 81%;text-align: left;">( \ <span class="s163">(</span> )</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 30pt;text-indent: 0pt;line-height: 17pt;text-align: left;"><span class="s9">Θ </span><u>n </u><span class="s10">log </span><u>s</u> < <span class="s9">Θ (</span>n <span class="s9">log </span>n<span class="s9">) Θ (log </span>s<span class="s9">) </span>< <span class="s9">Θ log</span><span class="s16">2 </span>n <span class="s9">log </span>s < <span class="s9">Θ (log </span>n<span class="s9">) log </span>n <span class="s9">= log </span>n<span class="s16">Θ(log </span>n<span class="s16">)</span>s < n<span class="s16">Θ(log </span>n<span class="s16">)</span></p><p class="s9" style="padding-left: 51pt;text-indent: 0pt;line-height: 9pt;text-align: left;">log <span class="s15">n</span></p><p class="s9" style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;line-height: 93%;text-align: left;"><span class="p">So Radix sort is theoretically better when the range is relatively small. But for 1 million numbers in binary, that gives us a very large range: </span>1<span class="s15">, </span>000<span class="s15">, </span>000<span class="s16">20</span></p><p style="padding-left: 6pt;text-indent: 0pt;line-height: 11pt;text-align: left;">It’s space-wise inefficient, but has spatial locality.</p></li><li style="padding-top: 3pt;padding-left: 38pt;text-indent: -31pt;text-align: justify;"><h2 style="display: inline;"><a name="bookmark176">Bucket Sort</a><a name="bookmark177">‌</a></h2><p style="padding-top: 8pt;padding-left: 6pt;text-indent: 0pt;text-align: justify;">Assume you have a uniformly distributed array of real numbers between 0 and 1. Create n buckets.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">1 <span class="p">Clear B;</span></p><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">2 </span><span class="h4">for </span>i <span class="s10">= 1 </span><span class="s191">to </span>n<span class="s15"> </span><span class="h4">do</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">l · J</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">3 </span><span><img width="1" height="16" alt="image" src="cmsc351/Image_258.png"/></span><span class="s33"> </span><span class="p">Put A[i] into bucket </span>B <span class="s9">[ </span>n A<span class="s9">[</span>i<span class="s9">] ]</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">4 <span class="h4">end</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">5 <span class="p">Sort each bucket;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">6 <span class="p">Concatenate each bucket;</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 6pt;text-indent: 0pt;text-align: left;">On average there will be 1 element per bucket. If you can rely on the buckets in the worst case not being very large you can use a quadratic sort within the bucket and still get a linear running time.</p><p style="padding-left: 7pt;text-indent: 0pt;text-align: justify;">You can even apply this to non uniform distributions. Assume a Normal distribution. Simply change the size of the buckets relative to the mean, with buckets closer to the mean having a smaller range and ones farther from the range on either side being larger.</p><p style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Also space wise inefficient, but has spatial locality.</p><p style="text-indent: 0pt;text-align: left;"><br/></p></li><li style="padding-left: 38pt;text-indent: -31pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark178">Selection</a><a name="bookmark183">‌</a></h2><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">How do we select the kth smallest element from a group of numbers? How do we select the median from a group of numbers? Median </span>= <span class="s15">n </span>+ <span class="s26">n</span><span class="s15"> </span>lg <span class="s15">n</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s140" style="padding-left: 12pt;text-indent: 0pt;text-align: left;"><span class="s17">1 </span><span class="h4">Function </span>SELECT(<span class="s18">A,k,p,r</span>)<span class="h4">is</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="192" alt="image" src="cmsc351/Image_259.png"/></span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">2 <span class="p">Find Approximate median for ‘qth smallest’;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">3 <span class="p">Partition based on ‘qth smallest’;</span></p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">− </p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">4 </span><span class="h4">if </span>k < q<span class="s15"> </span>p <span class="s10">+ 1</span><span class="s9"> </span><span class="h4">then</span></p><p class="s141" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">5 </span><span><img width="1" height="16" alt="image" src="cmsc351/Image_260.png"/></span><span class="s33"> </span>SELECT(<span class="s18">A,k,p,q-1</span>)<span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">6 <span class="h4">end</span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">7 </span>else if <span class="s18">k>q-p+1</span><span class="p"> </span>then</h4><p class="s141" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">8 </span><span><img width="1" height="16" alt="image" src="cmsc351/Image_261.png"/></span><span class="s33"> </span>SELECT(<span class="s18">A,k-q-p+1,q+1,r</span>)<span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">9 <span class="h4">end</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;text-align: justify;">10 <span class="h4">else</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: justify;">11 <span><img width="1" height="16" alt="image" src="cmsc351/Image_262.png"/></span><span class="s33"> </span><span class="p">k=q-p+1</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: justify;">12 <span class="h4">end</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;text-align: justify;">13 <span class="p">returnq,A[q];</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;text-align: justify;">14 <span class="h4">end</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">Take the list and find some approximate median, partition with this approximate median (q), then look on the left or right side depending on how k compares to our partition.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark179">Analyzing the recurrence</a><a name="bookmark184">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">It sounds like selection should be a very important problem, but in real life it doesn’t come up very much.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark180">Lower Bound</a><a name="bookmark185">‌</a></h4><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Let’s assume we know the true median, or that our approximate median is good enough.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">T <span class="s9">(</span>n<span class="s9">) = </span>n <span class="s3">− </span><span class="s9">1 + </span>T <span class="s121">(</span><span class="s3">1 </span><u>n</u><u> </u><span class="s27">−</span><span class="s3"> </span><span class="s10">1</span><span class="s9"> </span><span class="s3">1</span><span class="s121">\</span></p><p class="s15" style="text-indent: 0pt;line-height: 8pt;text-align: center;">n</p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_263.png"/></span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 68%;text-align: center;"><span class="s3">≈ </span><span class="s15">T </span>( <span class="s30">2 </span>) + <span class="s15">n </span><span class="s3">− </span>1</p><p class="s3" style="padding-left: 62pt;text-indent: 0pt;line-height: 17pt;text-align: center;">≈ <span class="s9">2</span><span class="s15">n </span>− <span class="s9">1 </span>− <span class="s9">lg </span><span class="s15">n</span></p><p class="s3" style="padding-left: 41pt;text-indent: 0pt;line-height: 17pt;text-align: center;">≈ <span class="s9">2</span><span class="s15">n</span></p><p style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">So if we got really lucky and got the true median we could find the kth element in linear time. As such we have a reasonable assumption for our lower bound. You’ll never do better than 2n comparisons in a real case when you don’t have the perfect median.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark181">Constrained case analysis</a><a name="bookmark186">‌</a></h3><p style="text-indent: 0pt;text-align: left;"><span><img width="5" height="1" alt="image" src="cmsc351/Image_264.png"/></span></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">4</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 4pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Let’s assume that we get a q at the <span class="s40">1 </span>mark, and assume that our k is always on the larger side.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="15" height="1" alt="image" src="cmsc351/Image_265.png"/></span></p><p class="s9" style="padding-top: 8pt;padding-left: 161pt;text-indent: 81pt;line-height: 46%;text-align: left;">3<span class="s15">n T </span>(<span class="s15">n</span>) = <span class="s15">n </span><span class="s3">− </span>1 + <span class="s15">T </span>( <span class="s30">4 </span>)</p><p class="s9" style="padding-top: 2pt;padding-left: 10pt;text-indent: 0pt;line-height: 8pt;text-align: center;">3<span class="s15">n</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="15" height="1" alt="image" src="cmsc351/Image_266.png"/></span></p><p class="s9" style="padding-left: 27pt;text-indent: 0pt;line-height: 67%;text-align: center;">= <span class="s15">T </span>( <span class="s30">4 </span>) + <span class="s15">n </span><span class="s3">− </span>1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_267.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_268.png"/></span></p><p class="s9" style="padding-top: 2pt;padding-left: 62pt;text-indent: 0pt;line-height: 9pt;text-align: center;">3 3 <span class="s16">2</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">For the general fractional partition.</p><p class="s3" style="padding-left: 7pt;text-indent: 0pt;line-height: 64%;text-align: left;">≈ <span class="s9">(</span><span class="s15">n </span>− <span class="s9">1) + ( </span><span class="s30">4 </span><span class="s15">n </span>− <span class="s9">1) + ( </span><span class="s30">4</span></p><p class="s9" style="padding-top: 1pt;padding-left: 32pt;text-indent: 0pt;line-height: 7pt;text-align: left;">1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="43" height="1" alt="image" src="cmsc351/Image_269.png"/></span></p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 67%;text-align: left;">= <span class="s30">1 </span><span class="s3">− </span>3<span class="s15">/</span>4 <span class="s15">n </span><span class="s3">− </span><span class="s15">c </span>log <span class="s15">n</span></p><p class="s3" style="padding-left: 7pt;text-indent: 0pt;text-align: left;">≈ <span class="s9">4</span><span class="s15">n</span></p><p class="s15" style="padding-left: 3pt;text-indent: 0pt;line-height: 15pt;text-align: left;">n <span class="s3">− </span><span class="s9">1) + </span>. . .</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 6pt;text-indent: 0pt;text-align: left;">Absolute worst case q.</p><p class="s15" style="padding-top: 7pt;padding-left: 6pt;text-indent: 0pt;line-height: 17pt;text-align: left;">T <span class="s9">(</span>n<span class="s9">) = </span>n <span class="s3">− </span><span class="s9">1 + </span>T <span class="s9">((1 </span><span class="s3">− </span>r<span class="s9">)</span>n<span class="s9">)</span></p><p class="s9" style="padding-left: 30pt;text-indent: 0pt;line-height: 16pt;text-align: left;">= <span class="s15">T </span>((1 <span class="s3">− </span><span class="s15">r</span>)<span class="s15">n</span>) + <span class="s15">n </span><span class="s3">− </span>1</p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="padding-left: 30pt;text-indent: 0pt;line-height: 17pt;text-align: left;">≈ <span class="s9">(</span><span class="s15">n </span>− <span class="s9">1) + ((1 </span>− <span class="s15">r</span><span class="s9">)</span><span class="s15">n </span>− <span class="s9">1) + ((1 </span>− <span class="s15">r</span><span class="s9">) </span><span class="s15">n </span>− <span class="s9">1) + </span><span class="s15">. . .</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 8pt;text-align: center;">1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="52" height="1" alt="image" src="cmsc351/Image_270.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 30pt;text-indent: 0pt;line-height: 7pt;text-align: left;">= <span class="s15">n c </span>log <span class="s15">n</span></p><p class="s9" style="padding-left: 42pt;text-indent: 0pt;line-height: 9pt;text-align: left;">1 1 + <span class="s15">r</span></p><p class="s9" style="padding-left: 42pt;text-indent: 0pt;line-height: 7pt;text-align: left;">1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_271.png"/></span></p><p class="s3" style="padding-left: 30pt;text-indent: 0pt;line-height: 67%;text-align: left;">≈ <span class="s103">r </span><span class="s15">n</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-top: 7pt;padding-left: 33pt;text-indent: 0pt;line-height: 17pt;text-align: center;">T <span class="s9">(</span>n<span class="s9">) = </span>n <span class="s3">− </span><span class="s9">1 + </span>T <span class="s9">(</span>n <span class="s3">− </span><span class="s9">1)</span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 15pt;text-align: center;">= (<span class="s15">n </span><span class="s3">− </span>1) + (<span class="s15">n </span><span class="s3">− </span>2) + (<span class="s15">n </span><span class="s3">− </span>3) + <span class="s15">. . .</span></p><p class="s10" style="padding-left: 21pt;text-indent: 0pt;line-height: 77%;text-align: center;"><span class="s25">= </span>(<span class="s26">n </span><span class="s27">− </span>1)<span class="s26">n</span></p><p class="s9" style="text-indent: 0pt;line-height: 9pt;text-align: center;">2</p><p class="s86" style="padding-left: 6pt;text-indent: 0pt;line-height: 8pt;text-align: center;">n<span class="s14">2</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="14" height="1" alt="image" src="cmsc351/Image_272.png"/></span></p><p class="s3" style="padding-left: 62pt;text-indent: 0pt;line-height: 69%;text-align: center;">≈ <span class="s30">2</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-top: 5pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark182">Average case Analysis</a><a name="bookmark187">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Sum over all possible pivots and let’s assume you always end up on the bigger side, for the pessimistic view. So we get the probabilistic analysis.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s22" style="padding-top: 2pt;text-indent: 0pt;text-align: left;"> <span class="s13"> </span><span class="s28">1</span><span class="s3">− · − −</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 3pt;text-indent: 0pt;text-align: center;">n</p><p class="s15" style="padding-top: 1pt;padding-left: 120pt;text-indent: 0pt;line-height: 9pt;text-align: left;">T <span class="s9">(</span>n<span class="s9">) = </span>n <span class="s9">1 + </span>T <span class="s9">(max(</span>q <span class="s9">1</span>, n q<span class="s9">))</span></p><p class="s15" style="text-indent: 0pt;line-height: 6pt;text-align: center;">n</p><p class="s11" style="padding-left: 62pt;text-indent: 0pt;line-height: 8pt;text-align: center;">q<span class="s14">=1</span></p><p class="s11" style="padding-left: 165pt;text-indent: 0pt;line-height: 4pt;text-align: left;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 2pt;padding-bottom: 2pt;padding-left: 144pt;text-indent: 0pt;text-align: left;">= <u>2</u><span class="s23"> </span><span class="s15">T </span>(<span class="s15">q</span>)</p><p class="s64" style="text-indent: 0pt;line-height: 4pt;text-align: left;">n</p><p class="s62" style="text-indent: 0pt;line-height: 6pt;text-align: left;">2</p><p style="padding-left: 170pt;text-indent: 0pt;line-height: 10pt;text-align: left;"/><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s64" style="text-indent: 0pt;line-height: 4pt;text-align: left;">n</p><p class="s62" style="text-indent: 0pt;line-height: 6pt;text-align: left;">2</p><p style="padding-left: 170pt;text-indent: 0pt;line-height: 10pt;text-align: left;"/><p class="s15" style="padding-top: 2pt;padding-left: 141pt;text-indent: 0pt;text-align: left;"><span class="p">Constructive Induction, guess the algorithm is linear Guess </span>T <span class="s9">(</span>n<span class="s9">) </span><span class="s3">≤ </span>an</p><p class="s13" style="padding-top: 1pt;text-indent: 0pt;text-align: left;"> <span class="s42">2</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 15pt;text-align: left;">= <span class="s15">n </span><span class="s3">− </span>1 + <span class="s15">aq</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 1pt;padding-left: 62pt;text-indent: 0pt;text-align: center;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s15" style="padding-top: 4pt;padding-left: 62pt;text-indent: 0pt;line-height: 13pt;text-align: center;">n <span class="s106">n</span></p><p class="s62" style="text-indent: 0pt;line-height: 6pt;text-align: center;">2</p><p class="s9" style="padding-top: 1pt;text-indent: 0pt;text-align: left;">= <span class="s15">n </span><span class="s3">− </span>1 + <u>2</u><span class="s26">a</span><span class="s192"> </span><span class="s15">q</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 7pt;text-indent: 0pt;text-align: center;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s15" style="padding-top: 4pt;text-indent: 0pt;text-align: right;">n</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s193" style="padding-top: 1pt;text-indent: 0pt;line-height: 12pt;text-align: right;"> <span class="s155"> </span><span class="s13"></span><span class="s11">n</span><span class="s24">−</span><span class="s14">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s64" style="padding-left: 8pt;text-indent: 0pt;line-height: 6pt;text-align: left;">n</p><p class="s77" style="text-indent: 0pt;line-height: 5pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s62" style="text-indent: 0pt;line-height: 5pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s24" style="padding-left: 14pt;text-indent: 0pt;line-height: 12pt;text-align: left;">−<span class="s14">1 </span><span class="s194"></span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"></p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-top: 1pt;text-indent: 0pt;line-height: 9pt;text-align: right;">2<span class="s15">a</span></p><p class="s9" style="text-indent: 0pt;line-height: 7pt;text-align: right;">= <span class="s15">q</span></p><p class="s15" style="text-indent: 0pt;line-height: 7pt;text-align: right;">n</p><p class="s11" style="text-indent: 0pt;line-height: 6pt;text-align: right;">q<span class="s14">=1</span></p><p class="s62" style="padding-left: 1pt;text-indent: 0pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="padding-left: 1pt;text-indent: 0pt;line-height: 8pt;text-align: left;">q<span class="s14">=1</span></p><p class="s9" style="padding-top: 5pt;padding-left: 1pt;text-indent: 0pt;text-align: left;"><span class="s26">q</span><span class="s94"></span><span class="s155"> </span><u>+</u> <span class="s15">n </span><span class="s3">− </span>1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="53" height="1" alt="image" src="cmsc351/Image_273.png"/></span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">=</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−</p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 15pt;text-align: left;">+ <span class="s15">n </span><span class="s3">− </span>1</p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 156pt;text-indent: 0pt;text-align: left;"><span class="s10">2</span>a<span class="s153"> </span>n<span class="s10">(</span>n <span class="s27">− </span><span class="s10">1)</span><span class="s9"> </span><span class="s15">n </span><span class="s9">( </span><span class="s15">n </span><span class="s3">− </span><span class="s9">1) </span><span class="s19">7</span></p><p class="s26" style="padding-top: 2pt;padding-left: 156pt;text-indent: 0pt;line-height: 16pt;text-align: left;"><span class="s10">2</span>a<span class="s153"> </span><span class="s15">n</span><span class="s16">2 </span>n<span class="s15"> n</span><span class="s16">2 </span>n<span class="s15"> </span><span class="s19">7</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s195" style="padding-left: 175pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="14" height="1" alt="image" src="cmsc351/Image_274.png"/></span> <span><img width="14" height="1" alt="image" src="cmsc351/Image_275.png"/></span></p><p class="s9" style="padding-left: 144pt;text-indent: 0pt;line-height: 17pt;text-align: left;"><span class="s50">= </span><span class="s15">n </span>2 <span class="s160">− </span>2 <span class="s160">− </span>8 <span class="s50">+ </span>4</p><p class="s15" style="text-indent: 0pt;line-height: 8pt;text-align: right;">an a</p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 15pt;text-align: left;">+ <span class="s15">n </span><span class="s3">− </span>1</p><p style="text-indent: 0pt;text-align: left;"><span><img width="15" height="1" alt="image" src="cmsc351/Image_276.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_277.png"/></span></p><p class="s9" style="padding-left: 144pt;text-indent: 0pt;line-height: 64%;text-align: left;">= <span class="s15">an </span><span class="s3">− </span><span class="s15">a </span><span class="s3">− </span><span class="s30">4 </span>+ <span class="s30">2 </span>+ <span class="s15">n </span><span class="s3">− </span>1</p><p class="s9" style="padding-left: 156pt;text-indent: 0pt;line-height: 8pt;text-align: left;">3 <span class="s15">a</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_278.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_279.png"/></span></p><p class="s9" style="padding-left: 144pt;text-indent: 0pt;line-height: 65%;text-align: left;">= <span class="s30">4 </span><span class="s15">an </span><span class="s3">− </span><span class="s30">2 </span>+ <span class="s15">n </span><span class="s3">− </span>1</p><p class="s9" style="padding-left: 160pt;text-indent: 0pt;line-height: 6pt;text-align: left;">3 <span class="s15">a</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_280.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_281.png"/></span></p><p class="s15" style="padding-left: 144pt;text-indent: 0pt;line-height: 83%;text-align: left;"><span class="s9">= ( </span><span class="s30">4 </span>a <span class="s9">+ 1)</span>n <span class="s3">− </span><span class="s30">2 </span><span class="s3">− </span><span class="s9">1 </span><span class="p">for induction to work </span><span class="s3">≤ </span>an <span class="s178">∴ </span>a <span class="s3">≥ </span><span class="s9">4</span></p><p class="s9" style="padding-left: 120pt;text-indent: 0pt;line-height: 19pt;text-align: left;"><span class="s15">T </span>(<span class="s15">n</span>) <span class="s3">≈ </span>4<span class="s15">n</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p></li><li style="padding-left: 38pt;text-indent: -31pt;text-align: justify;"><h2 style="display: inline;"><a name="bookmark188">Finding Median explicitly during selection</a><a name="bookmark191">‌</a></h2><p style="padding-top: 8pt;padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">Take the numbers and put them into a 2 dimensional grid with 5 rows and n/5 columns.</p><p style="padding-left: 6pt;text-indent: 0pt;text-align: justify;">Computer Memory is a 1 dimensional array, meaning that representing a 2 dimensional array requires a clever trick to access. A[i,j] Represented differently in row major order vs column major order. Column major order A[5(i-1) + j] Without using very specific pseudocode, let’s look theoretically at how something like this algorithm might work at a very high level.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">5</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">1 </span>Put items into 5x <span class="s84">n</span><span class="s11"> </span>grid</p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">2 <span class="p">Bubble Sort</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">3 <span class="s141">// Find median of each column. 10*n/5 = 2n comparisons.</span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">4 </span><span class="p">Find the median of these medians recursively. </span><span class="s141">// smaller subset of elements it should take </span>T <span class="s9">(</span>n/<span class="s9">5)</span></p><p class="s141" style="padding-left: 36pt;text-indent: 0pt;line-height: 12pt;text-align: left;">comparisons.</p><p class="s17" style="padding-left: 36pt;text-indent: -24pt;line-height: 93%;text-align: left;">5 <span class="p">Move columns with small medians left and columns with large medians right. </span><span class="s141">// This puts the median of medians in the middle element.</span></p><p class="s141" style="padding-left: 12pt;text-indent: 0pt;line-height: 15pt;text-align: left;"><span class="s17">6 </span><span class="p">Partition using the median of medians. </span>// Partitioning takes <span class="s15">n </span><span class="s3">− </span><span class="s9">1 </span>comparisons. <span class="s75"> </span></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">10</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;"><span class="s17">7 </span><span class="p">Recursively select on correct side, knowing what we know about median of medians. </span><span class="s141">// Takes </span>T <span class="s9">( </span><span class="s16">7</span>n <span class="s9">)</span></p><p class="s141" style="padding-left: 36pt;text-indent: 0pt;line-height: 11pt;text-align: left;">comparisons.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s178" style="padding-left: 11pt;text-indent: 0pt;line-height: 78%;text-align: justify;">D D D D D D D D D D D D D D D D D D D D D D D D D D</p><p class="s178" style="padding-left: 11pt;text-indent: 0pt;line-height: 78%;text-align: justify;">• • • • • • <span class="s15">M </span>• • • • • • D D D D D D D D D D D D D D D D D D D D D D D D D D</p><h3 style="padding-top: 12pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark189">Worst Case analysis</a><a name="bookmark192">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">About 25% of elements are guaranteed to be smaller, and about 25% are guaranteed to be bigger than the median of medians. The exact value is<u> </u><span class="s57">3</span><span class="s14"> </span><span class="s15">n </span>This gives us an upper bound on the size of a recursive call to partition at<u> </u><span class="s57">7</span><span class="s14"> </span><span class="s15">n</span>,</p><p class="s14" style="padding-left: 137pt;text-indent: 0pt;line-height: 2pt;text-align: left;">10 10</p><p style="padding-left: 6pt;text-indent: 0pt;line-height: 11pt;text-align: left;">which is the remaining number of elements to recurse over.</p><p class="s15" style="text-indent: 0pt;line-height: 10pt;text-align: left;">n</p><p style="text-indent: 0pt;text-align: left;"/><p class="s58" style="padding-top: 3pt;padding-bottom: 3pt;padding-left: 56pt;text-indent: 0pt;line-height: 75%;text-align: left;"> <span class="s57">3</span><span class="s14"> 10</span></p><p style="padding-left: 6pt;text-indent: 0pt;line-height: 3pt;text-align: left;"><span><img width="152" height="4" alt="image" src="cmsc351/Image_282.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 6pt;text-indent: 0pt;text-align: left;"><span><img width="562" height="38" alt="image" src="cmsc351/Image_283.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="text-indent: 0pt;text-align: left;"><span><img width="398" height="4" alt="image" src="cmsc351/Image_284.png"/></span></p><p class="s14" style="text-indent: 0pt;line-height: 7pt;text-align: left;">10</p><p style="text-indent: 0pt;text-align: left;"/><p class="s196" style="padding-left: 169pt;text-indent: 0pt;text-align: left;"> <span class="s57">7</span><span class="s14"> </span><span class="s15">n </span><span class="s3">→ </span><span class="p">remaining number of elements to recurse over</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-top: 3pt;padding-left: 170pt;text-indent: 0pt;line-height: 8pt;text-align: left;">n <span class="s9">7</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_285.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_286.png"/></span></p><p class="s9" style="padding-left: 100pt;text-indent: 0pt;line-height: 64%;text-align: left;"><span class="s15">T </span>(<span class="s15">n</span>) <span class="s3">≤ </span>2<span class="s15">n </span>+ <span class="s15">T </span>( <span class="s30">5 </span>) + <span class="s15">T </span>( <span class="s30">10 </span><span class="s15">n</span>) + <span class="s15">n </span><span class="s3">− </span>1</p><p class="s15" style="padding-left: 147pt;text-indent: 0pt;line-height: 7pt;text-align: left;">n <span class="s9">7</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_287.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_288.png"/></span></p><p class="s9" style="padding-left: 124pt;text-indent: 0pt;line-height: 78%;text-align: left;">= <span class="s15">T </span>( <span class="s30">5 </span>) + <span class="s15">T </span>( <span class="s30">10 </span><span class="s15">n</span>) + 3<span class="s15">n </span><span class="s3">− </span>1 <span class="p">Constructive induction, guess </span><span class="s15">T </span>(<span class="s15">n</span>) <span class="s3">≤ </span><span class="s15">an</span></p><p class="s15" style="padding-left: 141pt;text-indent: 0pt;line-height: 8pt;text-align: left;">n <span class="s9">7</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="8" height="1" alt="image" src="cmsc351/Image_289.png"/></span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="13" height="1" alt="image" src="cmsc351/Image_290.png"/></span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;">(</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 1pt;padding-left: 124pt;text-indent: 0pt;line-height: 36%;text-align: left;"><span class="s3">≤ </span>a <span class="s30">5 </span><span class="s9">+ </span>an <span class="s30">10 </span><span class="s9">+ 3</span>n <span class="s3">− </span><span class="s9">1</span></p><p class="s25" style="padding-top: 6pt;padding-left: 143pt;text-indent: -19pt;line-height: 76%;text-align: right;">=<u> 9</u><span class="s9"> 10</span></p><p class="s9" style="padding-left: 1pt;text-indent: 0pt;text-align: left;">+ 3<span class="s121">\</span><span class="s13"> </span><span class="s15">n </span><span class="s3">− </span>1</p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">10</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-top: 2pt;padding-left: 121pt;text-indent: 0pt;text-align: left;"><span class="p">need </span>an <span class="s9">=</span><span class="s3">⇒ </span>need<u> </u><span class="s10">9</span><span class="s9"> </span>a <span class="s9">+ 3 </span><span class="s3">≤ </span>a <span class="s178">∴ </span>a <span class="s3">≥ </span><span class="s9">30</span></p><p class="s9" style="padding-left: 91pt;text-indent: 0pt;line-height: 19pt;text-align: left;"><span class="s178">∴ </span><span class="s15">T </span>(<span class="s15">n</span>) <span class="s3">≤ </span>30<span class="s15">n</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">∼</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: justify;"><span class="p">Median is doable in linear time, but 30 is a very large coefficient. Compare it to quick sort at </span>n <span class="s9">lg </span>n<span class="p">,n must be </span><span class="s9">2</span><span class="s16">30</span></p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">for our linear median selection to be better.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark190">Theory</a><a name="bookmark193">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Say the upper bound, as some researchers claim to have found, that the upper bound on median selection is 3n.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;text-align: center;">2<span class="s15">n < T </span>(<span class="s15">n</span>) <span class="s15">< n</span>3<span class="s15">n</span></p><p class="s9" style="padding-left: 62pt;text-indent: 0pt;line-height: 18pt;text-align: center;">(2 + <span class="s15">ε</span>)<span class="s15">n </span>(3 <span class="s3">− </span><span class="s15">δ</span>)<span class="s15">n</span></p><p class="s9" style="text-indent: 0pt;line-height: 6pt;text-align: center;">5</p><p style="text-indent: 0pt;text-align: left;"><span><img width="7" height="1" alt="image" src="cmsc351/Image_291.png"/></span></p><p class="s15" style="padding-left: 62pt;text-indent: 0pt;line-height: 67%;text-align: center;">T <span class="s9">(</span>n<span class="s9">) </span><span class="s3">≈ </span><span class="s30">2 </span>n</p><p style="text-indent: 0pt;text-align: left;"><br/></p></li><li style="padding-top: 11pt;padding-left: 38pt;text-indent: -31pt;text-align: justify;"><h2 style="display: inline;"><a name="bookmark194">Graph Algorithms</a><a name="bookmark207">‌</a></h2><p style="padding-top: 8pt;padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">Graph description. Can be represented as an adjacency list or adjacency matrix.</p><p style="padding-left: 6pt;text-indent: 0pt;text-align: justify;">Undirected graph adjacency list representation is a bit awkward because it double counts shared edges. Altering an edge on one vertex requires altering the edge on its partner too. Requiring that you traverse both lists. One awkward way to alleviate this is to keep extra pointers between the list elements in shared edges.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark195">Memory Usage</a><a name="bookmark208">‌</a></h3><p class="s9" style="padding-top: 5pt;padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: justify;"><span class="p">Matrix, where n = number of vertices, Memory usage = </span>Θ(<span class="s15">n</span><span class="s16">2</span>)</p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: justify;"><span class="p">List, where m = number of edges, Memory usage = </span>Θ(<span class="s15">m </span>+ <span class="s15">n</span>)</p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">How big can m be? M can be as large as <span class="s15">n</span><span class="s16">2</span>, but will probably be smaller.</p><p style="text-indent: 0pt;text-align: left;"><span><img width="43" height="1" alt="image" src="cmsc351/Image_292.png"/></span></p><p class="s74" style="text-indent: 0pt;line-height: 9pt;text-align: left;">word size</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-left: 6pt;text-indent: 0pt;line-height: 14pt;text-align: left;">You could also use a bit matrix of size <span class="s123">n</span><span class="s98">2 </span>.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-top: 5pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark196">Edge Lookup</a><a name="bookmark209">‌</a></h3><p class="s9" style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">List: </span>Θ(<span class="s15">n</span>) <span class="p">Matrix: </span>Θ(1)</p><h3 style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark197">List all Edges</a><a name="bookmark210">‌</a></h3><p class="s9" style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;line-height: 93%;text-align: left;"><span class="p">List, Go down each index, then traverse each list. Amortized analysis is to visit n elements. </span>Θ(<span class="s15">m </span>+ <span class="s15">n</span>)<span class="p">. Matrix, Go across each row, looking at all the 0s, even when you don’t care about them. </span>Θ(<span class="s15">n</span><span class="s16">2</span>)<span class="p">.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark198">Take aways</a><a name="bookmark211">‌</a></h3><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Typically we want to use the Adjacency list representation, because it’s linear for in the average case.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark199">Changing the number of nodes</a><a name="bookmark212">‌</a></h3><h4 style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark200">Adding Nodes</a><a name="bookmark213">‌</a></h4><p style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Add dummy values that you can fill later to the next power of 2. If you have 11 nodes build a matrix with 16 columns and just read the first 11, when a new node is added just use the dummy space, when you reach 17 you need to copy the old matrix into the new one of size 32.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark201">Removing Nodes</a><a name="bookmark214">‌</a></h4><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Shrink the array in a way similar to adding a node.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark202">Depth First Search</a><a name="bookmark215">‌</a></h3><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">1 <span class="p">Mark v at visited;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">2 <span class="p">for all v such that (u,v) is an edge and v has not been visited ;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">3 <span class="p">DFS v;</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-left: 6pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="p">Adjacency Matrix: </span>O<span class="s9">(</span>n<span class="s16">2</span><span class="s9">)</span></p><p class="s15" style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="p">Adjacency List: </span>O<span class="s9">(</span>n <span class="s9">+ </span>m<span class="s9">)</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark203">Applications</a><a name="bookmark216">‌</a></h4><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Identify Connected Components.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark204">Breadth First Search</a><a name="bookmark217">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">While depth first search uses a recursive call, or a stack (which are naturally similar in modern machines) BFS uses a queue, which while similar in order analysis for most things is not naturally represented in a stack based machine. Does have some nice applications, like shortest distance algorithms.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark205">Identifying Connected Components</a><a name="bookmark218">‌</a></h3><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">A graph is connected if there is a path from every vertex to every other vertex in the graph.</p><p style="padding-top: 3pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">A connected component is a connected subgraph, or a connection of such components.</p><p class="s140" style="padding-top: 1pt;padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">1 </span><span class="h4">Function </span>Component(<span class="s18">G</span>)<span class="h4">is</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="163" alt="image" src="cmsc351/Image_293.png"/></span></p><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 15pt;text-align: left;"><span class="s17">2 </span><span class="h4">for </span><span class="s18">all </span>x <span class="s27">∈ </span>V <span class="s10">[</span>G<span class="s10">]</span><span class="s9"> </span><span class="h4">do</span></p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 16pt;text-align: left;"><span class="s17">3 </span><span><img width="1" height="32" alt="image" src="cmsc351/Image_294.png"/></span><span class="s33"> </span>visited<span class="s9">[</span>x<span class="s9">] </span><span class="s3">← </span>F alse<span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 10pt;text-align: left;">4 <span class="s15">t </span><span class="s3">← </span><span class="s9">0</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 10pt;text-align: left;">5 <span class="h4">end</span></p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">∈ </p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">6 </span><span class="h4">for </span><span class="s18">all </span>x<span class="s15"> </span>V <span class="s10">[</span>G<span class="s10">]</span><span class="s9"> </span><span class="h4">do</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="65" alt="image" src="cmsc351/Image_295.png"/></span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">7 </span>if <span class="s18">not visited[x]</span><span class="p"> </span>then</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="32" alt="image" src="cmsc351/Image_296.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">8 <span class="s15">t t </span><span class="s9">+ 1</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">9 <span class="s141">Compvisit </span><span class="p">[x];</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">10 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">11 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">12 <span class="h4">end</span></p><p class="s140" style="padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">13 </span><span class="h4">Function </span>Compvisit(<span class="s18">x</span>)<span class="h4">is</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="113" alt="image" src="cmsc351/Image_297.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">14 </span>visited<span class="s9">[</span>x<span class="s9">] </span>T rue<span class="p">;</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">15 </span>CompN um<span class="s9">[</span>x<span class="s9">] </span>t<span class="p">;</span></p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">∈ </p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">16 </span><span class="h4">for </span><span class="s18">all </span>y<span class="s15"> </span>adj<span class="s10">[</span>x<span class="s10">]</span><span class="s9"> </span><span class="h4">do</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="48" alt="image" src="cmsc351/Image_298.png"/></span></p><h4 style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">17 </span>if <span class="s18">not visited[y]</span><span class="p"> </span>then</h4><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 13pt;text-align: left;">18 <span><img width="1" height="16" alt="image" src="cmsc351/Image_299.png"/></span><span class="s33"> </span><span class="p">Compvisit[y];</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">19 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">20 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">21 <span class="h4">end</span></p><h4 style="padding-left: 168pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Algorithm 12: <span class="p">Connected Component</span></h4><p class="s15" style="padding-top: 1pt;padding-left: 6pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="p">Adjacency Matrix: </span>O<span class="s9">(</span>n<span class="s16">2</span><span class="s9">)</span></p><p class="s15" style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="p">Adjacency List: </span>O<span class="s9">(</span>n <span class="s9">+ </span>m<span class="s9">)</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark206">Bridges of Köningsberg</a><a name="bookmark219">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;"><span class="h4">Theorem 21.1 </span>(Eulerian Cycle 1736)<span class="h4">. </span>An undirected, (connected) graph <span class="s15">G </span><span class="s9">= (</span><span class="s15">v, e</span><span class="s9">) </span>has an Eulerian Cycle if and only if every vertex is connected and every vertex has an even degree (number of incoming and outgoing edges, with loops counted twice).</p><p style="text-indent: 0pt;text-align: left;"><br/></p></li><li style="padding-left: 38pt;text-indent: -31pt;text-align: justify;"><h2 style="display: inline;"><a name="bookmark220">Trees</a><a name="bookmark226">‌</a></h2><p style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Created by S. Jaladanki</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark221">Definitions</a><a name="bookmark227">‌</a></h3><h4 style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Definition 22.1 <span class="p">(Tree)</span>. <span class="p">An undirected and connected acyclic graph.</span></h4><ul id="l13"><li style="padding-top: 7pt;padding-left: 7pt;text-indent: 14pt;text-align: left;"><p style="display: inline;">If an edge is added between two vertices in a tree, a cycle is created</p></li><li style="padding-left: 7pt;text-indent: 14pt;line-height: 123%;text-align: left;"><p style="display: inline;"><a href="https://en.wikipedia.org/wiki/Minimum_spanning_tree" style=" color: black; font-family:"Book Antiqua", serif; font-style: normal; font-weight: normal; text-decoration: none; font-size: 10pt;" target="_blank">If any edge is removed from this cycle, we recreate a tree Source: </a><a href="https://en.wikipedia.org/wiki/Minimum_spanning_tree" class="s4" target="_blank">https://en.wikipedia.org/wiki/Minimum_spanning_tree</a></p><h4 style="padding-top: 4pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Definition 22.2 <span class="p">(Spanning Tree)</span>. <span class="p">A subset of edges that form a tree and contains every vertex in the graph. It does not have cycles.</span></h4><h4 style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Definition 22.3 <span class="p">(Minimum Spanning Tree (MST))</span>. <span class="p">A spanning tree that has the lowest possible sum of edge weights</span></h4></li><li style="padding-top: 7pt;padding-left: 7pt;text-indent: 14pt;text-align: left;"><p class="s15" style="display: inline;">m <span class="s9">= </span>n <span class="s3">− </span><span class="s9">1 </span><span class="p">There are m edges in a spanning tree in a graph with n vertices</span></p><ul id="l14"><li style="padding-top: 3pt;padding-left: 53pt;text-indent: -10pt;text-align: left;"><p style="display: inline;">For example, a graph with 2 vertices will have a spanning tree consisting of one edge which connects the two vertices</p><h3 style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark222">Minimum Spanning Tree Algorithms</a><a name="bookmark228">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">There are different approaches to form the Minimum Spanning Tree of a graph, and two important algorithms are Kruskal’s Algorithm and Prim’s Algorithm.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark223">Kruskal’s Algorithm</a><a name="bookmark229">‌</a></h4><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">In this algorithm, we go through the graph edges one at a time, from smallest edge weight to largest edge weight, and add it to a Minimum Spanning Tree (MST) as long as a cycle is not created. If the edge to add would create a cycle in the MST, it is not added and the next edge is examined. We can stop when we have n-1 edges in the MST.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">| | ≤ | | ≤ | |</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">1 </span><span class="p">Sort edges by weight so that </span>e<span class="s16">1 </span>e<span class="s16">2 </span>em <span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">2 <span class="s141">// Assign empty tree</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">3 <span class="s15">T </span><span class="s9">0</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">4 <span class="s141">// m is the edges in a graph</span></p><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">5 </span><span class="h4">for </span>i <span class="s10">= 1 </span><span class="s191">to </span>m<span class="s15"> </span><span class="h4">do</span></p><p style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;"><span class="s17">6 </span><span><img width="1" height="16" alt="image" src="cmsc351/Image_300.png"/></span><span class="s33"> </span>Put edge <span class="s15">i </span>into <span class="s15">T </span>if cycle is not made;</p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">7 <span class="h4">end</span></p><h4 style="padding-left: 174pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Algorithm 13: <span class="p">Kruskal’s Algorithm</span></h4><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark224">Prim’s Algorithm</a><a name="bookmark230">‌</a></h4><p style="padding-top: 6pt;padding-left: 5pt;text-indent: 1pt;text-align: justify;">In this algorithm, we can start at any vertex and grow the Minimum Spanning Tree (MST). We take the cheapest (smallest) edge coming off the growing tree that leads to a new vertex and add it to the MST. This process is repeated until a MST is made.</p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">∈ </p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">1 </span><span class="h4">for </span><span class="s18">all </span>x<span class="s15"> </span>V <span class="s10">[</span>G<span class="s10">]</span><span class="s9"> </span><span class="h4">do</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="64" alt="image" src="cmsc351/Image_301.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">∞</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">2 <span class="s141">// Distances to all vertices initialized to</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">← ∞</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">3 </span>D<span class="s9">[</span>x<span class="s9">] </span><span class="p">;</span></p><p class="s141" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;"><span class="s17">4 </span>// Predecessors (<span class="s9">Π</span>) to all vertices initialized to NIL</p><p class="s9" style="padding-left: 12pt;text-indent: 0pt;line-height: 16pt;text-align: left;"><span class="s17">5 </span>Π[<span class="s15">x</span>] <span class="s3">← </span><span class="s15">N IL</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 9pt;text-align: left;">6 <span class="h4">end</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">7 </span>Q V <span class="s9">[</span>G<span class="s9">] </span><span class="s141">// Q will hold the vertices which haven’t been checked off yet or "outside" vertices</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">8 <span class="s141">// Distance to start vertex (a) assigned 0 so it is first vertex popped from Q</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">9 </span>D<span class="s9">[</span>a<span class="s9">] 0</span><span class="p">;</span></p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">/<span class="s3"> </span>∅</p><p style="text-indent: 0pt;text-align: left;"/><h4 style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;"><span class="s17">10 </span>while <span class="s26">Q </span><span class="s10">=</span><span class="s9"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="146" alt="image" src="cmsc351/Image_302.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">11 <span class="s15">x </span><span class="p">Pop-minimum[Q];</span></p><h4 style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;"><span class="s17">12 </span>for <span class="s18">all y adjacent to x in Q</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="97" alt="image" src="cmsc351/Image_303.png"/></span></p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">∈ </p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;"><span class="s17">13 </span><span class="h4">if </span>y<span class="s15"> </span>Q <span class="s18">and </span>W <span class="s10">[</span>x, y<span class="s10">] </span>< D<span class="s10">[</span>y<span class="s10">]</span><span class="s9"> </span><span class="h4">then</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="64" alt="image" src="cmsc351/Image_304.png"/></span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">14 <span class="s141">// W[x,y] is the weight of edge x,y</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: justify;">15 <span class="s141">// Distance and predecessor to new vertex updated</span></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 14pt;text-align: justify;"><span class="s17">16 </span>D<span class="s9">[</span>y<span class="s9">] </span><span class="s3">← </span>W <span class="s9">[</span>x, y<span class="s9">]</span><span class="p">;</span></p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 14pt;text-align: justify;"><span class="s17">17 </span>Π[<span class="s15">y</span>] <span class="s3">← </span><span class="s15">x</span><span class="p">;</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 10pt;text-align: justify;">18 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">19 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: justify;">20 <span class="h4">end</span></p><h4 style="padding-left: 172pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Algorithm 14: <span class="p">Prim’s Algorithm</span></h4><p style="padding-top: 5pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">This algorithm is nearly identical to Dijkstra’s Algorithm. One important difference between these two is that Prim’s adds the vertex closest to the current tree and Dijkstra’s adds the vertex closest to the source vertex.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 6pt;text-indent: 0pt;text-align: left;">The implementation details are similar to Dijkstra’s Algorithm.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark225">Proof for Kruskal’s and Prim’s Algorithms</a><a name="bookmark231">‌</a></h4><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">The proof for Kruskal’s and Prim’s Algorithms, which are greedy algorithms, is a proof by contradiction. Let’s imagine that we have a partially formed MST and that this MST has been made by adding cheapest edges to the tree. On the other side of an imaginary boundary line, there are the remaining vertices which need to be added to the MST.</p><p style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Statement: The cheapest edge to cross the boundary is in the MST.</p><p style="padding-left: 6pt;text-indent: 0pt;text-align: justify;">Let’s say we just added the cheapest edge (1) to cross the boundary to the MST. If this edge (1) were then removed and then replaced with another edge (2) that also crosses the boundary, then we have a contradiction because the new edge (2) is not the cheapest edge to cross the boundary because the old edge (1) was already the cheapest. Therefore, we would no longer have a MST with the new edge (2).</p><p style="text-indent: 0pt;text-align: left;"><br/></p></li></ul></li></ul></li><li style="padding-left: 38pt;text-indent: -31pt;text-align: justify;"><h2 style="display: inline;"><a name="bookmark232">Shortest Path Algorithms</a><a name="bookmark236">‌</a></h2><h4 style="padding-top: 8pt;padding-left: 6pt;text-indent: 0pt;text-align: justify;">Types</h4><ul id="l15"><li style="padding-top: 5pt;padding-left: 31pt;text-indent: -10pt;text-align: left;"><p style="display: inline;">Single source, Single sink.</p><ul id="l16"><li style="padding-top: 2pt;padding-left: 53pt;text-indent: -10pt;text-align: left;"><p style="display: inline;">Ex. What is the best route from site A to site B?</p></li></ul></li><li style="padding-top: 4pt;padding-left: 31pt;text-indent: -10pt;text-align: left;"><p style="display: inline;">All Pairs.</p><ul id="l17"><li style="padding-top: 2pt;padding-left: 53pt;text-indent: -10pt;text-align: left;"><p style="display: inline;">Ex. What is the shortest route between every pair of cities?</p></li></ul></li><li style="padding-top: 4pt;padding-left: 31pt;text-indent: -10pt;text-align: left;"><p style="display: inline;">Single source.</p><ul id="l18"><li style="padding-top: 2pt;padding-left: 53pt;text-indent: -10pt;text-align: left;"><p style="display: inline;">Ex. What is the shortest distance from A to other locations?</p><p style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">It’s very hard to solve the Single source, single sink problem without also solving the single source problem for every node along the way. Same is true for All pairs.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark233">Dijkstra’s Algorithm</a><a name="bookmark237">‌</a></h3><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">∈ </p><p style="text-indent: 0pt;text-align: left;"/><p class="s26" style="padding-top: 8pt;padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">1 </span><span class="h4">for </span><span class="s18">all </span>x<span class="s15"> </span>V <span class="s10">[</span>G<span class="s10">]</span><span class="s9"> </span><span class="h4">do</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="48" alt="image" src="cmsc351/Image_305.png"/></span></p><p class="s9" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;"><span class="s17">2 </span><span class="s141">// </span>Θ(<span class="s15">n</span>)</p><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 14pt;text-align: left;"><span class="s17">3 </span>D<span class="s9">[</span>x<span class="s9">] </span><span class="s3">← ∞</span><span class="p">;</span></p><p class="s9" style="padding-left: 12pt;text-indent: 0pt;line-height: 14pt;text-align: left;"><span class="s17">4 </span>Π[<span class="s15">x</span>] <span class="s3">← </span><span class="s15">N IL</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 9pt;text-align: left;">5 <span class="h4">end</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">6 </span>Q V <span class="s9">[</span>G<span class="s9">] </span><span class="s141">// Q will hold the vertices which haven’t been checked off yet</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">7 </span>D<span class="s9">[</span>a<span class="s9">] 0</span><span class="p">;</span></p><p class="s27" style="text-indent: 0pt;line-height: 15pt;text-align: left;">/<span class="s3"> </span>∅</p><p style="text-indent: 0pt;text-align: left;"/><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">8 </span>while <span class="s26">Q </span><span class="s10">=</span><span class="s9"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="162" alt="image" src="cmsc351/Image_306.png"/></span></p><p class="s9" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">9 </span><span class="s141">// </span>Θ(<span class="s15">n</span>)</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">10 <span class="s15">x </span><span class="p">Pop-minimum[Q];</span></p><h4 style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;"><span class="s17">11 </span>for <span class="s18">all y adjacent to x in Q</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="97" alt="image" src="cmsc351/Image_307.png"/></span></p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;"><span class="s17">12 </span><span class="s141">// Depends on implementation. Can be adjacency matrix, checkable in </span>Θ(<span class="s15">n</span>)</p><p class="s26" style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;"><span class="s17">13 </span><span class="h4">if </span>D<span class="s10">[</span>x<span class="s10">] + </span>W <span class="s10">[</span>x, y<span class="s10">] </span>< D<span class="s10">[</span>y<span class="s10">]</span><span class="s9"> </span><span class="h4">then</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="48" alt="image" src="cmsc351/Image_308.png"/></span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: justify;">14 <span class="s141">// W[x,y] is the weight of edge x,y</span></p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 14pt;text-align: justify;"><span class="s17">15 </span>D<span class="s9">[</span>y<span class="s9">] </span><span class="s3">← </span>D<span class="s9">[</span>x<span class="s9">] + </span>W <span class="s9">[</span>x, y<span class="s9">]</span><span class="p">;</span></p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 14pt;text-align: justify;"><span class="s17">16 </span>Π[<span class="s15">y</span>] <span class="s3">← </span><span class="s15">x</span><span class="p">;</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 10pt;text-align: justify;">17 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">18 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">19 <span class="h4">end</span></p><p style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">This bears a similarity to Breadth First Search. From the source, you reach the vertices separated by 1 edge first, then those separated by 2 edges, then 3, etc. This forms an expanding shell of visited nodes with known shortest distance. We have connections to edges outside the shell, with known edge weights. Since we are picking the smallest such edge, the BFS-like process guarantees that you determine the shortest path to that vertex.</p><p style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">This only works when you have non-negative weight edges.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark234">Correctness Proof</a><a name="bookmark238">‌</a></h4><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">Base case: Nothing is in the circle, except the source vertex with distance 0.</p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">Inductive Step: Remove smallest edge weight from consideration and update connecting vertices if smaller.</p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">Since you know the shortest path to everything in the circle, the available path to the next shortest edge is guaranteed to be the shortest path to that vertex.</p><h4 style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark235">Implementation details</a><a name="bookmark239">‌</a></h4><p class="s9" style="padding-top: 7pt;padding-left: 6pt;text-indent: 0pt;text-align: justify;"><span class="p">Create Q as array. Let Q hold 1’s for vertices that haven’t been eliminated yet, and 0’s otherwise. Naive approach is to travel Q looking for 1, lookup weight in D and track smallest value. If implemented with Adjacency Matrix, the whole thing done in </span>Θ(<span class="s15">n</span><span class="s16">2</span>)<span class="p">.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">| |</p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><span class="p">The alternative is to use a priority queue / heap for Q, removing the smallest value. This necessitates some extra heap functions to grab an arbitrary node in the heap and change its weight. That lets you pop from the heap in logarithmic time. There’s an additional requirement to visit </span><span class="s15">adj</span>(<span class="s15">x</span>) <span class="p">additional vertices, and update them with our heap manipulation function to update weight, which is an additional </span>Θ(lg <span class="s15">n</span>)<span class="p">. Since Dijkstra’s does this for every</span></p><p class="s9" style="padding-left: 7pt;text-indent: 0pt;line-height: 17pt;text-align: left;"><span class="p">element the running time is </span>Θ(<span class="s15">m </span><span class="s3">· </span>lg <span class="s15">n</span>)<span class="p">.</span></p><p class="s15" style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">So if your graph is dense it’s better to use the Adjacency Matrix algorithm, which is quadratic in the number of vertices. If your graph is sparse it’s better to use the </span>m <span class="s9">log </span>n <span class="p">algorithm with a priority queue.</span></p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Of course in reality the quadratic, Adj. Matrix algorithm is usually better at the low level because of spatial locality.</p><p style="text-indent: 0pt;text-align: left;"><br/></p></li></ul></li></ul></li><li style="padding-left: 38pt;text-indent: -31pt;text-align: left;"><h2 style="display: inline;"><a name="bookmark240">NP-Completeness</a><a name="bookmark250">‌</a></h2><p style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Goal is to separate problems easy to solve from those hard to solve. Loosely speaking easy means polynomial time and hard means exponential time.</p><p style="padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;">These are not perfect definitions, in spite of that fact it’s still okay.</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">•</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 9pt;padding-left: 31pt;text-indent: 0pt;text-align: justify;">Nature is kind to us. Natural problems that are polynomial time tend to have low degree. Not a theorem, just an empirical statement.</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">•</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 8pt;padding-left: 31pt;text-indent: 0pt;text-align: justify;">We don’t really know what a computer is. Real world computers have memory hierarchy and variable running times, there’s concurrency as well. All models are equivalent up to polynomial time. One exception is quantum computers, but not really proven in reality.</p><ul id="l19"><li style="padding-top: 5pt;padding-left: 31pt;text-indent: -10pt;text-align: left;"><p style="display: inline;">Polynomials are closed under addition, multiplication, and composition.</p><h3 style="padding-top: 9pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;"><a name="bookmark241">Decision Problem Theory</a><a name="bookmark251">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">Decision problems are yes/no questions.</p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">Does a graph have an Eulerian cycle? But not What is the Eulerian Cycle.</p><h4 style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Definition 24.1 <span class="p">(P)</span>. <span class="p">Decision problems solvable in polynomial time.</span></h4><h4 style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Definition 24.2 <span class="p">(NP)</span>. <span class="p">Decision problems verifiable in polynomial time with a certificate.</span></h4><p style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">Problems in the class NP have the dichotomy that if the answer is yes you can demonstrate it in polynomial time, but many of them are not able to be disproved in polynomial time. When the answer is yes it’s easy to prove, otherwise it’s very hard.</p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Certificate is usually the solution to the problem. Example would be the coloring problem from the homework.</p><h4 style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Definition 24.3 <span class="p">(SAT)</span>. <span class="p">Satisfiability Problem Given a Boolean formula, is there a way of setting the variables to true and false such that the formula is true?</span></h4><p style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">If it is then it can be evaluated in polynomial time, the certificate is the assignment. If it isn’t satisfiable the only way to show that is to try every possibility of assignments, which takes exponential time.</p><h4 style="padding-top: 7pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Theorem 24.1 <span class="p">(Cook-Levin 1972)</span>. <span class="p">Satisfiability is NP-Complete.</span></h4><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">•</p><p style="text-indent: 0pt;text-align: left;"/><p style="padding-top: 9pt;padding-left: 31pt;text-indent: 0pt;text-align: justify;">The Cook-Levin Theorem implies that if we can solve a satisfiability problem in polynomial time, we can solve any problem in the class NP in polynomial time when the answer is "yes".</p><h3 style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark242">The Class of NP problems</a><a name="bookmark252">‌</a></h3><p class="s15" style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><span class="p">Is it the case that if something can be solved in polynomial time it can be verified in polynomial time? Does </span>P <span class="s9">= </span>N P <span class="p">? Or more directly, are P and NP-Complete classes distinct? No one knows.</span></p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">NP-Complete: The class of problems that are all equivalent to one another under reduction. Formula-SAT, circuit-SAT and coloring are all the same problem, really. They can be reduced to one another.</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">/ −</p><p style="text-indent: 0pt;text-align: left;"/><p class="s15" style="padding-left: 7pt;text-indent: 0pt;text-align: justify;"><span class="p">Most things in real life are in the NP class. Empirical Statement: For problems occurring in nature, Once in the class NP, it’s either P or NP-Complete. There’s a theorem that says that if </span>P <span class="s9">= </span>N P Complete <span class="p">then there are an infinite class of problem between them.</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark243">Reduction</a><a name="bookmark253">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Having proved that a problem is NP complete, how do we prove other problems are also NP complete?</p><h4 style="padding-top: 7pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Theorem 24.2. <span class="p">Circuit SAT is NP-complete.</span></h4><p style="text-indent: 0pt;text-align: left;"><span><img width="9" height="9" alt="image" src="cmsc351/Image_309.png"/></span></p><p class="s197" style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Proof. <span class="p">- Show in NP - Show hard for NP - Show that Circuit SAT is at least as hard as some other problem which we know is NP-complete.</span></p><p style="padding-top: 9pt;padding-left: 7pt;text-indent: 0pt;line-height: 62%;text-align: left;">Formula SAT <span class="s3">≤</span><span class="s15">p </span>Circuit SAT Circuit SAT <span class="s3">≤</span><span class="s15">p </span>Formula SAT</p><p style="padding-top: 10pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Converting from circuit to formula is harder than the other way. But the two are still verifiable in the same class of running time.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark244">Traveling Salesman Problem</a><a name="bookmark254">‌</a></h3><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Eulerian Cycles require that you hit every path once, while Hamiltonian Cycles require that you hit every vertex once. This is the crux of the traveling salesman problem. Hamiltonian Cycles are NP-Complete.</p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">The Traveling Salesman problem is this problem of finding the shortest path that hits all the nodes in a graph. Because the traveling salesman problem isn’t a yes no question the technically correct way of formulating it is to ask if there is a path with length less than some target length.</p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">This is a generalization of the Hamiltonian Cycle problem, which is NP complete, therefore the traveling salesman problem is NP complete.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark245">Theory</a><a name="bookmark255">‌</a></h4><p style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;text-align: justify;">There were generalizable characteristics of the Eulerian cycle problem that allowed Mathematicians to determine proofs around them, but the Hamiltonian Cycle problem doesn’t have any generalizable characteristics like that and it wasn’t until the advent of the NP completeness theorem that this was understood.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark246">Problems between P and NP-Complete</a><a name="bookmark256">‌</a></h3></li><li style="padding-top: 3pt;padding-left: 31pt;text-indent: -10pt;text-align: left;"><p style="display: inline;">Factoring</p></li><li style="padding-left: 31pt;text-indent: -10pt;text-align: left;"><p style="display: inline;">Discrete Logarithm</p></li><li style="padding-left: 31pt;text-indent: -10pt;text-align: left;"><p style="display: inline;">Graph Isomorphism</p><p style="padding-top: 4pt;padding-left: 6pt;text-indent: 0pt;text-align: left;">Their exact location isn’t known.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><h3 style="padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark247">Exam Materials</a><a name="bookmark257">‌</a></h3><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Must prove a problem is in class NP by stating what the cert is and showing how to use the cert to verify. No Reductions.</p><p style="padding-left: 7pt;text-indent: 0pt;text-align: justify;">Show that you can use the fact of the class of the decision problem form of the question to derive the class of the optimization problem form. If you can determine the yes/no condition of whether a formula is satisfiable, you can determine the certificate for that factor in Polynomial time.</p><h4 style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;"><a name="bookmark248">Formula SAT</a><a name="bookmark258">‌</a></h4><p class="s15" style="padding-top: 7pt;padding-left: 7pt;text-indent: 0pt;line-height: 93%;text-align: left;"><span class="p">Assume Decision version of Formula SAT is in P. We want to find the assignment. Given Formula A variables </span>x<span class="s16">1</span>, x<span class="s16">2</span>, . . . , xn</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s18" style="padding-left: 12pt;text-indent: 0pt;text-align: left;"><span class="s17">1 </span><span class="h4">if </span>not <span class="s140">SAT-decidability(</span>A<span class="s140">)</span><span class="s141"> </span><span class="h4">then</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;">2 <span><img width="1" height="16" alt="image" src="cmsc351/Image_310.png"/></span><span class="s33"> </span><span class="h4">return </span><span class="s18">False</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">3 <span class="h4">end</span></p><p class="s26" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">4 </span><span class="h4">for </span>i <span class="s10">= 1 </span><span class="s191">to </span>n<span class="s15"> </span><span class="h4">do</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="114" alt="image" src="cmsc351/Image_311.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">5 <span class="s15">B A</span><span class="p">;</span></p><p style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">6 </span>Assign True to <span class="s15">xi </span>in A <span class="s141">// Every time you see </span><span class="s15">xi </span><span class="s141">in the formula substitute with true</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">7 <span class="p">Simplify to remove True;</span></p><p class="s18" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">8 </span><span class="h4">if </span>not <span class="s140">SAT-decidability(</span>A<span class="s140">)</span><span class="s141"> </span><span class="h4">then</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="32" alt="image" src="cmsc351/Image_312.png"/></span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">9 <span class="s15">A B</span><span class="p">;</span></p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">10 </span>Assign False to <span class="s15">xi </span>and simplify;</p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;text-align: left;">11 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">12 <span class="h4">end</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;text-align: left;">13 <span class="h4">return </span><span class="s18">X</span><span class="p">;</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><h4 style="padding-left: 6pt;text-indent: 0pt;text-align: left;"><a name="bookmark249">Graph Coloring Problem</a><a name="bookmark259">‌</a></h4><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Given an integer k, is a graph k-colorable?</p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">That’s the decision problem. You can use that to solve the real question of what’s the smallest number k such that a graph is k-colorable.</p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-top: 2pt;padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">1 <span class="s15">c </span><span class="s9">1</span><span class="p">;</span></p><p class="s18" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">2 </span><span class="h4">while </span>not <span class="s140">Colorable(</span>G,c<span class="s140">)</span><span class="s141"> </span><span class="h4">do</span></p><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">←</p><p style="text-indent: 0pt;text-align: left;"/><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;">3 <span><img width="1" height="16" alt="image" src="cmsc351/Image_313.png"/></span><span class="s33"> </span><span class="s15">c c </span><span class="s9">+ 1</span><span class="p">;</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 11pt;text-align: left;">4 <span class="h4">end</span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">5 </span>for <span class="s18">i=1 to n</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="98" alt="image" src="cmsc351/Image_314.png"/></span></p><h4 style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">6 </span>for <span class="s18">d =1 to c</span><span class="p"> </span>do</h4><p style="text-indent: 0pt;text-align: left;"><span><img width="1" height="65" alt="image" src="cmsc351/Image_315.png"/></span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;">7 <span class="p">Set vertex i to color d;</span></p><p class="s140" style="padding-left: 12pt;text-indent: 0pt;line-height: 12pt;text-align: left;"><span class="s17">8 </span><span class="h4">if </span>Colorable(<span class="s18">G’,d</span>)<span class="s141"> </span><span class="h4">then</span></p><p class="s17" style="padding-left: 12pt;text-indent: 0pt;line-height: 13pt;text-align: left;">9 <span><img width="1" height="16" alt="image" src="cmsc351/Image_316.png"/></span><span class="s33"> </span><span class="p">exit;</span></p><p class="s17" style="padding-left: 7pt;text-indent: 0pt;line-height: 11pt;text-align: left;">10 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">11 <span class="h4">end</span></p><p class="s17" style="padding-top: 1pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">12 <span class="h4">end</span></p><p style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Assign arbitrary colors to the graph nodes one at a time and then ask the routine if the graph is still c-colorable. But assignment of colors isn’t allowed in our routine. So we need to use a trick.</p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">Make a complete graph of c vertexes. Then connect our goal vertex in the original graph G to every vertex except the color we want. This forces the color determiner to require a color at that vertex.</p><p class="s15" style="padding-left: 7pt;text-indent: 0pt;line-height: 17pt;text-align: left;"><span class="p">Size of </span>G <span class="s9">= </span><span class="s3">|</span>G<span class="s3">| </span><span class="s9">+ </span>c<span class="s16">2 </span><span class="s9">+ (</span>c <span class="s3">− </span><span class="s9">1)</span>n</p></li></ul></li><li style="padding-top: 3pt;padding-left: 38pt;text-indent: -31pt;text-align: justify;"><h2 style="display: inline;"><a name="bookmark260">Appendices</a><a name="bookmark263">‌</a></h2></li></ol><p style="padding-top: 8pt;padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">Created by S. Jaladanki</p><p style="padding-left: 7pt;text-indent: 0pt;line-height: 12pt;text-align: justify;">Here, additional information is given about concepts described in the above text.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><ol id="l20"><li style="padding-left: 25pt;text-indent: -18pt;text-align: justify;"><h3 style="display: inline;"><a name="bookmark261">Transpositions</a><a name="bookmark264">‌</a></h3><p style="padding-top: 6pt;padding-left: 6pt;text-indent: 0pt;text-align: justify;">A transposition involves a pair of numbers where the bigger number is above the smaller number.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">For example, let’s look at an example array with the values at indices 1 to 5 listed from top to bottom. We’re trying to sort this list to have lower numbers on top (or the left) and larger numbers on the bottom (the right).</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-top: 7pt;text-indent: 0pt;text-align: center;">3</p><p class="s9" style="padding-top: 3pt;text-indent: 0pt;text-align: center;">5</p><p class="s9" style="padding-top: 3pt;text-indent: 0pt;text-align: center;">2</p><p class="s9" style="padding-top: 3pt;text-indent: 0pt;text-align: center;">1</p><p class="s9" style="padding-top: 3pt;text-indent: 0pt;text-align: center;">4</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 7pt;text-indent: 0pt;text-align: justify;">In the above array, there are 2 transpositions involving 3, since both 1 and 2 are smaller than 3 but located farther to the bottom (or the right) than 3. There are 3 transpositions involving 5 since 2, 1, and 4 are smaller than 5 but located closer to the bottom of the array. Similarly, there is 1 transposition involving 2 (because of 1), 0 transpositions involving 1, and 0 transpositions involving 4. From the above array, there is a total of 6 transpositions.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p style="padding-left: 7pt;text-indent: 0pt;text-align: left;">The number of transpositions is equal to the number of exchanges in bubble sort. For instance, in an already sorted list, there would be 0 exchanges needed since there are 0 transpositions.</p><p style="text-indent: 0pt;text-align: left;"><br/></p></li><li style="padding-left: 24pt;text-indent: -17pt;text-align: left;"><h3 style="display: inline;"><a name="bookmark262">Summation Properties</a><a name="bookmark265">‌</a></h3></li></ol><p style="padding-top: 6pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Manipulating summations is an important part of the course, and examples of important properties of summations are provided.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 14pt;text-indent: 0pt;line-height: 8pt;text-align: left;">j</p><p class="s15" style="padding-left: 24pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s9">1 = </span>j <span class="s3">− </span>i <span class="s9">+ 1 </span><span class="p">Upper limit - lower limit + 1</span></p><p class="s11" style="padding-left: 9pt;text-indent: 0pt;line-height: 8pt;text-align: justify;">k<span class="s14">=</span>i</p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 13pt;text-indent: 0pt;line-height: 5pt;text-align: left;">n</p><p class="s26" style="padding-left: 24pt;text-indent: 0pt;line-height: 77%;text-align: left;"><span class="s142">i </span><span class="s9">= </span>n<span class="s10">(</span>n <span class="s10">+ 1)</span></p><p class="s9" style="text-indent: 0pt;line-height: 6pt;text-align: right;">2</p><p style="padding-top: 4pt;padding-left: 24pt;text-indent: 0pt;text-align: left;">Gauss’ sum formula, notice that lower limit is 1</p><p class="s11" style="padding-left: 9pt;text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p class="s11" style="padding-top: 1pt;padding-left: 13pt;text-indent: 0pt;line-height: 2pt;text-align: left;">n</p><p class="s11" style="padding-top: 6pt;padding-left: 9pt;text-indent: 0pt;line-height: 4pt;text-align: left;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s11" style="padding-top: 6pt;padding-left: 9pt;text-indent: 0pt;line-height: 4pt;text-align: left;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s9" style="padding-top: 5pt;padding-left: 8pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s22"> </span>(<span class="s15">i </span><span class="s3">− </span>1) =<span class="s23"> </span>(<span class="s15">i </span><span class="s3">− </span>1) + 1 =<span class="s23"> </span><span class="s15">i </span><span class="p">Subtract 1 from both limits and add 1 to formula</span></p><p class="s11" style="padding-left: 9pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=2</span></p><p class="s11" style="padding-left: 13pt;text-indent: 0pt;line-height: 2pt;text-align: left;">n</p><p class="s11" style="padding-left: 25pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=1</span></p><p class="s11" style="padding-left: 9pt;text-indent: 0pt;line-height: 2pt;text-align: left;">n</p><p class="s11" style="padding-left: 9pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=1</span></p><p class="s9" style="padding-top: 5pt;padding-left: 8pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s22"> </span><span class="s13"> </span><span class="s15">i </span>= (<span class="s23"> </span><span class="s15">i</span>) <span class="s3">− </span>1 <span class="p">Since added 1 to summation, subtract 1 outside of it</span></p><p class="s11" style="padding-left: 9pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=2</span></p><p class="s11" style="padding-left: 8pt;text-indent: 0pt;line-height: 3pt;text-align: left;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s11" style="padding-left: 8pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=1</span></p><p class="s11" style="padding-left: 12pt;text-indent: 0pt;line-height: 3pt;text-align: left;">n<span class="s24">−</span><span class="s14">1</span></p><p class="s9" style="padding-top: 7pt;padding-left: 9pt;text-indent: 0pt;text-align: left;"><span class="s22"> </span><span class="s13"> </span>2 = 2<span class="s23"> </span>1 <span class="p">Can pull out coefficients if not related to index (which is i here)</span></p><p class="s11" style="padding-top: 1pt;text-indent: 0pt;line-height: 10pt;text-align: right;">i<span class="s14">=1</span></p><p class="s9" style="padding-top: 2pt;text-indent: 0pt;text-align: left;"><u>1</u><span class="s23"> </span>(<span class="s15">i</span><span class="s16">2 </span>+ <span class="s15">i</span>) =<span class="s158"> </span><u>1</u><span class="s23"> </span><span class="s15">i</span><span class="s16">2 </span>+<span class="s158"> </span><u>1</u><span class="s23"> </span><span class="s15">i </span><span class="p">Can treat each term in parantheses as separate summation</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="text-indent: 0pt;line-height: 8pt;text-align: right;">n</p><p class="s11" style="padding-top: 1pt;padding-left: 9pt;text-indent: 0pt;line-height: 10pt;text-align: left;">i<span class="s14">=1</span></p><p class="s11" style="padding-left: 47pt;text-indent: 0pt;line-height: 8pt;text-align: left;">n n</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s9" style="padding-top: 3pt;padding-left: 8pt;text-indent: 0pt;line-height: 9pt;text-align: left;">2</p><p class="s11" style="padding-left: 16pt;text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p class="s9" style="padding-top: 2pt;text-indent: 0pt;text-align: left;"><span class="s22"> </span><span class="s13"> </span><u>1</u> (<span class="s15">i </span><span class="s3">− </span><span class="s15">j </span>+ 1) =<span class="s23"> </span><u>1</u><span class="s23"> </span>(<span class="s15">i </span><span class="s3">− </span><span class="s15">j </span>+ 1) <span class="p">Can pull out </span><u>1</u> <span class="p">from inner summation because j is index</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 1pt;padding-left: 13pt;text-indent: 0pt;text-align: left;">n i</p><p class="s9" style="padding-top: 3pt;padding-left: 8pt;text-indent: 0pt;line-height: 9pt;text-align: left;">2</p><p class="s11" style="padding-left: 16pt;text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p class="s9" style="padding-top: 3pt;text-indent: 0pt;line-height: 9pt;text-align: center;">2</p><p class="s11" style="padding-left: 26pt;text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=1</span></p><p class="s11" style="padding-top: 1pt;text-indent: 0pt;text-align: center;">n i</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s15" style="padding-top: 3pt;text-indent: 0pt;line-height: 10pt;text-align: right;">i</p><p class="s11" style="padding-left: 9pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=2 </span>j<span class="s14">=1</span></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 12pt;text-align: left;">2<span class="s15">i </span>=</p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 1pt;padding-left: 8pt;text-indent: 0pt;text-align: left;">lgn<span class="s24">−</span><span class="s14">1</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;text-align: right;">i<span class="s14">=2</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="81" height="1" alt="image" src="cmsc351/Image_317.png"/></span></p><p class="s9" style="text-indent: 0pt;line-height: 15pt;text-align: left;">1 <span class="s3">− </span>2</p><p style="text-indent: 0pt;text-align: left;"/><p class="s14" style="padding-top: 3pt;padding-left: 6pt;text-indent: 0pt;text-align: left;"><span class="s70">1 </span><span class="s3">− </span><span class="s9">2</span>(<span class="s11">lgn</span><span class="s24">−</span>1)+1</p><p class="s15" style="padding-top: 3pt;padding-left: 2pt;text-indent: 0pt;line-height: 10pt;text-align: left;">i i</p><p class="s11" style="padding-left: 9pt;text-indent: 0pt;line-height: 8pt;text-align: left;">j<span class="s14">=1</span></p><p style="text-indent: 0pt;text-align: left;"><span><img width="46" height="1" alt="image" src="cmsc351/Image_318.png"/></span></p><p class="s9" style="text-indent: 0pt;line-height: 10pt;text-align: left;">=</p><p style="text-indent: 0pt;text-align: left;"/><p class="s3" style="text-indent: 0pt;line-height: 15pt;text-align: left;">−<span class="s9">1</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s9" style="text-indent: 0pt;line-height: 17pt;text-align: left;">= <span class="s3">−</span>1 + <span class="s15">nlg</span><span class="s16">2 </span>= <span class="s15">n </span><span class="s3">− </span>1 <span class="p">Use of geometric series formula</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s70" style="padding-top: 3pt;padding-left: 9pt;text-indent: 0pt;text-align: left;">1 <span class="s3">− </span><span class="s9">2</span><span class="s11">lgn</span></p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s11" style="text-indent: 0pt;line-height: 7pt;text-align: left;">i<span class="s14">=0</span></p><p style="padding-left: 13pt;text-indent: 0pt;line-height: 7pt;text-align: left;"/><p style="padding-top: 3pt;padding-left: 7pt;text-indent: 0pt;text-align: left;">Following is an example of the Change of Variable Method.</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s13" style="text-indent: 0pt;line-height: 10pt;text-align: left;"> </p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-left: 51pt;text-indent: 0pt;line-height: 8pt;text-align: left;">n</p><p class="s15" style="padding-left: 60pt;text-indent: 0pt;line-height: 18pt;text-align: left;"><span class="s9">(</span>n <span class="s3">− </span>i <span class="s9">+ 1)</span></p><p class="s11" style="padding-left: 47pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=1</span></p><p style="padding-left: 44pt;text-indent: 0pt;text-align: left;">Writing out summation terms with substitution gives</p><p class="s9" style="padding-left: 47pt;text-indent: 0pt;line-height: 11pt;text-align: left;">= (<span class="s26">n </span><span class="s27">−</span><span class="s3"> </span>1 + 1) + (<span class="s15">n </span><span class="s3">− </span>2 + 1) + (<span class="s15">n </span><span class="s3">− </span>3 + 1) +<span class="s15">... </span>+ (<span class="s15">n </span><span class="s3">− </span>(<span class="s15">n </span><span class="s3">− </span>2) + 1) + (<span class="s15">n </span><span class="s3">− </span>(<span class="s15">n </span><span class="s3">− </span>1) + 1) + (<span class="s15">n </span><span class="s3">− </span><span class="s15">n </span>+ 1)</p><p style="text-indent: 0pt;text-align: left;"><br/></p><p class="s198" style="padding-left: 121pt;text-indent: 0pt;line-height: 1pt;text-align: left;"><span><img width="20" height="2" alt="image" src="cmsc351/Image_319.png"/></span> <span><img width="20" height="2" alt="image" src="cmsc351/Image_320.png"/></span><span class="s176"> </span><span><img width="20" height="2" alt="image" src="cmsc351/Image_321.png"/></span> <span><img width="20" height="2" alt="image" src="cmsc351/Image_322.png"/></span></p><p class="s13" style="padding-left: 58pt;text-indent: 0pt;line-height: 82%;text-align: left;"> <span class="s199">n</span><span class="s55"> </span>.. <span class="s199">n</span><span class="s11"> </span><span class="s200">−</span><span class="s24"> </span><span class="s201">1 </span>.. <span class="s199">n</span><span class="s11"> </span><span class="s200">−</span><span class="s24"> </span><span class="s201">2 </span>.. <span class="s201">3</span><span class="s57"> </span>.. <span class="s201">2</span><span class="s57"> </span>.. <span class="s201">1</span><span class="s57"> </span>..</p><p style="padding-left: 44pt;text-indent: 0pt;line-height: 12pt;text-align: left;">Based on the pattern and range of the terms (1,2,3...n-2,n-1,n) we can rewrite the summation as</p><p class="s26" style="padding-top: 1pt;text-indent: 0pt;text-align: left;"><span class="s94"> </span><span class="s13"> </span>n<span class="s10">(</span>n <span class="s10">+ 1)</span></p><p style="text-indent: 0pt;text-align: left;"/><p class="s11" style="padding-top: 2pt;padding-left: 62pt;text-indent: 0pt;text-align: left;">n</p><p class="s9" style="padding-top: 1pt;padding-left: 47pt;text-indent: 0pt;line-height: 10pt;text-align: left;">= (<span class="s15">i</span>) =</p><p class="s9" style="padding-left: 114pt;text-indent: 0pt;line-height: 6pt;text-align: left;">2</p><p class="s11" style="padding-left: 58pt;text-indent: 0pt;line-height: 8pt;text-align: left;">i<span class="s14">=1</span></p></body></html>