How do I find depth and height of all nodes in a bounded semilattice? I'm writing a program where I have a bounded semilattice (it has a root element at the top, all edges point downwards, and a node may have multiple parents). I need to precompute each node's depth (the max number of edges from the root node) and height (the max number of edges to any leaf). I have a naive implementation for just the heights where every node is compared to all it's descendants, so probably O(n^2). What is a faster algorithm that computes both height and depth?
If you do a topological sort and then traverse the nodes in reverse topologically sorted order, you can annotate each node with its height in linear time.  Similarly, you can annotate each node with its depth in linear time by traversing in topologically sorted order.  This achieves linear running  time, which is significantly faster than the quadratic time approach you mention.