@shaan0924, if you're referring to sequences being ordered by their underlying data, I don't think this is a requirement. I think the "ordering" of a sequence refers to the access order of the elements as you sequentially move through the sequence. E.g. I could have a sequence like {4, 1, 3, 9} where the order is 4 first, 1 second, 3 third, and 9 last, but the underlying data is not sorted.
What is the benefit of not being able to access particular indices of sequences?
^ I don't think there's much benefit, other than just sequences are supposed to be seen as a group of data, where the only operations you can make on them is the transformations we've spoken about (map, filter, etc) - by seeing it this way, the parallel nature of those operations lead to perf gains
I think an important concept of data structures it the concept of invariant. I feel that indexing sequences is not allowed because the invariant of a sequence is being a group of data and not a container of elements. Similarly to how there is no indexing for a list in c++, since the invariant of linked lists doesnt relate to indexing.
That is how I would think about it
What is the benefit of not being able to access particular indices of sequences?
My understanding is that, sequence is a more general abstraction in terms of the API that are available to developers; namely, if developers write programs that doesn't rely on the O(1) access by index, the runtime or execution engine may have larger flexibility in terms of the underlying data structures (and optimization opportunities).
Are sequences kind of like iterables in python?
I think they're more abstract than iterables, but I feel like an iterable is a type of sequence in a sense (correct me if I'm wrong)
Please log in to leave a comment.
Do sequences have to be ordered in order for us to use the following operations? If so, are there any operations that can work on unsorted/unordered data containers?