Polygon from a grid of squares?

I'm looking for an algorithm to find the polygon that surrounds a contiguous grid of squares without holes as shown ...

Algorithm for diameter of graph??

If you have a graph, and need to find the diameter of it (which is the maximum distance between two nodes), how can ...