private static void Compute() { var size = 200; var quickFind = new QuickFindUf(size); var quickUnion = new QuickUnionUf(size); var weightedQuickUnion = new WeightedQuickUnionUf(size); var connections = ErdosRenyi.Generate(size); var quickFindResult = new int[size]; var quickUnionResult = new int[size]; var weightedQuickUnionResult = new int[size]; int p, q; for (var i = 0; i < size; i++) { p = connections[i].P; q = connections[i].Q; quickFind.Union(p, q); quickUnion.Union(p, q); weightedQuickUnion.Union(p, q); quickFindResult[i] = quickFind.ArrayVisitCount; quickUnionResult[i] = quickUnion.ArrayVisitCount; weightedQuickUnionResult[i] = weightedQuickUnion.ArrayParentVisitCount + weightedQuickUnion.ArraySizeVisitCount; quickFind.ResetArrayCount(); quickUnion.ResetArrayCount(); weightedQuickUnion.ResetArrayCount(); } Draw(quickFindResult, "Quick-Find"); Draw(quickUnionResult, "Quick-Union"); Draw(weightedQuickUnionResult, "Weighted Quick-Union"); }
private static void Compute() { char[] split = { '\n', '\r' }; var input = File.ReadAllText(DataFiles.MediumUf).Split(split, StringSplitOptions.RemoveEmptyEntries); var size = int.Parse(input[0]); var quickFind = new QuickFindUf(size); var quickUnion = new QuickUnionUf(size); string[] pair; int p, q; var quickFindResult = new int[size]; var quickUnionResult = new int[size]; for (var i = 1; i < size; i++) { pair = input[i].Split(' '); p = int.Parse(pair[0]); q = int.Parse(pair[1]); quickFind.Union(p, q); quickUnion.Union(p, q); quickFindResult[i - 1] = quickFind.ArrayVisitCount; quickUnionResult[i - 1] = quickUnion.ArrayVisitCount; quickFind.ResetArrayCount(); quickUnion.ResetArrayCount(); } Draw(quickFindResult); Draw(quickUnionResult); }