Answer to Question #230624 in Java | JSP | JSF for rishav

Question #230624

Problem 3: In the country of WeirdLand, there is only one barber shop. In the shop there are 3 barbers, Alpha, Beta and Gamma, who are not always efficient as employees. All the customers are seated in a waiting area, each customer has a card which has a unique integral ID. For calling next person from the waiting area each barber has his own weird way: Alpha: He will call either the person with least ID from the waiting area of the one with max ID. Min or Max is decided randomly by him (assume 50% probability for each min or max). Beta: He will choose a ‘k’ and will call the kth smallest ID, (Kth ID when all IDs are arranged in ascending order). K is chosen randomly from the number of persons available in waiting area (1 <= K <= Total persons)


1
Expert's answer
2021-08-29T00:58:53-0400
int n;
int customers_id[n];
int i1=0;
int a_call_id1=customers_id[0];
int a_call_id2=customers_id[0];
int b_call_id1=customers_id[0];
int g_call_id=0;
Alpha{
    while(true):
        if(customers_id[i]<a_call_id1):
            a_call_id1=customers_id[i];
        if(customers_id[i]>a_call_id2):
            a_call_id2=customers_id[i];
}


Beta{
    while(true):
        if(customers_id[i]<b_call_id1):
            b_call_id1=customers_id[i];
}


Gamma{
    while(true):
            g_call_id1=median.(customers_id);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS