Skip to content

Commit 33343cd

Browse files
committed
General Bug Fix.
1 parent d11b764 commit 33343cd

File tree

7 files changed

+24
-41
lines changed

7 files changed

+24
-41
lines changed

1 Fundamental/1.5/1.5.14/Program.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ static void Main(string[] args)
2020

2121
// 证明:
2222
// 一次 Union 操作只可能发生如下两种情况。
23-
// 1. 两棵树的高度相同,这样合并后的新树的高度等于较大那棵树的高度 +1。
24-
// 2. 两棵树的高度不同,这样合并后的新树高度等于较大那棵树的高度。
25-
//
26-
// 现在证明通过加权 quick-union 算法构造的高度为 h 的树至少包含 2^h 个结点。
27-
// 基础情况,高度 h=0, 结点数 k=1。
28-
// 为了使高度增加,必须用一棵高度相同的树合并,而 h=0 时结点数一定是 1,则:
29-
// h=1, k=2
23+
// 1.两棵树的高度相同,这样合并后的新树的高度等于较大那棵树的高度 + 1。
24+
// 2.两棵树的高度不同,这样合并后的新树高度等于较大那棵树的高度。
25+
26+
// 现在证明通过加权 quick-union 算法构造的高度为 h 的树至少包含 2 ^ h 个结点。
27+
// 基础情况,高度 h = 0, 结点数 k = 1。
28+
// 为了使高度增加,必须用一棵高度相同的树合并,而 h = 0 时结点数一定是 1,则:
29+
// h = 1, k = 2
3030
// 由于两棵大小不同的树合并,最大高度不会增加,只会增加结点数。
3131
// 因此,每次都使用相同高度的最小树进行合并,有:
32-
// h=2, k=4
33-
// h=3, k=8
34-
// h=4, k=16
32+
// h = 2, k = 4
33+
// h = 3, k = 8
34+
// h = 4, k = 16
3535
// ......
36-
// 递推即可得到结论,k >= 2^h
36+
// 递推即可得到结论,k >= 2 ^ h
3737
// 因此 h <= lgk
3838
}
3939
}

1 Fundamental/1.5/1.5.18/RandomBag.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace _1._5._18
66
{
77
/// <summary>
8-
/// 随即背包
8+
/// 随机背包
99
/// </summary>
1010
/// <typeparam name="Item">背包中要存放的元素。</typeparam>
1111
public class RandomBag<Item> : IEnumerable<Item>

1 Fundamental/1.5/1.5.23/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Program
1919
{
2020
static void Main(string[] args)
2121
{
22-
int n = 1000;
22+
int n = 2000;
2323
for (int t = 0; t < 5; ++t)
2424
{
2525
Connection[] input = ErdosRenyi.Generate(n);

1 Fundamental/1.5/1.5.24/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Program
1616
{
1717
static void Main(string[] args)
1818
{
19-
int n = 5000;
19+
int n = 10000;
2020
for (int t = 0; t < 5; ++t)
2121
{
2222
var input = ErdosRenyi.Generate(n);

1 Fundamental/1.5/1.5.25/Program.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class Program
2828
{
2929
static void Main(string[] args)
3030
{
31-
int n = 20;
32-
int t = 5;
31+
int n = 40;
32+
int t = 4;
3333

3434
// quick-find
3535
Console.WriteLine("Quick-Find");
@@ -56,7 +56,7 @@ static void Main(string[] args)
5656

5757
// quick-union
5858
Console.WriteLine("Quick-Union");
59-
n = 20;
59+
n = 40;
6060
for (int i = 0; i < t; ++i, n *= 2)
6161
{
6262
Console.WriteLine("N:" + n * n);
@@ -77,8 +77,8 @@ static void Main(string[] args)
7777
}
7878

7979
// 加权 quick-union
80-
Console.WriteLine("Quick-Union");
81-
n = 20;
80+
Console.WriteLine("Weighted Quick-Union");
81+
n = 40;
8282
for (int i = 0; i < t; ++i, n *= 2)
8383
{
8484
Console.WriteLine("N:" + n * n);
@@ -108,7 +108,7 @@ static void Main(string[] args)
108108
static long RunTest(UF uf, Connection[] connections)
109109
{
110110
Stopwatch timer = new Stopwatch();
111-
long repeatTime = 5;
111+
long repeatTime = 3;
112112
timer.Start();
113113
for (int i = 0; i < repeatTime; ++i)
114114
{

1 Fundamental/1.5/1.5.3/Program.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,10 @@ static void Main(string[] args)
2727
int[] parent = weightedQuickUnion.GetParent();
2828
for (int i = 0; i < parent.Length; ++i)
2929
{
30-
if (parent[i] == i)
31-
{
32-
Console.WriteLine("|---- " + i);
33-
DFS(parent, i, 1);
34-
}
30+
Console.Write(parent[i] + " ");
3531
}
3632
Console.WriteLine("数组访问:" + weightedQuickUnion.ArrayParentVisitCount);
3733
}
3834
}
39-
40-
static void DFS(int[] parent, int root, int level)
41-
{
42-
for (int i = 0; i < parent.Length; ++i)
43-
{
44-
if (parent[i] == root && i != root)
45-
{
46-
for (int j = 0; j < level; ++j)
47-
{
48-
Console.Write(" ");
49-
}
50-
Console.WriteLine("|---- " + i);
51-
DFS(parent, i, level + 1);
52-
}
53-
}
54-
}
5535
}
5636
}

1 Fundamental/1.5/UnionFind/ErdosRenyi.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace UnionFind
55
{
6+
/// <summary>
7+
/// 提供一系列对并查集进行随机测试的静态方法。
8+
/// </summary>
69
public class ErdosRenyi
710
{
811
/// <summary>

0 commit comments

Comments
 (0)