Time Complexity for substr() function

W

Walter Roberson

:Any idea of the time complexity of the substr()
:in Perl?

:Is it under linear time?

:Any reference I can go to for that?

There's always the source...

perl knows the length of strings. Strings are stored as arrays
of characters, so whether you are going from the front or the back,
it's a fairly simple address calculation and length calculation.
Then it's just a matter of strncpy() and promoting the result
to a perl variable structure.

substr() is thus [near] constant-time with respect to the length of the
original string, and linear with respect to the length of the
extracted string.


However, this calculation goes out the window when you are using
unicode; I have never looked at the internal details of how
unicode is handled. substr() is defined in terms of characters,
not in terms of bytes, and the description of length() makes it clear
that the two are not the same.
 
E

Edward Wijaya

Hi,

Any idea of the time complexity of the substr()
in Perl?

Is it under linear time?

Any reference I can go to for that?

Thanks for your time.
Hope to hear from you again.

Regards
Edward WIJAYA
SINGAPORE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top