All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gr.james.simplegraph.examples.MaximumDegree Maven / Gradle / Ivy

Go to download

Simple Graph is a graph interface for Java 6 that is designed to expose a very simple API to support working with graphs

The newest version!
package gr.james.simplegraph.examples;

import gr.james.simplegraph.Graph;

/**
 * Get the maximum degree in a {@link Graph}.
 */
public final class MaximumDegree {
    private MaximumDegree() {
    }

    /**
     * Get the maximum degree in a {@link Graph}.
     * 

* Returns {@code -1} if the graph has no vertices. Returns {@code 0} if the graph has at least one vertex but no * edges. The degree of a vertex includes a self-loop, if present. *

* Complexity: O(V) * * @param g the graph * @return the maximum degree in {@code g} * @throws NullPointerException if {@code g} is {@code null} */ public static int maximumDegree(Graph g) { int max = -1; for (int i = 0; i < g.size(); i++) { final int degree = g.adjacent(i).size(); if (degree > max) { max = degree; } } return max; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy