Tower of Hanoi Problem Laboratory Experiment #1 Eltayeb Abuelyaman

Slides:



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

The Towers of Hanoi or Apocalypse When?.
CS1010: Programming Methodology
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 8: Recursion Presentation slides for Java Software Solutions for AP* Computer Science 3rd.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 20 Recursion.
Recursion. Idea: Some problems can be broken down into smaller versions of the same problem Example: n! 1*2*3*…*(n-1)*n n*factorial of (n-1)
Representational Choices The Towers of Hanoi Problem.
Fall 2007CS 2251 Proof by Induction. Fall 2007CS 2252 Proof by Induction There are two forms of induction Standard Induction –Prove the theorem is true.
1 Chapter 1: Introduction What you have learnt in Comp1220 or Comp1170? What will be taught in Comp 1200? - more Abstract Data Types -efficient algorithms.
Recursion Gordon College CPS212
Chapter 10: Recursion CS 201 Program Design with C Department of CS, Montana State University Mahmud Shahriar Hossain.
Review of Recursion. Definition: Recursion - The process of a function calling itself.
Recursion A recursive function is a function that calls itself either directly or indirectly through another function. The problems that can be solved.
Recursion Apan Qasem Texas State University Spring 2011.
1 Recursion. 2 Chapter 15 Topics  Meaning of Recursion  Base Case and General Case in Recursive Function Definitions  Writing Recursive Functions with.
Recursion CMPE231, Spring 2012 Aleaxander G. Chefranov 1.
Review Introduction to Searching External and Internal Searching Types of Searching Linear or sequential search Binary Search Algorithms for Linear Search.
Recursion Part 3 CS221 – 2/27/09. Recursion A function calls itself directly: Test() { … Test(); … }
Lecture 7 b Recursion is a fundamental programming technique that can provide an elegant solution to certain kinds of problems b Today: thinking in a recursive.
Java Programming: Guided Learning with Early Objects Chapter 11 Recursion.
Chapter 6.1: Recurrence Relations Discrete Mathematical Structures: Theory and Applications.
22C:19 Discrete Math Advanced Counting Fall 2010 Sukumar Ghosh.
1 Examples of Recursion Instructor: Mainak Chaudhuri
COMP 170 L2 L11: Recursion, Recurrence, and Induction l Objective n Recursion  A problem solving technique that reduces big problems into smaller ones.
CSE 251 Dr. Charles B. Owen Programming in C1 Functions.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Recursion.
UNIT 17 Recursion: Towers of Hanoi.
1 Recursion Recursive function: a function that calls itself (directly or indirectly). Recursion is often a good alternative to iteration (loops). Its.
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.
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.
CPS Today’s topics Programming Recursion Invariants Reading Great Ideas, p Brookshear, Section Upcoming Copyrights, patents, and.
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.
1 ADT Implementation: Recursion, Algorithm Analysis Chapter 10.
1 CSC 143 Recursion [Reading: Chapter 17]. 2 Recursion  A recursive definition is one which is defined in terms of itself.  Example:  Sum of the first.
Lecture 11 Recursion. A recursive function is a function that calls itself either directly, or indirectly through another function; it is an alternative.
1 Data Structures CSCI 132, Spring 2016 Notes 16 Tail Recursion.
Recursion To understand recursion, you first have to understand recursion.
Recursive. Recursive F(n) = F(n-1) + F(n-2) n! = (n-1)! x n C(m,n) = C(m-1,n-1)+C(m-1,n)......
1 Dr. Chow-Sing LinRecursion - CH 10 Problem Solving and Program Design in C Chapter 9 Recursion Chow-Sing Lin.
Chapter 9 Recursion. Copyright ©2004 Pearson Addison-Wesley. All rights reserved.10-2 Recursive Function recursive functionThe recursive function is –a.
Recursion.
CS212: Data Structures and Algorithms
Tower of Hanoi problem: Move the pile of rings from one peg to another
Recursion.
Chapter 19: Recursion.
Abdulmotaleb El Saddik University of Ottawa
Recursion: The Mirrors
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Another problem to solve…
ECE 103 Engineering Programming
CSE 1342 Programming Concepts
When Will The World End “Temple of Brahma” legend from the Indian city of Benares Priests must move 64 gold disks from one end of the temple to the other.
Another problem to solve…
7.Recursion Recursion is the name given for expression anything in terms of itself. Recursive function is a function which calls itself until a particular.
Tower of Hanoi problem: Move the pile of rings from one peg to another
Computer Architecture and Assembly Language CS 233 Lecture 1
The Hanoi Tower Problem
Recursion When performing a repetitive task either: a loop recursion
Tower of Hanoi Algorithm
Tower of Hanoi Txt: 10.4 and p. 478 & SOL: DM.10
Recursion.
CSC 143 Recursion.
Chapter 19: Recursion.
Dr. Sampath Jayarathna Cal Poly Pomona
Tower of Hanoi problem: Move the pile of rings from one peg to another
Another problem to solve…
Recursively Defined Sequences
Recursive Thinking.
Presentation transcript:

Tower of Hanoi Problem Laboratory Experiment #1 Eltayeb Abuelyaman The University of Nizwa College of Arts & Sciences Computer Architecture COMP 233 Summer 2013 Tower of Hanoi Problem Laboratory Experiment #1 Eltayeb Abuelyaman

About the Tower of Hanoi The famous Towers of Hanoi problem has an elegant solution through recursion. In the problem, three pegs, A, B and C exist. ‘n’ disks of differing diameters are placed on peg A so that the larger disk is always below a smaller disk. The objective is to move all the disks to peg C using peg B as auxiliary. Only the top disk on any peg may be moved to any other peg, and the larger disk may never rest on a smaller one.

Laboratory Experiment You task is to write a C++ program that simulate moves of n disks from one peg to another using a third peg as auxiliary. Make sure your code is well written and documented. Due date 25/6/2013 by 10:00 AM.

Hint: Example code The code on the next slide is written in C. You may use it as a guide to finish your project.

#include "stdio.h" void towers(int,char,char,char); void towers(int n,char frompeg,char topeg,char auxpeg) { /* If only 1 disk, make the move and return */ I f(n==1) printf("\nMove disk 1 from peg %c to peg %c",frompeg,topeg); return; } /* Move top n-1 disks from A to B, using C as auxiliary */ towers(n-1,frompeg,auxpeg,topeg); /* Move remaining disks from A to C */ printf("\nMove disk %d from peg %c to peg %c",n,frompeg,topeg); /* Move n-1 disks from B to C using A as auxiliary */ towers(n-1,auxpeg,topeg,frompeg);

The main program main() { int n; printf("Enter the number of disks : "); scanf("%d",&n); printf("The Tower of Hanoi involves the moves :\n\n"); towers(n,'A','C','B'); return 0; }

Good Luck