1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Lachaise Assignment
% LaTeX Template
% Version 1.0 (26/6/2018)
%
% This template originates from:
% http://www.LaTeXTemplates.com
%
% Authors:
% Marion Lachaise & François Févotte
% Vel ([email protected])
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass{article}
\input{structure.tex}
\title{CENG567: Homework \#1}
\author{Yiğit Sever}
\date{\today}
%----------------------------------------------------------------------------------------
\begin{document}
\maketitle
\section{Stable Matching}%
\label{sec:stable_matching}
% question a ✅ {{{1 %
\begin{question}%
\label{q:1_a}
Use \emph{Gale-Shapley} algorithm to find a stable matching for the following set of four colleges, four students and their preference lists.
\end{question}
\begin{commandline}[Gale-Shapley algorithm, from lecture slides, edited for the context]
\begin{verbatim}
Initialize each person to be free.
while (some student is free and hasn't applied to every college) {
Choose such a student m
c = 1st college on m's list to whom m has not yet applied
if (c is free)
assign c to m for potential application (a)
else if (c prefers m to their current applicant m')
assign m and c for potential application, and m' to be free (b)
else
c rejects m (c)
}
\end{verbatim}
\end{commandline}
A quick trace of the algorithm;
\begin{enumerate}
\item $S_1$ is free;
\begin{enumerate}
\item applies to first college on their preference list $C_4$;
\item $C_4$ is free so it accepts and is matched with $S_1$ (a).
\end{enumerate}
\item $S_2$ is free
\begin{enumerate}
\item applies to first college on their preference list; $C_1$
\item $C_1$ is free so it accepts and is matched with $S_2$ (a).
\end{enumerate}
\item $S_3$ is free;
\begin{enumerate}
\item applies to first college on their preference list; $C_1$
\item $C_1$ rejects $S_3$ because it prefers $S_2$ to $S_3$ (c).
\item applies to second college on their preference list; $C_2$
\item $C_2$ is free so it accepts and is matched with $S_3$ (a).
\end{enumerate}
\item $S_4$ is free;
\begin{enumerate}
\item applies to first college on their preference list; $C_4$
\item $C_4$ rejects $S_4$ because it prefers $S_1$ to $S_4$ (c).
\item applies to second college on their preference list; $C_3$
\item $C_3$ is free so it accepts and is matched with $S_4$ (a).
\end{enumerate}
\item There are no more free students to match, algorithm terminates.
\end{enumerate}
The final matching and the answer to Question~\ref{sec:stable_matching}(a) is;
\begin{align*}
S_1 &\rightarrow C_4 \\
S_2 &\rightarrow C_1 \\
S_3 &\rightarrow C_2 \\
S_4 &\rightarrow C_3
\end{align*}
% 1}}} %
% question b ✅ {{{1 %
\begin{question}
Find another stable matching with the same algorithm.
\end{question}
All executions of \emph{Gale-Shapley} yield the same stable matching (that is proposer-optimal) and cannot produce \emph{another} stable matching like the question text asks for.
% 1}}} %
% question c ✅ {{{1 %
\begin{question}
Consider a pair of man $m$ and woman $w$ where $m$ has $w$ at the top of his preference list and $w$
has $m$ at the top of her preference list. Does it always have to be the case that the pairing $(m, w)$ exist
in every possible stable matching? If it is true, give a short explanation. Otherwise, give a counterexample.
\end{question}
\emph{Proof by contradiction}.
Assume that in the resulting matching of \emph{Gale-Shapley}, we have $S'$, where $m$ is matched with $w'$ and $w$ is matched with $m'$.
The definition of stable matching dictates that there is \emph{no incentive to exchange}, yet in $S'$ $m$ can trade up to $w$ since $m$ prefers $w$ to $w'$ and $w$ can trade up since $w$ prefers $m$ to $m'$.
$S'$ could not have occurred since men propose in accordance to their preference list, which $w$ is on top of for $m$ and no other men that may propose to $w$ can make $w$ switch since they are not more preffered than $m$.
% 1}}} %
% question d ✅ {{{1 %
\begin{question}
Give an instance of $n$ colleges, $n$ students, and their preference lists so that the Gale-Shapley algorithm requires only $O(n)$ iterations, and prove this fact.
\end{question}
For a proposer agnostic formation, arrange the preference lists of colleges and students as follows;
\begin{gather*}%
\label{eq:college_prefs}
C_{1} \rightarrow \left\{ S_{1}, S_{n}, S_{n-1}, \dots, S_{2} \right\} \\
C_{2} \rightarrow \left\{ S_{2}, S_{n}, S_{n-1}, \dots, S_{3} \right\} \\
\dots \\
C_{k} \rightarrow \left\{ S_{k}, S_{n}, S_{n-1}, \dots, S_{k+1} \right\} \\
\dots \\
C_{n} \rightarrow \left\{ S_{n}, S_{n-1}, S_{n-2}, \dots, S_{1} \right\} \\
\end{gather*}
\begin{gather*}%
\label{eq:student_prefs}
S_{1} \rightarrow \left\{ C_{1}, C_{n}, C_{n-1}, \dots, C_{2} \right\} \\
S_{2} \rightarrow \left\{ C_{2}, C_{n}, C_{n-1}, \dots, C_{3} \right\} \\
\dots \\
S_{k} \rightarrow \left\{ C_{k}, C_{n}, C_{n-1}, \dots, C_{k+1} \right\} \\
\dots \\
S_{n} \rightarrow \left\{ C_{n}, C_{n-1}, C_{n-2}, \dots, C_{1} \right\} \\
\end{gather*}
Where the student list $\{S_1, S_2, \dots, S_{n}\}$ and college list $\{C_1, C_2, \dots, C_{n}\}$ are shifted.
In this setup, ever proposer will propose to the first suitor in their preference list which is guaranteed to be free since they are not the first on any other suitor's preference list.
The algorithm in this instance runs in $\mathcal{O}(n)$ iterations, every proposer will follow the (a) branch in the algorithm given under Question~\ref{q:1_a}.
% 1}}} %
% question e ✅ {{{1 %
\begin{question}
Give another instance for which the algorithm requires $\Omega(n^{2})$ iterations (that is, it requires at least $cn^{2}$ iterations for some constant $0 < c \le 1)$, and prove this fact.
\end{question}
\begin{infor}
We have collaborated with CENG567 student Manolya Atalay for this question and used the answers and explanations given in the linked Mathematics Stack Exchange question\footnote{\url{https://math.stackexchange.com/questions/1410898/worst-case-for-the-stable-marriage-problem}}.
\end{infor}
The worst problem instance for the algorithm (the instance that requires the largest number of steps) can be inferred as follows;
The highest number of times a man $m$ can \emph{propose} (every iteration has one proposal in it) to $n$ many women is $n-1$. It cannot be $n$ because it would mean that $m$ did not find a suitable partner (rejected by everyone), which is contradictory with the algorithm's perfect matching guarantee.
For $n$ men, in the worst case, each one can propose $n-1$ times; $n(n-1)$. One man has to propose one last time after getting rejected by $n-1$ women, giving the total number of proposals;
\begin{equation}
n (n-1) + 1
\end{equation}
As the theoretical highest number of iterations \emph{Gale-Shapley} can have.
As for the instance that produces this run time;
Men have to arrange their preference list as follows for $n>2$.
\begin{equation}
M_{k} \rightarrow
\begin{cases}
W_{k}, W_{k+1}, \dots, W_{n-1}, W_{1}, W_{2}, \dots, W_{n} &\mbox{if } k \ne n \\
W_{k-1}, W_{k}, \dots, W_{n-1}, W_{1}, W_{2}, \dots, W_{n} &\mbox{if } k = n \\
\end{cases}
\end{equation}
In other words, the \emph{last} man's preference list is identical to one above them.
Women have to arrange their preference list as follows for $n>2$;
\begin{equation}
W_{k} \rightarrow
\begin{cases}
M_{k+1}, M_{k}, \dots &\mbox{if } k \ne n-1 \\
M_{1}, M_{n}, \dots &\mbox{if } k = n-1 \\
\end{cases}
\end{equation}
The preference list of the last women $W_{n}$ does not matter neither does the order of the rest of the men in the preference list of the women given.
We have implemented \emph{Gale-Shapley} and an instance set creation script to test our findings;
\begin{commandline}[n=3]
\begin{verbatim}
n: Men Preference Table
A | 1 2 3
B | 2 1 3
C | 2 1 3
----
Women Preference Table
1| B A C
2| A C B
3| A B C
----
Matching B with 2 (a)
Matching C with 2, B is now free (b)
Matching A with 1 (a)
Matching B with 1, A is now free (b)
Matching A with 2, C is now free (b)
C is rejected by 1 because B is more preffered (c)
Matching C with 3 (a)
Final pairings:
A - 2
B - 1
C - 3
A proposed 2 times
B proposed 2 times
C proposed 3 times
total of 7 times with n(n-1) + 1 = 7
\end{verbatim}
\end{commandline}
\begin{commandline}[n=6]
\begin{verbatim}
n: Men Preference Table
A | 1 2 3 4 5 6
B | 2 3 4 5 1 6
C | 3 4 5 1 2 6
D | 4 5 1 2 3 6
E | 5 1 2 3 4 6
F | 5 1 2 3 4 6
----
Women Preference Table
1| B A C D E F
2| C B A D E F
3| D C A B E F
4| E D A B C F
5| A F B C D E
6| A B C D E F
----
Matching D with 4 (a)
Matching A with 1 (a)
Matching F with 5 (a)
E is rejected by 5 because F is more preffered (c)
Matching C with 3 (a)
Matching B with 2 (a)
// --- edited out for space ---
C is rejected by 1 because A is more preffered (c)
Matching C with 2, B is now free (b)
B is rejected by 3 because D is more preffered (c)
B is rejected by 4 because E is more preffered (c)
B is rejected by 5 because F is more preffered (c)
Matching B with 1, A is now free (b)
A is rejected by 2 because C is more preffered (c)
A is rejected by 3 because D is more preffered (c)
A is rejected by 4 because E is more preffered (c)
Matching A with 5, F is now free (b)
F is rejected by 1 because B is more preffered (c)
F is rejected by 2 because C is more preffered (c)
F is rejected by 3 because D is more preffered (c)
F is rejected by 4 because E is more preffered (c)
Matching F with 6 (a)
Final pairings:
E - 4
B - 1
A - 5
D - 3
C - 2
F - 6
A proposed 5 times
B proposed 5 times
C proposed 5 times
D proposed 5 times
E proposed 5 times
F proposed 6 times
total of 31 times with n(n-1) + 1 = 31
\end{verbatim}
\end{commandline}
% 1}}} %
\section{Stable Matching Variation}%
\label{sec:stable_matching_variation}
% stable matching question ✅ {{{1 %
\begin{question}
Consider a Stable Matching problem with men and women.
Consider a woman $w$ where she prefers man $m$ to $m'$, but both $m$ and $m'$ are low on her list of preferences.
Can it be the case that by switching the order of $m$ and $m'$ on her list of preferences (i.e., by falsely claiming that she prefers $m'$ to $m$) and running the algorithm with this modified preference list, $w$ will end up with a man $m''$ that she prefers to both $m$ and $m'$?
Either give a proof that shows such an improvement is impossible, or give an example preference list for which an improvement for $w$ is possible.
\end{question}
We will give an example instance.
Let's take the example preference list for men; $M = {x,y,z}$ and women: $W = {a,b,c}$.
\begin{table}[!htb]
\caption{Preference lists of women}%
\label{table:2_general}
\begin{minipage}{.5\linewidth}
\caption{Everyone is being truthful}%
\label{table:2_true}
\centering
\begin{tabular}{l|lll}
\textbf{a} & y & x & z \\
\textbf{b} & x & y & z \\
\textbf{c} & x & y & z
\end{tabular}
\end{minipage}%
\begin{minipage}{.5\linewidth}
\centering
\caption{a is lying about their preference}%
\label{table:2_lie}
\begin{tabular}{l|lll}
\textbf{a} & y & z & x \\
\textbf{b} & x & y & z \\
\textbf{c} & x & y & z
\end{tabular}
\begin{tikzpicture}[overlay]
\draw[red, line width=1pt] (-0.72,0.52) ellipse (0.70cm and 0.2cm);
\end{tikzpicture}
\end{minipage}
\end{table}
In the example given above in Table~\ref{table:2_general}, we have two cases for women, Table~\ref{table:2_true} where everyone has given their actual preference list and Table~\ref{table:2_lie} where $a$ has lied about their \nth{2} and \nth{3} preferences.
The following is the men's preference table;
\begin{table}[htb]
\centering
\begin{tabular}{l|lll}
\textbf{x} & a & b & c \\
\textbf{y} & b & a & c \\
\textbf{z} & a & b & c
\end{tabular}
\caption{The preference lists of the men.}%
\label{tab:men_pref}
\end{table}
The trace of \emph{Gale-Shapley} algorithm for the truth telling case with Table~\ref{table:2_true} and Table~\ref{tab:men_pref} is below;
\begin{enumerate}
\item Matching x with a (a)
\item Matching y with b (a)
\item z proposes to a but gets rejected because a prefers x more (c)
\item z proposes to b but gets rejected because b prefers y more (c)
\item Matching z with c (a)
\end{enumerate}
Which produces the following matching. Note that $a$ is matched with their \nth{2} choice.
\begin{align*}
x &\rightarrow a \\
y &\rightarrow b \\
z &\rightarrow c
\end{align*}
Now let's examine the trace of the algorithm when $a$ lies by providing an altered preference table. The trace below uses Table~\ref{table:2_lie} and Table~\ref{tab:men_pref};
\begin{enumerate}
\item Matching y with b (a)
\item Matching z with a (a)
\item \textbf{x proposes to a but gets rejected because a lies by saying that they like z more (c)}
\item Matching x with b, y is now free (b)
\item \textbf{Matching y with a, z is now free (b)}
\item z proposes to b but gets rejected because b prefers x more (c)
\item Matching z with c (a)
\end{enumerate}
The highlighted lines show that $a$ lies when proposed by $x$ and then is able to trade up to $y$. The following it the final matching;
\begin{align*}
x &\rightarrow b \\
y &\rightarrow a \\
z &\rightarrow c
\end{align*}
Woman $a$ was able to get their highest preferred option $y$ by telling a lie. We have proved that an improvement is possible.
% 1}}} %
\section{Asymptotics}%
\label{sec:asymptotics}
% asymptotics ✅ {{{1 %
\begin{question}
What is the running time of this algorithm as a function of $n$? Specify a function $f$ such that the running time of the algorithm is $\Theta(f(n))$.
\end{question}
{\centering
\begin{minipage}{.7\linewidth}
\begin{algorithm}[H]
\For(\tcc*[f]{outer loop}){$i = 2$; $i < n$; $i += 1$ }{
\For(\tcc*[f]{inner loop}){$j=1$; $j < n$; $j * = i$}{
Some $\Theta(1)$ operation\;
}
}
\caption{Equivalent algorithm to one given in Question 3, edited for brevity}%
\label{alg:question_3}
\end{algorithm}
\end{minipage}
\par
}
The outer loop runs in linear time $\mathcal{O}(n)$ whereas the inner loop requires some deconstruction;
Take the first iteration of the inner loop, $i = 2$ and $j$ is initialized at $1$.
\begin{align*}%
\label{eq:3_iterations}
1^{\text{st}} ~ \text{iteration} &\rightarrow j = j * i \implies j = 2 \\
2^{\text{nd}} ~ \text{iteration} &\rightarrow j = 4 \\
3^{\text{rd}} ~ \text{iteration} &\rightarrow j = 8 \\
\dots \\
m^{\text{th}} ~ \text{iteration} &\rightarrow j = i^{m} < n \\
\end{align*}
$m$ is the last iteration of the inner loop because it hit the stopping condition $i^{m} < n$.
Using the Equations above we can find the running time for the inner loop to hit stopping condition;
\begin{gather*}
i^{m} < n \\
m < \log_{i} n
\end{gather*}
In other words, the inner loop has a running time in the order of $\mathcal{O}(\log{n})$. By the product property of $\mathcal{O}$-notation we have the running time of $\mathcal{O}(n\log_{a}{n}), a > 1$ for the entire algorithm. The base $a$ is useful to answer the rest of the question;
We can specify a function $f$ such as $f = n \log_{b}(n)$ where $b > 1$. From the course slides;
\begin{equation*}
\lim_{n \to \infty}\frac{n\log_{a}{n}}{n \log_{b}{n}} = c
\end{equation*}
And when the limit of two functions $f, g$ converge to some constant $c$, then $f(n) = \Theta(g(n))$.
% 1}}} %
\section{Big $\mathcal{O}$ and $\Omega$}%
\label{sec:big_o_and_omega_}
% question a ✅ {{{1 %
\begin{question}
Let $f(n)$ and $g(n)$ be asymptotically positive functions. Prove or disprove the following conjectures.
\end{question}
\begin{info}[]
$f(n) = \mathcal{O}(g(n))$ implies $g(n) = \mathcal{O}(f(n))$
\end{info}
From the definition of Big $\mathcal{O}$ notation given in the lecture slides;
\begin{equation}%
\label{eq:a_bigo}
\exists ~ c > 0 \quad \text{and} \quad n_{0} \ge 0 \quad \mid \quad 0 \le f(n) \le c \cdot g(n) \quad \forall n \ge n_{0}
\end{equation}
If we rearrange the right hand side of the Proposition~\ref{eq:a_bigo};
\begin{equation*}%
0 \le \frac{1}{c} f(n) \le g(n) \\
\end{equation*}
Or simply,
\begin{equation}
\label{eq:a_bio_rearranged}
0 \le c' f(n) \le g(n)
\end{equation}
By the definition of Big $\mathcal{O}$ notation, in order for $g(n) = \mathcal{O}(f(n))$ to be true,
\begin{equation*}
\exists ~ k > 0 \quad \text{and} \quad n_{0}' \ge 0 \quad \mid \quad 0 \le g(n) \le k \cdot f(n) \quad \forall n' \ge n_{0}'
\end{equation*}
Has to be true, yet from Equation~\ref{eq:a_bio_rearranged} we know that $f(n)$ multiplied by some constant $c'$ is strictly smaller than $g(n)$. The conjecture is \emph{false}.
\begin{info}[]
$f(n) = \mathcal{O}((f(n))^{2})$
\end{info}
% https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-introduction-to-algorithms-sma-5503-fall-2005/assignments/ps1sol.pdf
We can reuse the definition of Big $\mathcal{O}$ notation given in Equation~\ref{eq:a_bigo}, and using the question text, we have;
For $c > 1$ and $n_{0} > 1$;
\begin{align*}%
f(n) &\le f(n)^{2} \quad \forall n \ge n_{0} \\
\text{take} ~ g(n) &= f(n)^{2} \\
f(n) &\le c\cdot g(n) \quad \forall n \ge n_{0}
\end{align*}
For $f(n) \ge 1$. The conjecture is true for asymptotically positive function $f(n)$ but does not hold for an $f(n) < 1$.
\pagebreak
\begin{info}[]
$f(n) + o(f(n)) = \Theta(f(n))$
\end{info}
From the definition of Big Theta notation, we are trying to prove a relation such that;
\begin{equation}%
\label{eq:a_big_theta}
0 \le c_{1} \cdot f(n) \le f(n) + o(f(n)) \le c_{2} \cdot f(n)
\end{equation}
First, let's give the little-o notation to remove $o(f(n))$ from Equation~\ref{eq:a_big_theta};
\begin{equation}%
\label{eq:a_little_o}
\forall ~ c > 0 \quad \exists ~ n_{0} > 0 \mid ~ 0 \le g(n) < c \cdot f(n) ~ \forall n \ge n_{0}
\end{equation}
So we can rewrite Equation~\ref{eq:a_big_theta} using Equation~\ref{eq:a_little_o};
\begin{equation}%
\label{eq:a_rewritten}
c_1 \cdot f(n) \le f(n) + g(n) \le c_2 \cdot f(n)
\end{equation}
It's trivial to pick $c_1 < 1$ to deal with the left hand side of the inequality;
\begin{equation*}
f(n) \le f(n) + g(n)
\end{equation*}
For the right hand side; we can start by picking $n_{0} = 1$ and $c = 1$ in the Equation~\ref{eq:a_little_o}; keeping $g(n)$ strictly smaller than $f(n)$.
In order to prove the right hand side of the inequality; we can pick $c_2 > 2$ which equals;
\begin{align*}%
\label{eq:c2gt2}
f(n) + g(n) &\le 2 \cdot f(n) \\
\cancel{f(n)} + g(n) &\le \cancel{2 \cdot} f(n) \\
g(n) &\le f(n)
\end{align*}
Which we proved above using Equation~\ref{eq:a_little_o}. This conjecture is \emph{true}.
% 1}}} %
% question b {{{1 %
% https://people.cs.umass.edu/~sheldon/teaching/cs311/hw/hw01.pdf
\begin{question}
For each function $f(n)$ below, find (and prove that)
\begin{enumerate}
\item the smallest integer constant H such that $f(n) = \mathcal{O}(n^H)$
\item the largest positive real constant L such that $f(n) = \Omega(n^L)$
\end{enumerate}
Otherwise, indicate that H or L do not exist.
\end{question}
\begin{info}[]
$f(n) = \frac{n(n+1)}{2}$
\end{info}
(1) For $n_{0} \ge 1$; $\frac{n(n+1)}{2}$ is strictly smaller than $n^{2}$, yet $H=1$ is not possible since through the definition of Big-$\mathcal{O}$ notation it implies that for a \emph{constant} $c$;
\begin{align*}
0 \le \frac{n(n+1)}{2} &\le c\cdot n \\
\frac{\cancel{n}(n+1)}{2} &\le c\cdot \cancel{n} \\
\frac{n+1}{2} &\cancel{\le} c
\end{align*}
Hence $f(n) = \mathcal{O}(n^{2})$ and $H=2$.
(2) $L=2$. We can pick the constant $c = \frac{1}{2}$ and write the Big-$\Omega$ notation;
\begin{gather*}
c > 0 ~ \text{and} ~ n_{0} \ge 0 \\
\frac{n(n+1)}{2} \ge \frac{1}{2} n^{2} \\
\frac{\cancel{n}(n+1)}{\cancel{2}} \ge \frac{1}{\cancel{2}} n^{\cancel{2}} \\
n+1 \ge n
\end{gather*}
Does a $L>2$ work? Pick any $\ell > 2$;
\begin{align*}
c > 0 ~ \text{and} ~ n_{0} &\ge 0 \\
\frac{n(n+1)}{2} &\ge \frac{1}{2} n^{\ell} \\
\frac{n(n+1)}{\cancel{2}} &\ge \frac{1}{\cancel{2}} n^{\ell} \\
n(n+1) &\ge n^{\ell} \\
n+1 &\ge n^{\ell - 1} \\
1 &\ge n(n^{\ell - 2} - 1)
\end{align*}
The final equation does not hold for $n>1$ or the assumed $\ell > 2$ so $L>2$ cannot be true.
\begin{info}[]
$f(n) = \sum^{\lceil{\log{n}}\rceil}_{k=0} \frac{n}{2^{k}}$
\end{info}
It's beneficial to unpack the infinite sum beforehand;
\begin{align*}
f(n) &= \sum^{\lceil{\log{n}}\rceil}_{k=0} \frac{n}{2^{k}}\\
&= \frac{n}{2^{0}} + \frac{n}{2^{1}} + \frac{n}{2^{2}} + \dots + \frac{n}{2^{\lceil{\log{n}}\rceil}} \\
&= n \Big(1 + \frac{1}{2^{1}} + \frac{1}{2^{2}} + \dots + \frac{1}{2^{\lceil{\log{n}}\rceil}} \Big) \\
\end{align*}
The infinite sum approaches 1 as $\lceil{\log n\rceil} \rightarrow \infty$, giving us;
\begin{equation*}
f(n) = 2 \cdot n \\
\end{equation*}
(1,2) Finally, $H = L = 1$ since $f(n)$ is $\Theta(n)$. Borrowing the Big-$\Theta$ notation from Equation~\ref{eq:a_big_theta} for $c_1 = 1$ and $c_2 = 2$;
\begin{equation*}
n \le f(n) \le 2n
\end{equation*}
\begin{info}[]
$f(n) = n(\log n)^{2}$
\end{info}
\begin{align*}
n^{2} \quad v.s. \quad n(\log{n})^{2} \\
n^{1} \quad v.s. \quad (\log{n})^{2} \\
\sqrt{n} \quad v.s. \quad \sqrt{(\log{n})^{2}} \\
n^{\frac{1}{2}} \quad v.s. \quad \log{n}
\end{align*}
(1) From the lectures we know that $\log{n}$ is $\mathcal{O}(n^{d})$ for all $d$.
If $\log{n}$ is $\mathcal{O}(n^{\frac{1}{2}})$ then $n(\log{n})^{2}$ is $\mathcal{O}(n^{2})$. $H=2$.
(2) For $L$; we know that $f(n) = n(\log{n})^{2} > n^{1}$ but $n(\log{n})^{2} < n^{2}$ hence $L = 1$.
% 1}}} %
\end{document}
|