@graphty/algorithms
Version:
Graph algorithms library for browser environments implemented in TypeScript
64 lines • 2.03 kB
TypeScript
/**
* K-Core Decomposition Algorithm
*
* Finds the k-core subgraph where each node has at least k neighbors
* within the subgraph. Used for identifying cohesive groups and
* understanding graph structure.
*/
import type { Graph } from "../core/graph.js";
export interface KCoreResult<T> {
cores: Map<number, Set<T>>;
coreness: Map<T, number>;
maxCore: number;
}
/**
* Extract the k-core subgraph
* Returns nodes that belong to k-core or higher
*
* @param graph - Undirected graph
* @param k - Core number
* @returns Set of nodes in k-core or higher
*/
export declare function getKCore(graph: Graph, k: number): Set<string>;
/**
* Get the induced subgraph for k-core
* Returns the actual subgraph containing only k-core nodes
*
* @param graph - Original graph
* @param k - Core number
* @returns K-core subgraph
*/
export declare function getKCoreSubgraph(graph: Graph, k: number): Map<string, Set<string>>;
/**
* Degeneracy ordering of the graph
* Orders nodes by their coreness values
*
* @param graph - Undirected graph
* @returns Array of nodes ordered by degeneracy
*/
export declare function degeneracyOrdering(graph: Graph): string[];
/**
* Find k-truss subgraph (triangular k-cores)
* Each edge must be part of at least k-2 triangles
*
* @param graph - Undirected graph
* @param k - Truss number (k >= 2)
* @returns Edges in k-truss
*/
export declare function kTruss(graph: Graph, k: number): Set<string>;
/**
* Convert directed graph to undirected for k-core analysis
*/
export declare function toUndirected<T>(directedGraph: Map<T, Map<T, number>>): Map<T, Set<T>>;
/**
* K-Core decomposition algorithm
* Finds all k-cores in the graph and assigns coreness values to nodes
*
* @param graph - Undirected graph - accepts Graph class or Map<T, Set<T>>
* @returns K-core decomposition results
*
* Time Complexity: O(V + E)
* Space Complexity: O(V)
*/
export declare function kCoreDecomposition(graph: Graph): KCoreResult<string>;
//# sourceMappingURL=k-core.d.ts.map