What is the difference between a deep copy and a shallow copy?

copy, deep-copy, language-agnostic, shallow-copy

Solution

Shallow copies duplicate as little as possible. A shallow copy of a collection is a copy of the collection structure, not the elements. With a shallow copy, two collections now share the individual elements.

Deep copies duplicate everything. A deep copy of a collection is two collections with all of the elements in the original collection duplicated.

Problem

What is the difference between a deep copy and a shallow copy?

Original source

Related problems