public static <T> node_t<T> has_cycle(node_t<T> head) {
    node_t<T> fast = head;
    node_t<T> slow = head;

    while (slow != null && slow.next != null && fast != null 
                        && fast.next != null && fast.next.next != null) {
      slow = slow.next;
      fast = fast.next.next;
      if (slow == fast) {  // there is a cycle.
        // Calculates the cycle length.
        int cycle_len = 0;
        do {
          ++cycle_len;
          fast = fast.next;
        } while (slow != fast);

        // Tries to find the start of the cycle.
        slow = head;
        fast = head;
        // Fast pointer advances cycle_len first.
        while (cycle_len-- > 0) {
          fast = fast.next;
        }
        // Both pointers advance at the same time.
        while (slow != fast) {
          slow = slow.next;
          fast = fast.next;
        }
        return slow;  // the start of cycle.
      }
    }
    return null;  // no cycle.
  }