473,385 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

o-notation

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
2 1475
dtimes6
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
3,652 Expert 2GB
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

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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.