Lau J.

asked • 10/15/20

Python question concerning computational complexity

Determine the tightest simple bound of the worst-case computational complexity of the following function in terms of the size of the input list (n=len(lst)) and justify your answer. For that, describe what situation constitutes the worst case and what line(s) is/are dominating the overall computational cost. Provide additional arguments as necessary (you should not need more than 3-4 sentences).

def large_prefix(lst, t):

    n = len(lst)

    s = 0

    for i in range(len(lst)):

        s = s + lst[i]

        if s > t:

            return lst[:i+1]

    return None


1 Expert Answer

By:

Gavin R. answered • 10/22/20

Tutor
5.0 (122)

Experienced Coding Instructor and Tutor

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.