Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE USE THIS CODE: import java.util.*; public class HW8_1 { public static void main(String[] args) { // create a solution instance Solution sol = new

image text in transcribed


PLEASE USE THIS CODE:  import java.util.*; public class HW8_1 {     public static void main(String[] args) {        // create a solution instance        Solution sol = new Solution();        // create a random binary tree of your choice        BSTNode tree = new BSTNode(3);        tree.left    = new BSTNode(0);        tree.right   = new BSTNode(0);        // your solution method will be tested with        // a random tree of your choice        System.out.println(sol.distribute(tree)); // 2     } }  // =============================================== // DO NOT MODIFY TREE BELOW THIS LINE // =============================================== class BSTNode {    int val;    BSTNode left;    BSTNode right;    BSTNode(int x) { val = x; } }  // =============================================== // DO NOT MODIFY TREE ABOVE THIS LINE // ===============================================  class Solution {    // YOUR MAY ADD ANY GLOBAL VARIABLES,    // HELPER METHODS, etc., in this class    /**    * PURPOSE:    * PARAMETERS:    * RETURN VALUES:    */    public int distribute(BSTNode root) {       // YOUR CODE HERE    } }
 image text in transcribedimage text in transcribed

The COVID-19 pandemic situation has challenged the medical equipment supply chain leading to an uneven distribution of personal protective equipments (PPEs) at local hospitals. Assuming the following: . These hospitals are represented as nodes (of type BSTNode) in a binary tree. There are N number of hospitals. There are N number of PPES. Even distribution means each hospital receives 1 PPE (in real situation, this 1 PPE can be 1 truck load of PPES but we are using 1 PPE to simplify this problem). To solve the supply chain logistic, you are asked to write a quick software to output the number of moves required to evenly distribute PPES amongst the hospitals such that each receives 1 PPE. For example you may have an initial distribution map looking like so: 3 1 /\ -----> 0 0 1 1 For brevity the above tree can be flattened level-order-wide in an array as [3,0,0]. The resulting tree is [1,1,1]. The above initial distribution requires TWO (2) moves to arrive at an even distribution with each node receiving 1 PPE, namely, 1 PPE going from root -> root.left, and another PPE from root -> root.right. You will start with the following code template.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

To solve this problem we can perform a postorder traversal of the binary tree starting from the leaf nodes and recursively pass the excess PPEs up the tree until the root node At each node we calculat... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Operations Management Processes And Supply Chains

Authors: Lee Krajewski, Naresh Malhotra, Larry Ritzman

13th Global Edition

129240986X, 978-1292409863

More Books

Students also viewed these Programming questions