Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8142469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:49:50+00:00 2026-06-06T12:49:50+00:00

Some claim that appending to immutable lists is more efficient. Is this true? How?

  • 0

Some claim that appending to immutable lists is more efficient. Is this true? How?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:49:51+00:00Added an answer on June 6, 2026 at 12:49 pm

    Producing a modified version of a list by allocating an array large enough to hold the modified version and copying over all of the unmodified elements is somewhat expensive, regardless of whether the modification is an append, an insert, a deletion, replacement, or anything else. The cost is roughly comparable to that of producing an unmodified, but distinct, copy of the list.

    If an object Foo wishes to maintain a list of elements in such a way that it can only be changed when Foo changes it, there are two common approaches it can use to do so:

    1. It can use an “immutable list” type which guarantees that any instance which has ever been exposed to the outside world will forever hold the same sequence of objects. The object `Foo` would be free to expose references to this list, since nobody would be able to alter it. If `Foo` wants to e.g. add an item to its list, it would generate a new immutable list which contains all the items in the list, plus the new one, and start holding a reference to that instead of the old one.
    2. It can create a list object which is mutable, but is never exposed to the outside world. If anyone needs to retrieve the sequence of items from the list, `Foo` would copy the list’s contents into a new list with which the caller could use in any way it sees fit without affecting `Foo`s list..

    If one uses approach #1, then every time Foo alters the list it must create a new “immutable list” instance, but Foo could answer a request for the list’s contents without having to copy it. If one uses approach #2, adding items to the list (and other modifications) will be cheaper, but answering a request for the list’s contents will require copying the list. Whether it’s better to use approach #1 or approach #2 will depend upon how often the list is updated, versus how often the application will need a copy of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some people claim that scala is able to deal with recursive structural types if
I've seen pictures like this on Facebook: The instructions claim that your SIM card
Some people claim that using namespace std; is bad practice. Others say it's OK
I know that this question may be closed by some of you, but my
I've read some articles about Android NDK. Most of them claim Native C is
Some time ago I've read an article on CLR, where author showed that if
Some reasons i am experiencing this issue on my website. When the website loads
Some context for this code, what I am trying to do is create a
How to build an area-efficient circuit that counts the number of set bits in
Some claim eval is evil. Any regular HTML page may look like: <script src=some-trendy-js-library.js></script>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.