public static List<Graph.Edge> minimumSpanningTree(Graph g, int sourceVertex) {
        Set<Integer> mould = new HashSet<>();
        Set<Integer> universe = new HashSet<>();
        universe.addAll(g.getAllVertex());

        List<Graph.Edge> minimumSpanningTree = new ArrayList<>();


        mould.add(sourceVertex);
        universe.remove(sourceVertex);


        PriorityQueue<Graph.Edge> heap = new PriorityQueue<>(universe.size(),new Comparator<Graph.Edge>(){

            @Override
            public int compare(Graph.Edge e1, Graph.Edge e2) {

                return Integer.compare(e1.weight, e2.weight);
            }
        });

        while(!universe.isEmpty()) {
            // go through all the vertices of the mould
            for(int vertex: mould){
                // check all outgoing edges

                for(Graph.Edge edge: g.getEdges(vertex)) {
                    // add the edge which is not targeting to a edge present in the mould
                    if(!mould.contains(edge.to)){
                        heap.add(edge);
                    }
                }
            }



            //this will find the next edge to be included which has minimum shortest Cost till origin +weight
            //remove it from the heap
            Graph.Edge target = null;
            //get the edge which has minimum cost and which goes to a destination not already in mould.
            while(true) {
                target = heap.remove();
                if(!mould.contains(target.to)){
                    break;
                }

            }


            // remove the target vertex from universe
            universe.remove(target.to);
            // add it to mould
            mould.add(target.to);

            //update the minimum spanning tree
            minimumSpanningTree.add(target);


        }

        return minimumSpanningTree;
    }