0

I need to reverse a list in python3 using the function below:

def flip(arr): arr = arr[::-1] return arr 

I would like to know what the runtime for this function is.

3
  • 2
    O(n) (stack overflow wont let me post a comment less than 15 chars) Commented Jul 12, 2019 at 1:38
  • 1
    Have you measured it? Commented Jul 12, 2019 at 1:38
  • @StephenRauch No but I know it makes a copy, so it cannot be faster than O(n), anything slower would be ridiculous Commented Jul 12, 2019 at 1:39

1 Answer 1

0

using timeit module

timeit.timeit(stmt='pass', setup='pass', timer=, number=1000000)

>>? def flip(arr): arr = arr[::-1] return arr >>? import timeit >>? timeit.timeit('__main__.flip(range(10000))', 'import __main__', number=1) 0.0005059589886400317 
Sign up to request clarification or add additional context in comments.

2 Comments

What does the returned time indicate? How can you prove the time complexity with a single value?
The return time is the runtime for the function in seconds. The time complexity is o(n). You can examine the runtime with variable size input list

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.