public ArrayList<Edge> kruskalAlg() {

        ArrayList<Edge> mst = new ArrayList<Edge>();
        
        while (mst.size() < this.cells.size() - 1) {
            
            //Select a random edge from the list of edges
            Random rand = new Random();
            Edge randEdge = this.edges.get(rand.nextInt(this.edges.size()));

            // Get the indexes of the random edge
            int indexFrom = this.cells.indexOf(randEdge.from);
            int indexTo = this.cells.indexOf(randEdge.to);

            // If the representative of indexFrom and indexTo are
            // not equal, union them and add the edge to the spanning tree
            if (this.findRep(indexFrom) != this.findRep(indexTo)) {
                this.union(indexFrom, indexTo);
                mst.add(randEdge);
            }

            // Remove the added edge so it doesn't get picked again
            this.edges.remove(randEdge);
        }
        return mst;
    }