You are on page 1of 4

LEC 2: Introduction to Computer Programming

Topic: Understanding Recursion in Approximating Square Roots

Assumption:
- We are trying to find the square root of a given number, denoted as 'y'.
- The correct answer is known to be between 0 and 'y'.
- We are going to use a recursive method to approximate the square root.

Method Overview:
1. Start with an initial guess, 'g.'
2. Test the guess by squaring it: 'g * g.'
3. If 'g * g' is greater than 'y', adjust our guess to the left.
4. If 'g * g' is less than 'y', adjust our guess to the right.
5. Repeat steps 2-4 until we narrow down the range where the square root lies.

Concrete Example: Let's consider 'y' as 15.

1. Initial guess: 'g' = 7.5 (the average of 0 and 15).


2. Calculate 'g * g': 7.5 * 7.5 = 56.25.
3. Since 56.25 is greater than 15, the correct answer must lie between the left (0) and our guess value (7.5).

Recursion in Action:
- Now, let's guess 'g' = 2.
- Calculate 'g * g': 2 * 2 = 4.
- Since 4 is less than 15, we know that the correct square root is to the right of our guess.

Continuing the Process:


- When 'g * g' is less than 'y', we update the value of the left boundary to 'g.'
- When 'g * g' is greater than 'y,' we update the value of the right boundary to 'g.'

This process continues until we get closer and closer to the correct square root value by iteratively narrowing down
the range between our left and right boundaries.

Conclusion:
- The concept we are using is called recursion, where we solve a problem by breaking it down into smaller, similar
problems.
- In this case, we recursively update our guess and the boundaries until we approximate the square root of 'y'
accurately.
- Focus on single step thinking processes.

These recursive steps help us efficiently approach the correct square root value through a series of refined guesses.
Title: Introduction to the Tower of Hanoi

What is the Tower of Hanoi?


- The Tower of Hanoi is a classic puzzle or problem.
- It consists of three rods and a number of disks of different sizes, which can be slid onto any rod.
- The puzzle starts with the disks in a neat stack in ascending order of size on one rod, with the smallest disk at the
top.

Objective:
- The goal of the puzzle is to move the entire stack of disks from one rod to another while obeying the following
rules:
1. Only one disk can be moved at a time.
2. A disk can only be placed on top of a larger disk or an empty rod.
3. You can never place a larger disk on top of a smaller disk.

Components:
- Three rods (usually labeled A, B, and C).
- A set of disks of different sizes.

How to Solve the Tower of Hanoi:


- The key to solving the Tower of Hanoi puzzle is to follow a recursive strategy.
- Here are the basic steps:
1. Move the top 'n-1' disks from the source rod to an auxiliary rod, using the destination rod as a temporary
auxiliary.
2. Move the largest disk from the source rod to the destination rod.
3. Move the 'n-1' disks from the auxiliary rod to the destination rod, using the source rod as a temporary auxiliary.

Visualization:
- Imagine you have three rods (A, B, and C) and a stack of disks on rod A, with the smallest disk at the top and the
largest at the bottom.
- Your goal is to move this entire stack from rod A to rod C using rod B as an auxiliary.
- You'll follow the steps above recursively to achieve this goal.

Important Points:
- The minimum number of moves required to solve the Tower of Hanoi puzzle with 'n' disks is 2^n - 1.
- It's a classic example of a problem that can be efficiently solved using recursion.
- The Tower of Hanoi puzzle has applications in algorithm design and computer science.

Conclusion:
- The Tower of Hanoi is an intriguing and classic puzzle that teaches valuable lessons in problem-solving and
recursion.
- As you progress in your programming journey, you'll encounter more complex problems that can be tackled using
similar recursive techniques.
GitHub Overview:

GitHub is a web-based platform and community for version control and collaboration. It is widely used for managing
and hosting code repositories, tracking changes to code over time, and enabling collaborative software development.
GitHub is an essential tool for developers, as it provides a platform for storing, sharing, and collaborating on software
projects.

How to Set Up a GitHub Account:


Setting up a GitHub account is straightforward:

1. Go to GitHub: Visit the GitHub website at https://github.com/.

2. Sign Up: Click on the "Sign up" button on the homepage.

3. Provide Information: Fill out the required information, including your username, email address, and password.
Choose a unique username that will be associated with your GitHub account.

4. Choose a Plan: GitHub offers both free and paid plans. For beginners, the free plan is usually sufficient. You can
always upgrade later if needed.

5. Verify Your Email: After signing up, you'll receive a verification email. Click the link in the email to verify your
email address.

6. Complete Setup: Follow the on-screen prompts to complete the setup of your GitHub account.

Resources Linked to a GitHub Account:


- Once you have a GitHub account, you can create and manage repositories (projects), contribute to open-source
projects, collaborate with others, and access a variety of developer tools.

Why Should You Use GitHub:


1. Version Control: GitHub uses Git, a distributed version control system, which allows you to track changes to your
code and collaborate with others seamlessly.

2. Collaboration: GitHub enables multiple developers to work on the same project simultaneously, making it an
ideal platform for team projects.

3. Open Source: Many open-source projects are hosted on GitHub, making it a valuable platform for contributing to
and learning from established projects.

4. Portfolio: GitHub can serve as a portfolio of your coding projects and contributions, making it easier for potential
employers to assess your skills.

5. Community: GitHub has a vast community of developers, which means you can seek help, and advice, and
collaborate on interesting projects.

Creating a File for Beginners and Solving Practice Problems:


To create a file on GitHub and solve practice problems, follow these steps:

1. Create a Repository: After logging in to your GitHub account, click the "New" button to create a new repository.
Give it a name, choose visibility (public or private), and initialize it with a README file.
2. Clone the Repository: On your local machine, use Git to clone the repository to your computer. This allows you
to work on the files locally.

3. Create a New File: In your local repository, create a new file. You can use a code editor or a plain text editor to
write code.

4. Write Code: Write beginner-level code or solve practice problems in the newly created file.

5. Commit Changes: After writing your code, use Git to commit the changes to your local repository.

6. Push to GitHub: Push the changes from your local repository to your GitHub repository.

Now, your code is available on GitHub, and you can share it with others, showcase your skills, and collaborate with
fellow developers.

You might also like