DBSCAN
DBSCAN (Density-Based Spatial Clustering of Applications with Noise) is a non-parametric unsupervised clustering algorithm that groups points into maximally connected high-density regions of arbitrary shape while labeling isolated points in low-density regions as noise.
DBSCAN (Density-Based Spatial Clustering of Applications with Noise) is a foundational non-parametric clustering and outlier-detection algorithm in computation and algorithms, spatial data mining, and machine learning, introduced by Martin Ester, Hans-Peter Kriegel, Jรถrg Sander, and Xiaowei Xu in 1996. Unlike centroid-based methods such as k-means clustering, which partition every point into one of k convex Voronoi diagram cells and require specifying the number of clusters k in advance, DBSCAN defines clusters as maximal density-connected sets of points separated by lower-density background regions.
Because DBSCAN grows clusters transitively through local neighborhood graphs rather than optimizing a global parametric centroid objective, it simultaneously discovers non-convex, elongated, or ring-shaped structures, determines the number of clusters automatically from two local density thresholds, and classifies isolated observations in sparse regions as explicit noise (outliers). In 2014, DBSCAN received the ACM SIGKDD Test of Time Award for its lasting impact across geographic information systems (GIS), astronomical sky surveys, single-cell transcriptomics, and LiDAR point-cloud segmentation.
Core Definitions and Density-Connectivity Graph
Let X = {x1, x2, โฆ, xn} be a dataset equipped with a distance metric d(p, q) (such as Euclidean distance, cosine distance, or Levenshtein distance). DBSCAN is governed by two hyperparameters: a neighborhood radius ฮต > 0 and a minimum point count MinPts โ โ. For every point p โ X, its closed ฮต-neighborhood is defined as:
Nฮต(p) = { q โ X : d(p, q) โค ฮต }.
Based on the cardinality |Nฮต(p)|, every point in X falls into one of three topological roles:
- Core point: A point p โ X is a core point if its ฮต-neighborhood contains at least MinPts points (including p itself): |Nฮต(p)| โฅ MinPts.
- Directly density-reachable & Border point: A point q is directly density-reachable from a point p if q โ Nฮต(p) and p is a core point. A non-core point b (with |Nฮต(b)| < MinPts) that lies inside Nฮต(p) of at least one core point p is called a border point.
- Noise (outlier) point: Any point z โ X that is neither a core point nor directly density-reachable from any core point is classified as noise.
Density-Reachability vs. Density-Connectivity
A point q is density-reachable from p if there exists a chain of points p1, p2, โฆ, pm with p1 = p and pm = q such that each pi+1 is directly density-reachable from pi (meaning p1, โฆ, pmโ1 must all be core points). Because q may be a border point, density-reachability is transitive but asymmetric. To obtain a symmetric relation, two points p and q are defined as density-connected if there exists a core point o โ X from which both p and q are density-reachable. A DBSCAN cluster C โ X is then defined as a non-empty subset satisfying both maximality (if p โ C and q is density-reachable from p, then q โ C) and connectivity (all pairs p, q โ C are density-connected).
Algorithmic Execution and Spatial Indexing Complexity
DBSCAN traverses X via breadth-first search over the core-point neighborhood graph:
- Iterate through each unvisited point p โ X and mark p as visited.
- Execute a range query to retrieve Nฮต(p). If |Nฮต(p)| < MinPts, provisionally label p as NOISE (note that p may later be claimed as a border point by an adjacent core point).
- If |Nฮต(p)| โฅ MinPts, create a new cluster C, add p to C, and initialize a seed queue Q โ Nฮต(p) \ {p}.
- While Q is non-empty, pop a point q from Q: if q was previously labeled NOISE, relabel q as a border member of C; if q was unvisited, mark q visited, assign q to C, query Nฮต(q), and if |Nฮต(q)| โฅ MinPts append all unqueued members of Nฮต(q) to Q.
Because DBSCAN performs exactly one ฮต-range query per point p โ X, its total time complexity is n ร Trange. Without a spatial index, scanning all n points per query takes O(n2) time. When low-dimensional coordinates (d โค 20) are indexed in an R*-tree, k-d tree, ball tree, or Delaunay triangulation neighborhood graph, average-case runtime drops to O(n log n) with O(n) memory.
| Density / Partitioning Method | Handles Non-Convex Shapes | Handles Varying Cluster Densities | Determinism on All Points | Typical Time Complexity |
|---|---|---|---|---|
| Standard DBSCAN | Yes | No (single global ฮต) | Core & noise deterministic; border order-dependent | O(n log n) indexed; O(n2) dense |
| DBSCAN* (Core-Only) | Yes | No (single global ฮต) | 100% deterministic (borders treated as noise) | O(n log n) |
| OPTICS (Ordering Points) | Yes | Yes (reachability dendrogram) | Deterministic ordering | O(n log n) |
| HDBSCAN (Hierarchical) | Yes | Yes (mutual reachability MST) | Deterministic hierarchy stability | O(n log n) to O(n2) |
| k-Means Clustering | No (convex Voronoi only) | Poor | Initialization-dependent | O(nkd) per step |
Parameter Selection, Determinism, and Hierarchical Extensions (OPTICS & HDBSCAN)
Choosing MinPts and the k-Distance Knee Plot
Ester et al. and subsequent high-dimensional analyses (Schubert et al., 2017) recommend setting MinPts โฅ d + 1, with MinPts = 2d as a robust default for noisy datasets of dimension d (and MinPts = 4 for 2D spatial data). Once MinPts is fixed, the radius ฮต is selected by computing the distance dk(p) from each point p โ X to its (MinPts โ 1)-th nearest neighbor, sorting these distances in ascending order, and locating the "knee" or "elbow" where the sorted k-distance curve bends sharply upward from compact intra-cluster spacing to sparse background noise.
Border-Point Ambiguity, OPTICS, and HDBSCAN
Restricted to core points and noise points, DBSCAN is deterministic: core points form connected components of the undirected symmetric graph on {p : |Nฮต(p)| โฅ MinPts} with edges d(p, q) โค ฮต. Only border points within distance ฮต of two clusters can change membership depending on iteration order; DBSCAN* (Campello et al., 2013) eliminates this ambiguity by defining only core points as cluster members.
When a dataset contains clusters of varying densities, no single global radius ฮต resolves dense sub-clusters without splitting sparse clusters into noise. OPTICS (Ankerst et al., 1999) orders points by their core distance and reachability distance across all scales ฮต, while HDBSCAN (Campello, Moulavi, & Sander, 2013) builds the minimum spanning tree of the mutual reachability distance dmreach(p, q) = max{corek(p), corek(q), d(p, q)} and extracts persistent clusters using a single minimum-cluster-size hyperparameter.
Frequently Asked Questions
Why does DBSCAN setting MinPts = 2 reduce to single-linkage hierarchical clustering?
When MinPts = 2 (or MinPts = 1), every point with at least one neighbor within distance ฮต is a core point. The DBSCAN clusters then coincide with the connected components of the ฮต-neighborhood graph, which matches cutting a single-linkage hierarchical clustering dendrogram at height ฮต.
How does the curse of dimensionality affect DBSCAN?
In high-dimensional Euclidean spaces (d โซ 50), pairwise Euclidean distances concentrate around their mean (limdโโ (dmax โ dmin)/dmin โ 0), flattening density contrast. Applying principal component analysis or UMAP dimensionality reduction, or switching from Euclidean distance to cosine or shared-nearest-neighbor (SNN) similarity, restores density separation.
References
- Ester, M., Kriegel, H.-P., Sander, J., & Xu, X. (1996). A density-based algorithm for discovering clusters in large spatial databases with noise. Proceedings of the Second International Conference on Knowledge Discovery and Data Mining (KDD-96), 226โ231. https://doi.org/10.5555/3001460.3001507
- Ankerst, M., Breunig, M. M., Kriegel, H.-P., & Sander, J. (1999). OPTICS: Ordering points to identify the clustering structure. ACM SIGMOD Record, 28(2), 49โ60. https://doi.org/10.1145/304181.304187
- Campello, R. J. G. B., Moulavi, D., & Sander, J. (2013). Density-based clustering based on hierarchical density estimates. Advances in Knowledge Discovery and Data Mining (PAKDD 2013), 160โ172. https://doi.org/10.1007/978-3-642-37456-2_14
- Schubert, E., Sander, J., Ester, M., Kriegel, H. P., & Xu, X. (2017). DBSCAN revisited, revisited: Why and how you should (still) use DBSCAN. ACM Transactions on Database Systems, 42(3), 19:1โ19:21. https://doi.org/10.1145/3068335