## david31337

``````try {
for (int j=0; j < length; j++) {
int indx = s.indexOf(text.charAt(j));
if (indx >= 27 && indx <= 36) {
code += ((indx + key)%26);
}
else {
code += s.charAt((indx + key)%36);
}
}
}``````

Hi, Im pritty new to java, I wrote this code and just out of intrest was wondering about it's time complexity. Is there any way to work out max and min run times for any given value? I've been looking into this a bit, and have come up with nothing. Anyway any insite on how to start/finish this would be great?

## Narue 5,707

>and just out of intrest was wondering about it's time complexity
Um, O(N). Loops are what you look for primarily when working out time complexity, and since there's only one loop, it's pretty straightforward.

## Rashakil Fol 978

It is O(length), but what is the variable s? Is it a string of fixed size? Is it a variable length string? If so, then generally, your running time is O(length * s.length()), because the indexOf method should take O(s.length()) time in the average and worst case. Holding s.length() fixed, your running time is O(length).

## david31337

S = a string of 36 letters and numbers.
Thanks for the replies.
So s is fixed so the running time in O(length)?! What does that actually mean, is that a good running time? Im guessing here, but is that this big O theory? Sorry for being stupid, but my course don't cover this and the info about it on the net is very confusing!

## Narue 5,707

http://www.eternallyconfuzzled.com/articles/bigo.html

I usually don't plug my own stuff out of principle, but any other explanations I've found have been overly mathematical and confusing even to me. And I like to think that I have an above average understanding of these things. :rolleyes:

## david31337

That is a good link! makes sense now! Thanks all for the replies!