Some Additional Notes
- Just remember the notation
- $f(n) = \sqrt(n) \in O(n)$ therefore $f(n)$ has polynomial running time
- Logs
- $\log_b n = x $ means that $b^x = n$
- We frequently deal with $\log_2 n$ which is sometimes written $\lg n$
- $\log_e n$ is frequently written $\ln n$
- The relationship between logs in different bases
-
$$\begin{eqnarray}
\log_a n = x \\
a^x =n \\
\log_ba^x = \log_bn \\
x \log_b a = \log_b n \\
\log_a n \log_b a = \log_b n \\
\log_a n = \frac{\log_b n}{\log_b a} \\
\end{eqnarray}$$
- So the logs in different bases are just a constant $\frac{1}{\log_b a}$ of another.
- Because of this we will generally work in base 2.
- Base 2 is natural for computing
- So $\log_a n \in \Theta(\log_b n)$
- And we generally write that something is $O\log n$, even if we worked in another base.
- They have a discussion of implementing GS Stable Matching.
- you should read this.
- Note the input will be $O(n^2)$ because there are $n$ men, each with a preference list containing $n$ items.
- As we discussed before, you need to be careful about implementation or you might be $O(n^3)$ or higher.
- In my implementation, i used a index list.
- I used a 0 based ranking system (so array indexes worked)
- If woman w ranks five men 3 1 0 2 4
-
Man ID | Rank$_0$ |
3 | 0 |
1 | 1 |
0 | 2 |
2 | 3 |
4 | 4 |
- So I buit an index array (IA)
Index | 0 | 1 | 2 | 3 | 4 | Man I |
value | 2 | 1 | 3 | 0 | 4 | Has rank |
- This way I can determine the preference of man n in constant time.
- Does she prefer man 2 or man 3?
- Man 2's preference IA[2] = 3
- Man 3's preference IA[3] = 0
- IA[3] < IA[2]
- She prefers man 3.
- I am trading space (store a second array) for time.