Embercode
✕
Linked ListsQuick quiz

Recursion depth and groups

7 questions. Covers Reverse in groups of k.

Questions 1 to 5 of 7

  1. 1. print_reverse prints the list 1 -> 2 -> 3 -> 4 as 4 3 2 1. What makes it print in that order?
  2. 2. On the lesson's test build, length_rec crashes at 400000 nodes, but length_loop handled 1000000 nodes. What is the reason?
  3. 3. What does this program print? ``cpp #include <iostream> struct Node { int value; Node* next; }; void walk(const Node* head) { if (head == nullptr) { std::cout << "end\n"; return; } std::cout << "down " << head->value << '\n'; walk(head->next); std::cout << "up " << head->value << '\n'; } int main() { Node c{3, nullptr}, b{2, &c}, a{1, &b}; walk(&a); } ``
  4. 4. What does this program print? ``cpp #include <iostream> struct Node { int value; Node* next; }; Node* bad_reverse(Node* head) { if (head == nullptr || head->next == nullptr) { return head; } bad_reverse(head->next); head->next->next = head; head->next = nullptr; return head; } int main() { Node c{3, nullptr}, b{2, &c}, a{1, &b}; Node* result = bad_reverse(&a); std::cout << result->value << '\n'; } ``
  5. 5. True or false: a recursive list function with no base case stops when it reaches the last node.

5 question(s) left on this page.