# Lab 02 - Debugging

Slides:

{% file src="<https://3351151415-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKipySCGxC8NC1UpA24DS%2Fuploads%2FUVeQWkoQoV1j7UjsVwOt%2FLab2.pdf?alt=media&token=64b8e5c8-4e48-4ab5-a5d9-8d244b000b0d>" %}
Lab 2 Slides
{% endfile %}

## Selected Problems from Exercise 1

### Wishful Thinking

Before we talk about the wishful thinking, let's get a quick review of the **Mathematical Induction**

#### Mathematical Induction

Suppose we want to find the value of $$P(n)$$ for any non-negative interger $$n$$, we only need to do two things:

1. Find $$P(0)$$.
2. Find a way to get $$P(k+1)$$ based on the value of $$P(k)$$.

The so called "**Wishful Thinking"** is just the reverse of above!

#### Wishful Thinking

Suppose we already know:

1. How to compute $$P(k+1)$$ using $$P(k)$$;
2. The value of $$P(0)$$, i.e., "the base case" (or **terminating condition**)

Now we want to find $$P(n)$$, and so we can just find $$P(n-1)$$ first. To find $$P(n-1)$$, we just need to find $$P(n-2)$$ first... the cycle goes on until we reach $$P(0)$$ where the recursion terminates.


---

# Agent Instructions: 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/lab/lab-02.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.
