Question

Let T(n) be the running time of function select_even. Find the equation of T(n) and find...

Let T(n) be the running time of function select_even. Find the equation of T(n) and find the complexity of T(n) using big-O notation.

def select_even(L):
output = []
for x in L:
if x%2==0:
output.append(x)
return output

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def select_even(L):
    output = [] // 1
    for x in L: // n
        if x%2==0:  // k times. assuming there are k numbers in L list.
            output.append(x)    // 1
    return output   // 1

if there are n elements in L list, and k elements in the list.
x%2==0, indicates that x is even
so, T(n) = 2 + n + k.
we know that k <= n
so, T(n) <= 2+n+n
= 2+2n
hence time complexity is O(n)

Answer: O(n)
Add a comment
Know the answer?
Add Answer to:
Let T(n) be the running time of function select_even. Find the equation of T(n) and find...
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