title: What is the Big-O of this function that reverses words in a string
body: <p>I have a simple function, reverseWords(), that reveses the words in a string. eg. an input of a S = "this is a string" gives an output of "siht si a gnirts"</p>
  
  <p>I was wondering what the big O of this function is. Is it O(N), O(N^2), or O(N* M)?</p>
  
  <pre><code>def reverseWords(S):
      # code in Python 2.7
      listA = S.split()
      output = []
      for element in listA:
          output.append(element[::-1])
  
      return (" ".join(output))
  </code></pre>
  
  <p>Is it O(N), O(N^2), or O(N* M)?</p>
  
  <ul>
  <li>O(N^2) because we have a nested loop eg. passing over input once, outer loop, and then reversing each character as the inner loop</li>
  <li>O(N*M) same reason as above except M is denoted as the looping over the characters</li>
  <li>O(N) because... I forgot the explanation</li>
  </ul>