O(2x) - Exponential
O(c) - Constant
O(n!) - Factorial
O(x3) - Cubic
O(n) - Loglinear
O(logn) - Logarithmic
We will use the following two theorems on limits.
Theorem 1 If a ∈ R and limx = L → ∞ f(x) < ∞ then limx → ∞ af(x) = aL.
Theorem 2 If limx = L → ∞ f(x) < ∞ and limx → ∞ g(x) = M < ∞ then limx → ∞ f(x) + g(x) = L + M.
Suppose that f(x) ∈ O(h(x)) and
g(x) ∈ O(h(x)).
Thus limx → ∞ f(x)/ h(x) = L < ∞
and limx → ∞ g(x)/ h(x) = M < ∞.
Now for any a, b ∈ R limx → ∞ af(x)/ h(x) = aL < ∞ and limx → ∞ bg(x)/ h(x) = bM by Theorem 1.
So limx → ∞ af(x)/ h(x)
+ bg(x)/ h(x)
= aL + bM < ∞, by Theorem 2.
So f(x) + g(x) ∈ O(h).
v1 | v2 | v3 | v4 | v5 |
0 | 0 | 0 | 0 | 1 |
0 | 0 | 1 | 1 | 0 |
0 | 1 | 0 | 0 | 1 |
0 | 1 | 0 | 0 | 1 |
1 | 0 | 1 | 1 | 0 |
Index | Pointer | Vertex |
---|---|---|
1: | 0 | 5 |
2: | 6 | 3 |
3: | 7 | 2 |
4: | 8 | 2 |
5: | 9 | 1 |
6: | 0 | 4 |
7: | 0 | 5 |
8: | 0 | 5 |
9: | 10 | 3 |
10: | 0 | 4 |
1: | 5 |
---|---|
2: | 3, 4 |
3: | 2, 5 |
4: | 2, 5 |
5: | 1, 3, 4 |
A2 = |
| A3 = |
|
Wk(vi, vj) represents the length of the shortest path from vi to vj using only vertices from v1 to vk internally, or ∞ if no such path exists.
Thus W1(v1, v2) is the length of the shortest path from v1 to v2 using only v1 internally. But there is no edge v1 v2, so this is ∞.
A similar argument holds for W2(v1, v2).
First note that Wk(v1, vk) = ∞ for every k < 5, since every path to v1 must pass through the point v5. This argument saves a lot of calculation. Further note that Wk(vi, vj) = 1 if and only if there is an edge between vi, vj.
Now
W5(v1, v2)
= min(W4(v1, v2),
W4(v1, v5) +
W4(v5, v2)).
Firstly, W4(v1, v5)
= 1 since there is an edge between them.
Further
W4(v5, v2) =
min(W3(v5, v2),
W3(v5, v4) +
W3(v4, v2)
).
W3(v4, v2) =
W3(v5, v4) =
1, since there is an edge between them.
So W4(v5, v2) = 2.
Thus W5(v1, v2) = 3.
The point of this question was to show that calculations of the W's can be long, though I have used quite a few shortcuts here.
Not shown.
To find Wk(vi, vj) we must find Wk-1(vi, vj) for each pair i, j ≤ k, giving k choose 2 = k(k-1)/2. This yields k(k-1)/2 calculations at each level. We must find Wn(vi, vj) for each i and j, giving
If the vi, vj entry of Ak is non zero it means there is a path of length k. This suggests the following algorithm:
Find succesive powers of the adjacency matrix until the vi, vj entry is non zero.
In the worst case we must calculate n matrix products, each taking O(n2) steps, for a total of roughly O(n3).
Note that this is the same as the W method.
Graphs: | ||||||
---|---|---|---|---|---|---|
Name | Bowtie | Dumbell | Extended Bowtie | |||
Start | Central vertex | One of the central vertices | e |