You are the CEO of a company with an unorthodox organizational...

Question

# You are the CEO of a company with an unorthodox organizational...

You are the CEO of a company with an unorthodox organizational structure. In particular, the company is organized like a binary tree with you as the root node. Each employee has exactly one direct supervisor, and no employee is his/her own direct or indirect supervisor. Every supervisor has at most two direct subordinates. You need to convey some news to all the employees in the organization, so you decide to take the following approach: you place a phone call to each of your direct subordinates, one at a time. After hearing the news, each subordinate notifies his/her direct subordinates, one at a time. This process continues until everyone in the organization has heard the news. Every person only calls their direct subordinates, though multiple phone calls (in different subtrees) may be taking place simultaneously. Each phone call takes exactly one minute. Your task on this problem is to determine the minimum amount of time required, in minutes, for the news to spread to the entire office. Complete the method named getSpreadTime in Office.java that solves the problem described above. This method takes an int[][] parameter named tree that describes the organizational structure of the office. Employees are numbered starting at 1, while you, the CEO, are employee 0. The number of a supervisor is always lower than that of his/her direct subordinates. The i th element in tree (i.e., tree[i]) is itself a two element array; tree[i][0] contains the number of thefirst subordinate (the left-hand person) and tree[i][1] contains the number of the second subordinate (right-hand person). A missing subordinate is indicated with a −1. The method should return as an int the minimum number of minutes required for the news to be conveyed to all the employees in the given organization.

Notes and Constraints • You can assume that the input parameter tree will always contain at least one element (i.e., tree.length ≥ 1). Further, every element in tree will itself be an int[] of length 2. • Since subordinates always have higher numbers than their supervisors, the elements of the array tree[i] will always be greater than i (except for the special value −1 that indicates a missing subordinate). • Place all test code in main which is the only method that is allowed to print any output to the console.

Examples In each of the following, you may find it helpful to first sketch out the tree that is given. 1. tree = {{1, 2},{-1, -1}, {-1, -1}} Returns: 2 You call subordinate 1 at time 0 and then subordinate 2 at time 1. Neither of those subordinates has any subordinates of their own. By time 2, both subordinates will have heard the news.

2. tree = {{1, 2}, {-1, -1}, {3, 4}, {-1, -1},{-1, -1}} Returns: 3 This time, call employee 2 first, and then employee 1 at time 1. After hearing the news, employee 2 will call employee 3 at time 1 and employee 4 at time 2. It takes 3 minutes for everybody to hear the news.

3. tree = {{-1, 1}, {2, -1}, {-1, 3}, {4, -1}, {-1, -1}} Returns: 4 Everyone has only one subordinate, resulting in a chain of phone calls.

4. tree = {{1, 2}, {3, 4}, {5, 6}, {-1, -1}, {7, -1}, {8, 9}, {-1, -1}, {10, -1}, {-1, 11}, {12, -1}, {-1, -1}, {-1, -1}, {13, 14}, {-1, -1}, {-1, -1}} Returns: 6

Complete

/** Program for determining the time it would take for news to propagate through

* an office heirarchy.

*

*

*/

public class Office {

/** Returns the time it would take for news to be relayed through the given

* office heirarchy.

*

* @param tree a 2d integer array where the entry at element i is a two-

*             element array; the first element is the id (index) of the

*             left child and the second element is the id (index) of the

*             right child.

*

* @return the time it would take for the news to be relayed to all the

*         employees in the organization.

*/

public static int getSpreadTime(int[][] tree) {

// COMPLETE ME!

return 0; // placeholder

}

/** Tester method. */

public static void main(String[] args) {

int[][] heirarchy1 = {{1, 2}, {-1, -1}, {-1, -1}};

int[][] heirarchy2 = {{1, 2}, {-1, -1}, {3, 4}, {-1, -1}, {-1, -1}};

int[][] heirarchy3 = {{-1, 1}, {2, -1}, {-1, 3}, {4, -1}, {-1, -1}};

int[][] heirarchy4 = {{1, 2}, {3, 4}, {5, 6}, {-1, -1}, {7, -1},

{8, 9}, {-1, -1}, {10, -1}, {-1, 11}, {12, -1},

{-1, -1}, {-1, -1}, {13, 14}, {-1, -1},

{-1, -1}};

}

}

Solved by verified expert

sec

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dap

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec faci

10,000 step-by-step explanations

## Step-by-step explanation

• sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet.
• sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adi

sectetur adipiscing elit. Nam lacinia pulvinar tor
sectetur adipiscing elit. Nam lacinia pulvin
sectetur adipiscing elit. Nam lacinia pulvinar
sectetur adipiscing elit. Nam lacinia pulvinar torto
sectetur adipiscing elit. Nam lacinia pulvinar tortor nec fa

10,000 step-by-step explanations

## Step-by-step explanation

• sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie
• sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a moles
• sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fu

sec
s
secte
sectet
secte
sectet
sectetur

• sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus
• sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ult
• sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam ris
• sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, cons