Question

You have a complex project involving m independent tasks. Since the tasks can be performed in...

You have a complex project involving m independent tasks. Since the tasks can be performed in parallel, the time to complete the project will be the maximum time taken by any task. You’d like to hire one of k companies to do the whole project, and you’re given a 2- dimensional list x with k rows and m columns, where x[i][j] is the amount of time company i would take to complete task j. Write a Python function hire(x) to help you decide which company to hire; it should return a pair (i, j) where i is the index of the company that will finish the project quickest, and j is the index of the task that will take them the longest (the “bottleneck”). The running time should be O(km), i.e., linear as a function of the total number of entries. For example, hire([[1, 4], [3, 2]]) should return (1, 0). Do not use Python’s built-in min or max functions.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for posting the question, here is the code in Python to find the index of the company that will finish the task first and the index of the company that will take the maximum time.

Here is the code and the screenshot

_____________________________________________________________________________________________

def hire(x):

    fastest_company_index=0
    longest_company_index=0
    fastest_time=x[0][1]
    longest_time=x[0][1]

    for index in range(len(x)):
        entry = x[index]
        if fastest_time > entry[1]:
            fastest_time=entry[1]
            fastest_company_index=index

        if longest_time<entry[1]:
            longest_time=entry[1]
            longest_company_index=index

    return fastest_company_index,longest_company_index

print(hire([[1,4],[3,2]]))

________________________________________________________________________________________________

|芔CookieCalculator.py def hire (x) Eastest_corpany index-0 longest company index-0 astest_tire-x[0j [i] longest_tire-xlo] 1 for index in range (ien (x)) entryx[index] if fastest time > entry]: 10 Eestest tine-entry[i] astest_company index-index 12 13 14 L5 L6 17 18 19 20 if longest_timecentry: longest tine-entryi] longest_company index-index return fastest_company_index, longest_company index print 《h1re {[[1,4], [3,2]])) hire CookieCalculator C:UerUser PycharmProjects Cheggvenv Scripts python.exe C:Users/User/PycharmProjectsChegg.idea/CookieCalculator.py for index in rangellen())if fastest time> entryl1] Run: Process finished cxit code 0 IDE and Plugin Updates PyCharm is ready to update. 兼S; Debug :-S: TODO Terminal Python Console IDE and Plugin Updates: PyCharm is ready to update. (15 minutes age) 4: Run 12:40 CRLF: UTF-8:

thank you so much : )

Add a comment
Know the answer?
Add Answer to:
You have a complex project involving m independent tasks. Since the tasks can be performed in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT