static void Main(string[] args)
        {
            int N = 10;

            int[] edges = new int[5];
            for (int i = 0; i < 5; i++)
            {
                var uf = new UF(N);
                Console.WriteLine(N + "\t" + ErdosRenyi.Count(uf));
                N *= 10;
            }
        }
Beispiel #2
0
        /// <summary>
        /// 进行若干次随机试验,输出平均 union 次数,返回平均耗时。
        /// </summary>
        /// <param name="uf">用于测试的并查集。</param>
        /// <param name="connections">用于测试的输入。</param>
        /// <returns>平均耗时。</returns>
        static long RunTest(UF uf, Connection[] connections)
        {
            var timer      = new Stopwatch();
            var repeatTime = 5;

            timer.Start();
            for (var i = 0; i < repeatTime; i++)
            {
                ErdosRenyi.Count(uf, connections);
            }
            timer.Stop();

            return(timer.ElapsedMilliseconds / repeatTime);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            for (int n = 10; n < 10000; n *= 2)
            {
                int total = 0;
                for (int i = 0; i < 100; i++)
                {
                    UF uf = new UF(n);
                    total += ErdosRenyi.Count(uf);
                }

                Console.WriteLine("实验结果:" + total / 100);
                Console.WriteLine("1/2NlnN:" + Math.Log(n) * n * 0.5);
                Console.WriteLine();
            }
        }
        /// <summary>
        /// 进行若干次随机试验,输出平均 union 次数,返回平均耗时。
        /// </summary>
        /// <param name="uf">用于测试的并查集。</param>
        /// <returns>平均耗时。</returns>
        static long RunTest(UF uf)
        {
            Stopwatch timer      = new Stopwatch();
            int       total      = 0;
            int       repeatTime = 10;

            timer.Start();
            for (int i = 0; i < repeatTime; i++)
            {
                total += ErdosRenyi.Count(uf);
            }
            timer.Stop();
            Console.WriteLine("平均次数:" + total / repeatTime);

            return(timer.ElapsedMilliseconds / repeatTime);
        }