> For the complete documentation index, see [llms.txt](https://wenbo-notes.gitbook.io/cs1010-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wenbo-notes.gitbook.io/cs1010-notes/lec-tut-lab-exes/lecture/lec-10-more-recursion/diagnostic-quiz.md).

# Diagnostic Quiz

## Problems

### 1. Tower of Hanoi

> *Disk `i-1` is moved twice the number of times of Disk `i`*

It is **correct.** This can be reasoned using the recurrence relation $$T(n)=2T(n-1)+1$$ for the Tower of Hanoi problem.

### 5. Time Complexity for Nqueens

> *Consider the solution to N-Queens given in class. Suppose the running time of `nqueens` is* $$T(n)$$*. What is* $$T(1)$$*?*

This is an awesome question. $$T(1)$$ happens when we reach the **base case**, so here we need to think about what will happen in the **base case**.

The base case is:

{% code lineNumbers="true" %}

```c
if (row == n - 1) {
  if (!threaten_each_other_diagonally(queens, n - 1)) {
    cs1010_println_string(queens);
    return true;
  }
  return false;
}
```

{% endcode %}

It calls `threaten_each_other_diagonally` which runs in $$O(n)$$.

```c
bool threaten_each_other_diagonally(char queens[], size_t last_row) {
  for (size_t curr_row = 0; curr_row <= last_row; curr_row += 1) {
    if (has_a_queen_in_diagonal(queens, curr_row, last_row)) {
      return true;
    }
  }
  return false;
}
```

And print a string with length `n` takes $$O(n)$$. So, the overall running time for $$T(1)$$ is $$O(n^2)$$.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wenbo-notes.gitbook.io/cs1010-notes/lec-tut-lab-exes/lecture/lec-10-more-recursion/diagnostic-quiz.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
