%%%%%%% 
% find_diam.m
% Author: Lance Harden, Davidson College
% July 2006
% 
% Description: Given an adjacency matrix, adj, find_diam computes the
% diameter of the associated graph.

function [diam] = find_diam(adj)

b = length(adj);
runningor = zeros(b);
runningproduct = eye(b);
ipower = 0;

while ((b^2 - sum(sum(runningor))) ~= 0)
    ipower = ipower + 1;
    runningproduct = runningproduct * adj;
    runningor = runningor | runningproduct;
end

diam = ipower;
