double treeNodeSplitCost(treeNode node, Point centreA, Point centreB) {
        //loop counter variable
        int i;

        //stores the cost
        double sum = 0.0;

        for (i = 0; i < node.n; i++) {
            //loop counter variable
            int l;

            //stores the distance between p and centreA
            double distanceA = 0.0;

            for (l = 0; l < node.points[i].dimension; l++) {
                //centroid coordinate of the point
                double centroidCoordinatePoint;
                if (node.points[i].weight != 0.0) {
                    centroidCoordinatePoint = node.points[i].coordinates[l] / node.points[i].weight;
                } else {
                    centroidCoordinatePoint = node.points[i].coordinates[l];
                }
                //centroid coordinate of the centre
                double centroidCoordinateCentre;
                if (centreA.weight != 0.0) {
                    centroidCoordinateCentre = centreA.coordinates[l] / centreA.weight;
                } else {
                    centroidCoordinateCentre = centreA.coordinates[l];
                }

                distanceA += (centroidCoordinatePoint - centroidCoordinateCentre) *
                        (centroidCoordinatePoint - centroidCoordinateCentre);
            }

            //stores the distance between p and centreB
            double distanceB = 0.0;

            for (l = 0; l < node.points[i].dimension; l++) {
                //centroid coordinate of the point
                double centroidCoordinatePoint;
                if (node.points[i].weight != 0.0) {
                    centroidCoordinatePoint = node.points[i].coordinates[l] / node.points[i].weight;
                } else {
                    centroidCoordinatePoint = node.points[i].coordinates[l];
                }
                //centroid coordinate of the centre
                double centroidCoordinateCentre;
                if (centreB.weight != 0.0) {
                    centroidCoordinateCentre = centreB.coordinates[l] / centreB.weight;
                } else {
                    centroidCoordinateCentre = centreB.coordinates[l];
                }

                distanceB += (centroidCoordinatePoint - centroidCoordinateCentre) *
                        (centroidCoordinatePoint - centroidCoordinateCentre);
            }

            //add the cost of the closest centre to the sum
            if (distanceA < distanceB) {
                sum += distanceA * node.points[i].weight;
            } else {
                sum += distanceB * node.points[i].weight;
            }

        }

        //return the total cost
        return sum;

    }