Given a network of industrial machines, implement an algorithm to detect cycles and explain the time and space complexity.