Calling Circle Problem



As you are probably aware, various phone companies (e.g., MCI, AT&T) offer discounts to customers based on their "calling circle" (e.g., MCI's friends-and-family program). Their idea is, you determine your calling circle and you get a discount for each call placed to anyone in your circle. The way they actually produce discounts on your bill is to scan your monthly bill looking for conversations that occured within your circle.

Suppose we wish to examine phone records and "suggest" calling-circles to customers. We are going to define calling-circle in the following way. Suppose the records show that "Ali" talks to "Bill" (it doesn't matter who actually dials), "Bill" talks to "Chen", and "Dave" talks to "Ella". Then, we can identify two calling circles: "Ali-Bill-Chen" and "Dave-Ella". Thus, a calling circle includes pairs who may not have had a direct conversation, but linked via a sequence of conversations.

The starting template for this problem is CallingCircle.java.

Data will be provided in a 2D array of int's:


  static int findNumCallingCircles (int[][] conversations)
  {
    // conversations[i][j] == 1 if i has had a conversation with j.
    // conversations[i][j] == 0 otherwise.
  }

Start by writing pseudocode.