网络中最大的连接组件

Biggest connected component in network

我有一个包含源-目标节点的大文本文件 (20 GB) 文件,并且 threshold.If 阈值 > 0 已连接,否则 connected.I 不想在数组或数组中添加连接的节点list(哪个适合数据量大的?)和找巨人连接component.I觉得BFS算法是最短路径的一种解决方法

文本文件

100 101 -0.3434
100 102  1.0023
100 103  1.100
103 104  0.210
...

我的代码:

String line = null;
HashMap<Integer,ArrayList<Node>> arr = new HashMap<Integer,ArrayList<Node>>();
BufferedReader reader = new BufferedReader(new FileReader("C:/Users/UserPC/Desktop/output.txt"));
        while((line = reader.readLine()) != null){
            String[] spl = line.split("\s+");
            //System.out.println(spl[0]+","+spl[1]);
            int source = Integer.parseInt(spl[0]);
            int target = Integer.parseInt(spl[1]);


            arr.computeIfAbsent( source, k -> new ArrayList<>()).add(new Node(target));

        } 

        reader.close();

20 GB 将花费太多时间,如果你没有正确地实现它们顺便说一下,你可以考虑一个图形数据结构,然后你通过调整权重应用最小生成树算法,这样它只找到权重小于或大于的节点一定的价值。

步骤: 步骤1: 制作包含源节点、目的地和 weight/threshold.

的一维包数组
    step 1:
    private Bag<Integer>[] array = (Bag<Integer>[]) new Bag[V];
    for all indexes:
    array[i] = new Bag<Integer>();

创建一个 class,表示您的组件已连接,它们的阈值是多少:调用已连接。

int firstNode = readIn via scanner.
int secondNode = readIn.
Int thresHold = read;
Connected connected = new Conncted(firstNode,secondNode,threshold);



    add all these connected component into array of bag so you have a graph then use minimumspanning tree or anyother algorithm, there are many.