1 In this puzzle, the player begins with n disks of decreasing diameter placed one on top of the other on one of three pegs of the game board. The player.

Slides:



Advertisements
Similar presentations
3/25/2017 Chapter 16 Recursion.
Advertisements

Tower of Hanoi Tower of Hanoi is a mathematical puzzle invented by a French Mathematician Edouard Lucas in The game starts by having few discs stacked.
Recursion and Induction
CSC 205 Programming II Lecture 10 Towers of Hanoi.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 8: Recursion Presentation slides for Java Software Solutions for AP* Computer Science 3rd.
The Algorithmic problems?
Chapter Recurrence Relations
MAT 4 – Kompleks Funktionsteori MATEMATIK 4 INDUKTION OG REKURSION MM 1.4 MM 1.4: Induktion og Rekursion Topics: Mathematical induction Example of Towers.
COSC 2006 Data Structures I Recursion III
Recurrences. What is a Recurrence Relation? A system of equations giving the value of a function from numbers to numbers in terms of the value of the.
Representational Choices The Towers of Hanoi Problem.
CS102 Algorithms and Programming II1 Recursion Recursion is a technique that solves a problem by solving a smaller problem of the same type. A recursive.
© 2006 Pearson Addison-Wesley. All rights reserved6-1 Chapter 6 Recursion as a Problem- Solving Technique.
© 2006 Pearson Addison-Wesley. All rights reserved6-1 More on Recursion.
Chapter 10 Recursion. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Explain the underlying concepts of recursion.
Recursion.
The Tower of Hanoi
© 2006 Pearson Addison-Wesley. All rights reserved3-1 Chapter 3 Recursion: The Mirrors.
Chapter 5 Recursion as a Problem-Solving Technique.
1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.
Multi-Peg Towers of Hanoi By Krüz Kalke Summer
Chapter 2 Recursion: The Mirrors. © 2005 Pearson Addison-Wesley. All rights reserved2-2 Recursive Solutions Recursion is an extremely powerful problem-
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
When confronted with a new problem there are two questions you should ask: 1. Is this problem like, or a special case of, a problem that I already know.
Recursion and Induction Themes –Recursion –Recurrence Definitions –Recursive Relations –Induction (prove properties of recursive programs and objects defined.
Introduction to Programming (in C++) Recursion Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
Copyright © Cengage Learning. All rights reserved.
Recursively Defined Sequences Lecture 35 Section 8.1 Wed, Mar 23, 2005.
Advanced Counting Techniques
Analysis of Algorithm Lecture 3 Recurrence, control structure and few examples (Part 1) Huma Ayub (Assistant Professor) Department of Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 3-1 Chapter 3 Recursion: The Mirrors.
Chapter 3 Recursion: The Mirrors. © 2004 Pearson Addison-Wesley. All rights reserved 3-2 Recursive Solutions Recursion –An extremely powerful problem-solving.
13.2 Recursive Definitions Objective 1) Provide the recursive definition for sequences; 2) Identify the type of a sequence from a recursive definition.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 5: Recursion as a Problem-Solving Technique Data Abstraction.
Module #20 - Recurrences 1 Ch. 7 Recurrence Relations Rosen 6 th ed., §§7.1.
R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations.
# 1# 1 VBA Recursion What is the “base case”? What is the programming stack? CS 105 Spring 2010.
Chapter 4 Recursion. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Explain the underlying concepts of recursion.
Recurrence Relation Models
Chapter 6.1: Recurrence Relations Discrete Mathematical Structures: Theory and Applications.
Hanoi Towers Big Oh Recursion Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science.
Discrete Mathematics Recurrence Relations Chapter 5 R. Johnsonbaugh
Chapter 2 Recursion: The Mirrors. © 2005 Pearson Addison-Wesley. All rights reserved2-2 Recursive Solutions Recursion is an extremely powerful problem-solving.
22C:19 Discrete Math Advanced Counting Fall 2010 Sukumar Ghosh.
1 Examples of Recursion Instructor: Mainak Chaudhuri
Pass the Buck Every good programmer is lazy, arrogant, and impatient. In the game “Pass the Buck” you try to do as little work as possible, by making your.
Towers of Hanoi Move n (4) disks from pole A to pole B such that a larger disk is never put on a smaller disk A BC ABC.
CMPF144 FUNDAMENTALS OF COMPUTING THEORY Module 9: The Tower of Hanoi.
Hanoi Towers part 1 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
Tower of Hanoi Tower of Hanoi is a mathematical puzzle invented by a French Mathematician Edouard Lucas in The game starts by having few discs stacked.
Recursively Defined Sequences Lecture 40 Section 8.1 Wed, Apr 11, 2007.
Aumm-e-hani munir Maria umer Rakhshanda batool Faiza.
Chapter 2 Recursion: The Mirrors. © 2005 Pearson Addison-Wesley. All rights reserved2-2 Recursive Solutions Recursion is an extremely powerful problem-solving.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
1 Towers of Hanoi Three pegs, one with n disks of decreasing diameter; two other pegs are empty Task: move all disks to the third peg under the following.
Discrete Math For Computing II. Contact Information B. Prabhakaran Department of Computer Science University of Texas at Dallas Mail Station EC 31, PO.
Tower of Hanoi problem: Move the pile of rings from one peg to another
Towers of Hanoi Move n (4) disks from pole A to pole C
Copyright © Cengage Learning. All rights reserved.
Tower of Hanoi problem: Move the pile of rings from one peg to another
Copyright © Cengage Learning. All rights reserved.
The Hanoi Tower Problem
Tower of Hanoi Txt: 10.4 and p. 478 & SOL: DM.10
Recursion and Induction
Recursion.
Recursion and Induction
Chapter 3 :Recursion © 2011 Pearson Addison-Wesley. All rights reserved.
Tower of Hanoi problem: Move the pile of rings from one peg to another
Recursively Defined Sequences
Recursion: The Mirrors
Presentation transcript:

1 In this puzzle, the player begins with n disks of decreasing diameter placed one on top of the other on one of three pegs of the game board. The player must move the disks from peg to peg, using each of the three pegs, until the entire tower is moved from the starting peg to one of the others. The only rule governing the movement of the disks is that in each move a disk of larger diameter must never be placed on top of one of smaller diameter Organizing Data: The Towers of Hanoi

2 Towers of Hanoi Puzzle

3

4

5

6

7

8

9 The Towers of Hanoi Pseudocode solution solveTowers(count, source, destination, spare) if (count is 1) Move a disk directly from source to destination else { solveTowers(count-1, source, spare, destination) solveTowers(1, source, destination, spare) solveTowers(count-1, spare, destination, source) } //end if

The Cost of Towers of Hanoi Solution to the Towers of Hanoi problem solveTowers(count, source, destination, spare) if (count is 1) Move a disk directly from source to destination else { solveTowers(count-1, source, spare, destination) solveTowers(1, source, destination, spare) solveTowers(count-1, spare, destination, source) }

The Cost of Towers of Hanoi With N disks, how many moves does solveTowers make? Let moves(N) be the number of moves made starting with N disks When N = 1 –moves(1) = 1 When N > 1 –moves(N) = moves(N – 1) + moves(1) + moves(N – 1)

The Cost of Towers of Hanoi Recurrence relation for the number of moves that solveTowers requires for N disks –moves(1) = 1 –moves(N ) = 2 * moves(N – 1) + 1 if N > 1

The Cost of Towers of Hanoi A closed-form formula is more satisfactory –You can substitute any given value for N and obtain the number of moves made –moves(N ) = 2 N – 1, for all N ≥ 1 –Induction on N can prove this