i have a question about Structural sharing from List in Scala. I have read some where in the Internet this sentence
List implements structural sharing of the tail list. This means that many operations are either zero- or constant-memory cost.
but i dont really understand how would time and memory cost of the operations for lists be reduced. For example
val mainList = List(3, 2, 1)
val with4 = 4 :: mainList // O(1)
if we want to create another list with4 time would just be O(1) and memory cost one instead but for operations of the list how would it be different ? I mean with length() or reverse() ... it would still be O(n) as normal ? Can anyone please explain me and if you can maybe an example would be really helpful. Thank you!