slicing
Taking a sub-sequence of a list, string or tuple with the syntax seq[start:stop], which in Python returns a new copy.
In more detail
A list slice copies every element reference in the range, so it costs O(k) time and memory for k elements. Changing the slice afterwards does not change the original list. Code that slices inside a loop, such as recursive helpers that pass lists[1:], quietly adds linear cost at every step.
Related terms
- Python list — Python's built-in ordered, growable sequence, implemented as a dynamic array of pointers to objects.
- auxiliary space — The memory an algorithm allocates beyond the input itself, such as a temporary copy or a helper array.
Taught in
- Space, In-Place Work And The Call Stack — Algorithms & Data Structures for Working Engineers
- What A Hash Function Promises — Algorithms & Data Structures for Working Engineers
- Arrays: Contiguous Memory And Constant-Time Access — Algorithms & Data Structures for Working Engineers
- Searching With Hashes Versus Trees — Algorithms & Data Structures for Working Engineers
- Divide And Conquer And The Recurrence — Algorithms & Data Structures for Working Engineers