0
$\begingroup$

This question already has an answer here:

I have a loop that runs n-m+1 times where

m = len(list_m)

n = len(list_n)

for i in range(n-m+1):

Is this time complexity O(n-m+1)?

$\endgroup$

marked as duplicate by Raphael May 9 at 9:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ What definition tells you? $\endgroup$ – Evil May 9 at 2:48
  • $\begingroup$ We discourage posts that simply state a problem out of context, and expect the community to solve it. Assuming you tried to solve it yourself and got stuck, it may be helpful if you wrote your thoughts and what you could not figure out. It will definitely draw more answers to your post. Until then, the question will be voted to be closed / downvoted. You may also want to check out these hints, or use the search engine of this site to find similar questions that were already answered. $\endgroup$ – Raphael May 9 at 9:31
  • $\begingroup$ What happens in the loop? What have you tried and where did you get stuck? Check out many other questions like this: runtime-analysis+loops. $\endgroup$ – Raphael May 9 at 9:32
0
$\begingroup$

If you are doing $k$ (i.e., constantly many) operations, each taking constant time $O(1)$, then the complexity will be on the order of $ O(k(n-m+1)) $, which is equivalent to $ O(n-m+1) $. I recommend you to read this article or the Wikipedia page for the big-O notation.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.