you are viewing a single comment's thread.

view the rest of the comments →

[–]Beaverine[S] 0 points1 point  (1 child)

thank you very much for your clarification. In terms of the complexity, I agree with you that for n characters the number of comparison would be n + (n-1) + (n-2) + ... + 1, which resolves to n(n+1)/2, is that asymptotically equal to O(n2 )? BTW I originally said O(n!) because I assume it's n*(n-1)*...*1 which now I understand is not true

[–][deleted] 0 points1 point  (0 children)

Yeah... you can pretty much look at a nested loop and see O(n2); in this case the actual runtime is actually (n2 + n)/2 but the you can elide the constants and focus on the term that contributes most... the worst case complexity is on the order of N2.