1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
makkiz [27]
3 years ago
12

Barr the Bear has started a business to sell fish to Poe and his fellow penguins. The penguin customers submit many fish orders,

but Barr can only process one order at a time. Suppose that Barr currently has orders from n penguin customers (label them as 1, 2, . . . , n). Customer i’s order takes ti time to complete. Barr is going to process each penguin’s order one by one, and the scheduling of orders can be described as a permutation of the customers. Let Ci denote the completion time of order i. For instance, if customer j’s order is the first to be completed, then we would have Cj = tj (assume Barr begins processing orders at time 0); if customer k’s order is the second to be completed after that, then Ck = Cj + tk = tj + tk, and so on. Each customer is of different importance to Barr’s business, and we denote this relative weight by wi (for customer i). Barr wishes to minimize the weighted sum of the completion times of n orders, Pn i=1 wi · Ci . Intuitively, the more important a customer is, the sooner Barr wishes to complete the customer’s order. Design an O(n log n) algorithm to solve this problem to help Barr. You are given a set of n orders with a processing time ti and a weight wi for each customer i (assume ti , wi are positive integers). You want to decide an ordering of the customer orders so as to minimize the weighted sum of the completion times. Prove correctness of your algorithm (i.e., optimality) and analyze its runtime.
Computers and Technology
1 answer:
luda_lava [24]3 years ago
5 0

Answer:

Algorithm below designed using Java

Explanation:

import java.util.SortedMap;

import java.util.TreeMap;

import java.util.Vector;

public class SchedulingProblem {

static Vector<Integer> processTime = new Vector<>();

static Vector<Integer> processWeight = new Vector<>();

static SortedMap<Integer, Double> timeWeightRatio = new TreeMap<Integer, Double>() {

};

 

static int number = 2;

public static void main(String[] args) {

processTime.add(1);

processWeight.add(10);

processTime.add(3);

processWeight.add(2);

for (int i = 0; i < number; i++) { // O(N)

timeWeightRatio.put(i, processWeight.get(i) / (processTime.get(i) * 1.0)); // O(log(n))

}

// ------------ O(nlog(n))

int sum = 0, tmpTime = 0;

while (timeWeightRatio.size() > 0) { // O(n)

tmpTime += processTime.get(timeWeightRatio.firstKey()); // O(n)

sum += processWeight.get(timeWeightRatio.firstKey()) * tmpTime; // O(n)

System.out.print(processWeight.get(timeWeightRatio.firstKey()) + " * " + tmpTime + ((timeWeightRatio.size() > 1) ? " + " : " = " + sum));

timeWeightRatio.remove(timeWeightRatio.firstKey()); // O(log(n))

}

 

// >>>> O(nlog(n))

}

}

You might be interested in
Which of the following ""invisible"" marks represents an inserted tab?
Pachacha [2.7K]

Answer:

Easy peasy, if you open Microsoft word and you click up at the top and you click the symbol as shown in A, then you click on inserted tab it will show up as B which is  → symbol

So the answer is B  →.

4 0
3 years ago
Write a program that uses nested loop or for statements to display Pattern A below, followed by an empty line and then another s
JulsSmile [24]

Answer:

public class Pyramid {

   public static void main(String[] args) {

             int h = 7;

       System.out.println("Pattern A");

               for(int i = 1; i <= h; ++i)

               {

                   for(int j = 1; j <= i; ++j) {

                       System.out.print("+");

                   }

                   System.out.println();

               }

       System.out.println();

       System.out.println("Pattern B");

               for (int i = 1; i<=h; ++i)

               {

                 for(int j = h; j >=i; --j){

                     System.out.print("+");

                 }

                   System.out.println();

               }

           }

       }

Explanation:

  • The trick in this code is using a nested for loop
  • The outer for loop runs from i = 0 to the heigth of the triangle (in this case 7)
  • The inner for loop which prints the (+) sign runs from j = 0 to j<=i
  • It prints the + using the print() function and not println()
  • In the pattern B the loop is reversed to start from  i = height
8 0
2 years ago
Define online pollution
Elis [28]

Explanation:

E-Pollution is the environmental damage that comes from the constant heat and cooling down in facilities that are referred to data centers. Data centers are where online information is collected, processed, stored and exchanged.

4 0
2 years ago
What the benefit is of folder when working with files
Mariana [72]
It helps you keep things organized and easier to find files

3 0
3 years ago
Complete the concept map on computer as outlined below​
USPshnik [31]

Answer:

Here is your answer.

have a great day

6 0
2 years ago
Other questions:
  • I plugged my phone up into a charger, the charger sparked and i unplugged my phone and now it wont charge at all, does anyone kn
    13·1 answer
  • A database has a built-in capability to create, process and administer itself.
    14·1 answer
  • Using a caesar cypher with an offset of three characters (a -&gt; d, b -&gt;e, ...., z -&gt; c), what would be the correct cyphe
    6·1 answer
  • An example of an asset is:<br><br> A. Time<br> B. Money<br> C. A Car <br> D. All of the above
    5·2 answers
  • What is a functional organisation? and how it functions​?
    12·1 answer
  • Dominic list his camera for sale on an online auction site Chloe is the highest bitter and purchase as the camera how does the a
    14·1 answer
  • Question 1 of 10 Which type of information systems personnel are involved in organizing information so that users can access it
    7·1 answer
  • How has the widespread shift to remote work caused businesses to reconsider their use of Extended Reality (XR)?.
    13·1 answer
  • When a computer is infected by a virus, _______.
    14·1 answer
  • before you start researching fleet management software, your first task is to clearly define the problem. this will help guide y
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!