Questions & AnswersJava Programming

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

Question
Answered step-by-step
Asked by DrUniverse8675 on coursehero.com

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}};

        System.out.println(getSpreadTime(heirarchy1)); // should print 2

       

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

        System.out.println(getSpreadTime(heirarchy2)); // should print 3

       

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

        System.out.println(getSpreadTime(heirarchy3)); // should print 4

       

        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}};

        System.out.println(getSpreadTime(heirarchy4)); // should print 6    

    }    

}

Answer & Explanation

Solved by verified expert
Answered by AgentDragonflyPerson731 on coursehero.com

sectetur adipiscing e

sec

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

sectetur adipiscing elit. Nam lac

sectetur adip

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

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec faci
CliffsNotes Logo

Unlock access to this and over
10,000 step-by-step explanations

Unlock Explanation

Have an account? Log In

sectetur adipiscing<p></p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapi</p><p>sectetur adipiscing elit. Nam lacinia pu</p><p>sectetur</p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentes</p><p>sectetur adipiscing elit. Nam lacinia pulvinar torto</p><p>sectetur a</p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facili</p><p>sectetur adipiscing elit.</p><p>sectetur adipiscing elit</p><p>sectetur adipiscing eli</p><p>sectetur adipiscing elit. Nam lac</p><p>sectetur adipiscing elit.</p><p>sectetur adi</p><p>sectetur adipiscing elit. Na</p><p>sectetur adipiscing elit. Nam lacinia pulvinar to</p><p>sectetur adipiscing elit. Nam</p><p>sectetur adipiscing elit. Nam lacinia p</p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam ri</p><p>sectetur adipiscin</p><p>sectetur adipiscing elit. Nam l</p><p>sectetur adipiscing elit. Nam lacinia p</p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam ri</p><p>sectetur adipiscin</p><p>sectetur adi</p><p>sectetur adipiscing eli</p><p>sectet</p><p><br/> </p><p> </p><p>sectetur adipiscing elit.</p><p>sectetur adipiscing elit. Nam lacinia pulvina</p><p>     </p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec fac</p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellen</p><p>     </p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesq</p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellen</p><p>     </p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesq</p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellen</p><p>     </p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellen</p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus e</p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque d</p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor</p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque</p><p>sectetur adi</p><p>s</p>

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

Other answer

Answered by debaudenangelica718 on coursehero.com


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

CliffsNotes Logo

Unlock access to this and over
10,000 step-by-step explanations

Unlock Explanation

Have an account? Log In

<p>sectetur adipiscing elit. Nam lacinia p<br/>sectetur adipiscing<br/>sectet<br/>sectetur adipiscing el<br/>sectetur adipiscing eli<br/>sectetur adipiscing elit. Nam la<br/>sectetur adipiscing elit. Nam lacinia pulvinar torto<br/>sectet<br/>sectetur adipiscing elit. Nam la<br/>sectetur adipiscing elit. Nam lacinia pulvinar tortor<br/>sectet<br/>sectetur adipiscing elit. Nam lacinia pulvinar<br/>s</p><p>sectetur adipi<br/>sectetur adipiscing elit. Nam lacinia pu<br/>sectetur adipiscing elit. Nam lacinia pulvinar tortor n<br/>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis.</p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pell<br/>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis.</p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pell<br/>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis.</p><p>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pe<br/>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapib<br/>sectetur adipiscing elit. Nam lacinia pulvinar tor<br/>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis.<br/>s</p><p>sectetur<br/>s<br/>s<br/>s<br/>s</p>

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

Get unstuck with a CliffsNotes subscription

Example CliffsNotes Question and Answer
Unlock every step-by-step explanation, download literature note PDFs, plus more.Get Access

Related Q&A