code: def _rsl_prims_balltree(
      X, k=5, alpha=1.4142135623730951, metric="euclidean", **kwargs
  ):
      # The Cython routines used require contiguous arrays
      if not X.flags["C_CONTIGUOUS"]:
          X = np.array(X, dtype=np.double, order="C")
  
      dim = X.shape[0]
      k = min(dim - 1, k)
  
      tree = BallTree(X, metric=metric, **kwargs)
  
      dist_metric = DistanceMetric.get_metric(metric, **kwargs)
  
      core_distances = tree.query(X, k=k)[0][:, -1].copy(order="C")
      min_spanning_tree = mst_linkage_core_vector(
          X, core_distances, dist_metric, alpha
      )
  
      single_linkage_tree = label(min_spanning_tree)
      single_linkage_tree = SingleLinkageTree(single_linkage_tree)
  
      return single_linkage_tree
  
imports: import numpy
  from sklearn.base import BaseEstimator, ClusterMixin
  from sklearn.metrics import pairwise_distances
  from scipy.sparse import issparse
  from joblib import Memory
  from sklearn.utils import check_array
  from ._hdbscan_linkage import mst_linkage_core, mst_linkage_core_vector, label
  from ._hdbscan_boruvka import KDTreeBoruvkaAlgorithm, BallTreeBoruvkaAlgorithm
  from .dist_metrics import DistanceMetric
  from ._hdbscan_reachability import mutual_reachability
  from .plots import SingleLinkageTree
  from sklearn.neighbors import KDTree, BallTree
  from warnings import warn
label_desc: Use image node_id 3 for calling a global function with example usage: _rsl_prims_balltree(X, k, alpha, metric) and returns: single_linkage_tree