Embercode
✕
Linked ListsQuick quiz

Recursion depth and groups in Python

7 questions. Covers Reverse in groups of k in Python.

Questions 1 to 5 of 7

  1. 1. Why does this function raise RecursionError on any non-empty list? ``python def length_stuck(node): if node is None: return 0 return 1 + length_stuck(node) ``
  2. 2. What does this print? reverse_buggy below reverses the links correctly, but it returns head. It uses the from_list and show helpers from this lesson. ``python def reverse_buggy(head): if head is None or head.next is None: return head new_head = reverse_buggy(head.next) head.next.next = head head.next = None return head print(show(reverse_buggy(from_list(1, 2, 3)))) ``
  3. 3. What does this print? It uses the from_list, show and reverse_in_groups helpers from this lesson. ``python print(show(reverse_in_groups(from_list(1, 2, 3, 4, 5, 6, 7), 3))) ``
  4. 4. True or false, and why: the loop version of length from the recursion lesson can walk a list of any length without a RecursionError.
  5. 5. True or false, and why: reverse_in_groups reverses a short last block that has fewer than k nodes, because its loop only stops when the list is empty.

5 question(s) left on this page.