function to start minimizing gaddag by computing depths