By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,404 Members | 1,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,404 IT Pros & Developers. It's quick & easy.

o-notation

P: 9
i have another question regarding the o-notation.
how does using strings insted of simple types like integers alter the
o-notation of operations?
thanks
Nov 7 '06 #1
Share this Question
Share on Google+
2 Replies


P: 73
This infact is a very hard question!
That depends on what is the use of the string. And how u use it!
Nov 8 '06 #2

Ganon11
Expert 2.5K+
P: 3,652
In general, using strings does not seriously affect Big-O notation. Of course, it depends on what you're doing with it.

Recall that a string can be considered an array of characters. Thus, if you were accessing each character of a string, this would be the same as accessing each member of an integer array (a.k.a. O(n)). Also, using a string method (such as stringVariable.find(char OR string)) will have a certain run-time - .find() probably has O(n) (since it will perform a linear search through the string), and .substr() probably has O(1) (since it will take a constant time to get the substring). Of course, these are just my guesses, so I'm not completely sure.

Generally, treat strings as character arrays for purposes of determining Big-O notation,
Nov 8 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.