Class MaximumCardinalityIterator

java.lang.Object
org.graph4j.traversal.MaximumCardinalityIterator
All Implemented Interfaces:
IntIterator

public class MaximumCardinalityIterator extends Object implements IntIterator
Implements an iterator that performs Maximum Cardinality Search (MCS) algorithm on an undirected graph. MCS is a graph traversal algorithm which orders the vertices based on their cardinality in non-increasing order. The cardinality of a vertex is defined as the number of its neighbors, which have been already visited by this iterator. At each step, the iterator chooses a vertex with maximum cardinality, breaking ties arbitrarily.
Author:
Cristian Frăsinaru
  • Constructor Details

    • MaximumCardinalityIterator

      public MaximumCardinalityIterator(Graph graph)
      Creates an iterator starting with the first vertex of the graph (the one at index 0)
      Parameters:
      graph - the input graph.
    • MaximumCardinalityIterator

      public MaximumCardinalityIterator(Graph graph, int start)
      Creates an iterator starting with the specified vertex.
      Parameters:
      graph - the input graph.
      start - the start vertex number.
      Throws:
      InvalidVertexException - if the graph does not contain the start vertex.
  • Method Details

    • hasNext

      public boolean hasNext()
      Description copied from interface: IntIterator
      Returns true if the iteration has more elements.
      Specified by:
      hasNext in interface IntIterator
      Returns:
      true if the iteration has more elements, false otherwise.
    • next

      public int next()
      Description copied from interface: IntIterator
      Returns the next element in the iteration.
      Specified by:
      next in interface IntIterator
      Returns:
      the next element in the iteration.
    • currentVertexId

      public int currentVertexId()
    • cardinality

      public int cardinality()