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
Scorpion4ik [409]
3 years ago
14

Papa Mario of Mario's Pizzeria has baked a huge pizza and cut it into n slices, but he is clumsy and the pizza wasn't evenly sli

ced. Then slices have size S1, S2,.....Sn. There are n hungry students who each want to eat a slice of pizza. Suppose the ith student would be happy with any slice whose size is at least t,. Give an efficient algorithm to determine whether it is possible to distribute the pizza slices so everyone is happy
(a) What algorithm paradigm is most appropriate for this problem?
A. Divide-and conquer
B. Greedy algorithm
C. Dynamic Programming
D. Linear Programming
E. Graph Algorithm
F. None of these

b) Verbally describe an efficient algorithm to solve this problem
(c) What is the asymptotic running time of your algorithm?
Computers and Technology
1 answer:
rosijanka [135]3 years ago
3 0

Suppose there are n student: 1, 2, 3, ..., i, ..., n.

Now, let's say each want slice size to be: t1, t2, ..., ti, ..., tn.

Let's pizza slices be : s1, s2, ..., si, ..., sn.

Now, it can be said that a student ' i ' will accept a slice of pizza ' si ' only if the size of slice is more then ' ti '.

Logic to distribute: what can be done is we can sort the demand i.e ti of students and also sort the size of pizza slices si. Now, Papa Mario can distribute the sorted slices to students sorted demand(smallest to heighest) one by one as they appear in sorted lists. Now, it will only be possible to distribute the slices to make everyone happy, if and only if in sorted lists of both s and t for each index k, it holds the condition: tk <= sk.

Let me explain you with example:

Lets says size of whole pizza is 100.

Now number of students n = 4.

Let there demands be : 20, 35, 15, 10.

This means 1st student atleast require the slice size of 20 and so on.

Case 1: Papa Mario divides the pizza into slices of size: 25, 20, 20, 35.

=> Now, we sort both lists.

Thus t => 10, 15, 20, 35

and s => 20, 20, 25, 35

Now, as we can see that for all index  tk <= sk, hence pizza can be distrubeted so that everyone can be happy.

Case 2: Papa Mario divides the pizza into slices of size: 30, 20, 20, 30.

=> Now, we sort both lists.

Thus t => 10, 15, 20, 35

and s => 20, 20, 30, 30

Now, as we can see that, for last student with demand of 35, the pizza slice alotted is of size 30, thus he is unhappy, and pizza cannot be distributed so that everyone becomes happy.

Now, after the approach, let's discuss question.

(a) Greedy algorithm paradigm is most appropriate for this problem, as what we are doing is greedily distributing small slices to those students which have least demands first then tackling bigger demands of students, by remaining bigger slices.

(b) As we are mainly sorting thel ist of sizes of pizza slices and student demands, thus we need to use an efficient algorithm to sort the lists. Such an efficient algorithm can be QuickSort() or MergeSort().

(c) Asymptotic running time of our algorithm would be O(n*logn).

You might be interested in
Anybody know the answer to this question?
aniked [119]

Answer:

sorry i need pointssssss

7 0
3 years ago
In C++ please.
natali 33 [55]

Answer:

Following are the code to this question:

#include <iostream>//defining header file  

using namespace std;    

bool rightTriangle(int s1,int s2,int s3) //defining method rightTriangle  

{

int t1,t2,t3; //defining integer variables

t1 = s1*s1; // multiplying side value and store it into declaring integer  variables

t2 = s2*s2; // multiplying side value and store it into declaring integer variables

t3 = s3*s3;  // multiplying side value and store it into declaring integer variables

if(t3 == t1+t2)//use if block to check Pythagoras theorem

{

return true; //return true

}

else //else block

{

return false; //return false

}

}

bool equalNums(int n1,int n2,int n3,int n4) //defining method equalNums  

{

if(n1==n3 && n2==n4) //defining if block that checks  

{

return true;//return value true  

}

else //else block  

{

return false; //return value false

}

}

int main()//defining main method

{  

int t1=3,t2=4,t3=5,t11=3,t12=4,t13=5; //declaring integer varibles and assign value  

int check=0;   //defining integer varible check that checks values

if(rightTriangle(t1,t2,t3)&&rightTriangle(t11,t12,t13)) //defining codition to check value using and gate

{

if(equalNums(t1,t3,t11,t13) || equalNums(t2,t3,t12,t13)) // defining conditions to check value using or gate

check = 1; //if both conditions are true

}

if(check==1) //if block to check value is equal to 1

{

cout << "Right Congruent Triangles"; //print message

}

else//else block

{

   cout << "Not Right Congruent Triangles";//print message

}

}

Output:

Right Congruent Triangles

Explanation:

  • In the above-given code, a boolean method "rightTriangle" is declared, in which it accepts three integer variable "s1, s2, and s3" as a parameter, inside the method three another variable "t1, t2, and t3" is declared, in which parameter stores its square value.
  • In the next line, a conditional statement is declared that checks the "Pythagoras theorem" value and returns its value.  
  • In the next step, another method "equalNums" is declared, that accepts four integer parameter "n1, n2, n3, and n4", inside the method a conditional statement is used that uses an operator to check n1, n3, and n2, n4 value if it is true it will return true value else it will return false.
  • Inside the main method, integer variable and a check variable is defined that uses the if block to passes the value into the method and checks its return value is equal if all the value is true it will print the message "Right Congruent Triangles" else "Not Right Congruent Triangles".
7 0
3 years ago
Rows within a spreadsheet are identified by:
EleoNora [17]

Answer:

Option C: Numbers.

Explanation:

By default, rows within a spreadsheet are identified by Numbers i.e. 1,2,3,............

Total rows are 1048575 in one spreadsheet.

7 0
3 years ago
NWhen you measure a person’s weight, you are measuring the
MAVERICK [17]

Answer:

gravitational force acting on that person.

Explanation:

5 0
3 years ago
Read 2 more answers
. Which responsibility belongs to the marketing function?
miskamm [114]

Answer:

The marketing functions involves various responsibilities of the business organization, these functions are responsible for the growth of company. The key roles and responsibilities of marketing functions are market research, finance, product development, communication, distribution, planning, promotion, selling etc.

4 0
3 years ago
Other questions:
  • According to many experts how often should files be backed up
    12·1 answer
  • The picture that graphically represents the items you use in Windows is called a/an
    15·1 answer
  • A _____ is inserted so that a portion of a document that can have different formatting from the rest of the document. a. heading
    9·1 answer
  • arlos, an algebra teacher, is creating a series of PowerPoint presentations to use during class lectures. After writing, formatt
    12·2 answers
  • PLEASE HELPP!!!!!
    14·1 answer
  • Create an old sample dictionary {0:10, 1:20} as follows to store numbers. Write a Python script to ask how many runs from user i
    11·1 answer
  • Which of the following is the best name for a history report about world war 1
    7·1 answer
  • Use the _______ command to center worksheets vertically and/or horizontally on a page.
    9·1 answer
  • Which of the following transferable skills are generally the most look for in the it <br> field
    10·1 answer
  • In your opinion., which Zelda character is the hottest? Be honest.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!