- -
UPV
 

Recursion in Python: traversing a list with slices

In this video we learn about traversing a list using slices in a recursive way. There are two strategies: bottom-up composition, which removes the first element until the list is empty, and top-down composition, which removes the last element until the list is empty. Both approaches have the same base case, which checks if the list is empty. In the general case, they handle the first or last element and perform a recursive call with a slice of the list. However, this approach is not efficient because it makes a copy of the full list every time a slice is performed. A better way would be to update a pointer to the previous list and note the current position, which will be discussed in the next video.


EMAS upv