Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Rope (data structure)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Comparison with monolithic arrays== {| class="wikitable floatright" |+ Complexity{{citation needed|date=October 2010}} ! Operation !! Rope !! String |- align="center" | Index<ref name="Boehm" /> || {{bad|O(log n)}} || {{yes|O(1)}} |- align="center" | Split<ref name="Boehm" /> || {{bad|O(log n)}} || {{yes|O(1)}} |- align="center" | Concatenate || {{yes|O(1) amortized, O(log n) worst case}}{{Citation needed|date=June 2022|reason=earlier this article claims "A concatenation can be performed simply by ... which is constant time.", or O(1).}} || {{bad|O(n)}} |- align="center" | Iterate over each character<ref name="Boehm" /> | {{okay|O(n)}} || {{okay|O(n)}} |- align="center" | Insert<ref name=":0" />{{Failed verification|date=September 2023}} || {{yes|O(log n)}} || {{bad|O(n)}} |- align="center" | Append<ref name=":0">{{Cite web|url=https://www.sgi.com/tech/stl/ropeimpl.html|title=Rope Implementation Overview|website=www.sgi.com|access-date=2017-03-01 |archive-url=https://web.archive.org/web/20171219030153/https://www.sgi.com/tech/stl/ropeimpl.html |archive-date=2017-12-19 }}</ref>{{Failed verification|date=September 2023}} || {{yes|O(1) amortized, O(log n) worst case}} || {{bad|O(1) amortized, O(n) worst case}} |- align="center" | Delete || {{yes|O(log n)}} || {{bad|O(n)}} |- align="center" | Report || {{bad|O(j + log n)}} || {{yes|O(j)}} |- align="center" | Build || {{okay|O(n)}} || {{okay|O(n)}} |} Advantages: * Ropes enable much faster insertion and deletion of text than monolithic string arrays, on which operations have time complexity O(n). * Ropes do not require O(n) extra memory when operated upon (arrays need that for copying operations). * Ropes do not require large contiguous memory spaces. * If only nondestructive versions of operations are used, rope is a [[persistent data structure]]. For the text editing program example, this leads to an easy support for multiple [[undo]] levels. Disadvantages: * Greater overall space use when not being operated on, mainly to store parent nodes. There is a trade-off between how much of the total memory is such overhead and how long pieces of data are being processed as strings. The strings in example figures above are unrealistically short for modern architectures. The overhead is always O(n), but the constant can be made arbitrarily small. * Increase in time to manage the extra storage * Increased complexity of source code; greater risk of bugs This table compares the ''algorithmic'' traits of string and rope implementations, not their ''raw speed''. Array-based strings have smaller overhead, so (for example) concatenation and split operations are faster on small datasets. However, when array-based strings are used for longer strings, time complexity and memory use for inserting and deleting characters becomes unacceptably large. In contrast, a rope data structure has stable performance regardless of data size. Further, the space complexity for ropes and arrays are both O(n). In summary, ropes are preferable when the data is large and modified often.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)