Movatterモバイル変換


[0]ホーム

URL:


PPTX, PDF441 views

Tower of Hanoi

The document describes the Tower of Hanoi puzzle and its solution. The puzzle consists of three rods and disks of different sizes that can slide onto any rod. The goal is to move all disks from one rod to another, following three rules: only one disk can be moved at a time, only the top disk can be removed, and no disk can be placed on top of a smaller disk. The document provides an algorithm and recursive function to solve the puzzle by moving disks one by one from the source rod to the auxiliary rod and then to the destination rod. It also includes a C++ program that implements the Tower of Hanoi puzzle and solution.

Embed presentation

Download to read offline
• It consists of three rods, and a number of disks ofdifferent sizes which can slide onto any rod.• The puzzle starts with the disks in a neat stack inascending order of size on one rod, the smallest atthe top, thus making a conical shape.
RULES• The mission is to move all the disks to some anothertower without violating the sequence of arrangement.A few rules to be followed for Tower of Hanoi are −1. Only one disk can be moved among the towers at anygiven time.2. Only the "top" disk can be removed.3. No large disk can sit over a small disk.• Following is an animated representation of solving aTower of Hanoi puzzle with three disks.• Tower of Hanoi puzzle with n disks can be solved inminimum 2n−1 steps. It is shows that a puzzle with 3disks has taken 23 - 1 = 7 steps.
ALGORITHM• If we have only one disk ,then it can easily be moved fromsource to destination peg.• If we have 2 disks −• First, we move the smaller (top) disk to aux peg.• Then, we move the larger (bottom) disk to destinationpeg.• And finally, we move the smaller disk from aux todestination peg.• To move n disks from source to destination, The steps tofollow are -• Step 1 − Move n-1 disks from source to aux• Step 2 − Move nth disk from source to dest• Step 3 − Move n-1 disks from aux to dest
A recursive algorithm for Tower of Hanoi can bedriven as follows −• START• ProcedureHanoi(disk, source,dest, aux)• IF disk ==1, THEN– move disk from source to dest• ELSE• Move(disk -1, source, dest, aux)// Step 1• Move(1, source, aux,dest)// Step 2– move disk from source to dest• Move(disk -1, aux, source, dest)// Step 3• END IF• ENDProcedure• STOP
PROGRAM TO IMPLEMENT TOWEROF HANOI:• #include <iostream.h>• #include <conio.h>• void tower(int a, char source, char aux, char dest)• {• if(a==1)• {• cout<<"ttMove disc 1 from "<<source<<" to "<<dest<<"n";• return;• }• else{• tower(a-1,source,dest,aux);• cout<<"ttMove disc "<<a<<" from "<<souce<<" to "<<dest<<"n";• tower(a-1,aux,source,dest);• }• }
• void main()• {• clrscr();• int n;• cout<<"ntt*****Tower of Hanoi*****n";• cout<<"ttEnter number of discs : ";• cin>>n;• cout<<"nn";• tower(n,'A','B','C');• getch();• }
OUTPUT
Thank You

Recommended

PPTX
Memory Management in OS
PPTX
Page replacement algorithms
PDF
Unix Programming Lab
PDF
Hsc computer science chap 1 Operating System (1).pdf
PPTX
Paging and Segmentation in Operating System
PPT
Lecture 3,4
PPT
Greedy method by Dr. B. J. Mohite
PDF
Intro to AI STRIPS Planning & Applications in Video-games Lecture6-Part1
PPTX
Top down parsing
PPTX
Lecture 6- Deadlocks.pptx
PPTX
TOC Introduction
PPTX
Operating Systems
PPTX
Process management in linux
PPT
Shortest path
PPTX
Passes of Compiler.pptx
PDF
Introduction of suffix tree
PPTX
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
PPT
Disk scheduling algorithms
PPTX
Virtual memory management in Operating System
PPTX
cpu scheduling
PPT
Introduction to System Calls
PPT
SINGLE-SOURCE SHORTEST PATHS
PPTX
Operating Systems: Virtual Memory
PPTX
State space search
PDF
Chapter1 Formal Language and Automata Theory
PDF
Next Generation Technologies (November – 2018) [Choice Based | Question Paper]
PPTX
TOWERS OF HANOI_problemsolutionandexplanationwithalgorithm.pptx
PPTX
Tower Of Hanoi -A MatheMatical PuZzle

More Related Content

PPTX
Memory Management in OS
PPTX
Page replacement algorithms
PDF
Unix Programming Lab
PDF
Hsc computer science chap 1 Operating System (1).pdf
PPTX
Paging and Segmentation in Operating System
PPT
Lecture 3,4
PPT
Greedy method by Dr. B. J. Mohite
Memory Management in OS
Page replacement algorithms
Unix Programming Lab
Hsc computer science chap 1 Operating System (1).pdf
Paging and Segmentation in Operating System
Lecture 3,4
Greedy method by Dr. B. J. Mohite

What's hot

PDF
Intro to AI STRIPS Planning & Applications in Video-games Lecture6-Part1
PPTX
Top down parsing
PPTX
Lecture 6- Deadlocks.pptx
PPTX
TOC Introduction
PPTX
Operating Systems
PPTX
Process management in linux
PPT
Shortest path
PPTX
Passes of Compiler.pptx
PDF
Introduction of suffix tree
PPTX
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
PPT
Disk scheduling algorithms
PPTX
Virtual memory management in Operating System
PPTX
cpu scheduling
PPT
Introduction to System Calls
PPT
SINGLE-SOURCE SHORTEST PATHS
PPTX
Operating Systems: Virtual Memory
PPTX
State space search
PDF
Chapter1 Formal Language and Automata Theory
PDF
Next Generation Technologies (November – 2018) [Choice Based | Question Paper]
Intro to AI STRIPS Planning & Applications in Video-games Lecture6-Part1
Top down parsing
Lecture 6- Deadlocks.pptx
TOC Introduction
Operating Systems
Process management in linux
Shortest path
Passes of Compiler.pptx
Introduction of suffix tree
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
Disk scheduling algorithms
Virtual memory management in Operating System
cpu scheduling
Introduction to System Calls
SINGLE-SOURCE SHORTEST PATHS
Operating Systems: Virtual Memory
State space search
Chapter1 Formal Language and Automata Theory
Next Generation Technologies (November – 2018) [Choice Based | Question Paper]

Similar to Tower of Hanoi

PPTX
TOWERS OF HANOI_problemsolutionandexplanationwithalgorithm.pptx
PPTX
Tower Of Hanoi -A MatheMatical PuZzle
PPTX
Tower of Hanoi presentation
PDF
Tower of hanoi algorithm
PPTX
Tower of Hanoi
PPTX
Tower of hanoi
PPTX
Data structure lab
PPTX
Data Structure and Algorithms The Tower of Hanoi
PPT
Towers Hanoi Algorithm
PPTX
Tower of hanoi
PPT
towers of hanoi
PPTX
Tower of Hanoi Method
PPTX
Tower Of Hanoi
PDF
The Towers of Hanoi puzzle has three posts and some number n of disk.pdf
PPT
AI concept every important Tower Of Honoi.ppt
PPTX
Data structure
PPTX
Recusion
PPT
Tower of honoi using open source code python
PPTX
Tower of hanoi
PPTX
DS EXPERIENTIAL TOWER OF HANOI IMPLEMENT TOWER OF HANOI PROBLEM USING STACK...
TOWERS OF HANOI_problemsolutionandexplanationwithalgorithm.pptx
Tower Of Hanoi -A MatheMatical PuZzle
Tower of Hanoi presentation
Tower of hanoi algorithm
Tower of Hanoi
Tower of hanoi
Data structure lab
Data Structure and Algorithms The Tower of Hanoi
Towers Hanoi Algorithm
Tower of hanoi
towers of hanoi
Tower of Hanoi Method
Tower Of Hanoi
The Towers of Hanoi puzzle has three posts and some number n of disk.pdf
AI concept every important Tower Of Honoi.ppt
Data structure
Recusion
Tower of honoi using open source code python
Tower of hanoi
DS EXPERIENTIAL TOWER OF HANOI IMPLEMENT TOWER OF HANOI PROBLEM USING STACK...

More from Varunjeet Singh Rekhi

PPTX
Natural Language Processing
PPTX
Transistors and Applications
PPTX
Expert Systems
PPTX
Production System
PPTX
Tic Tac Toe
PPT
Simple Harmonic Motion
PPTX
SCSI Interfaces
PPTX
Video DIsplay Technologies
PPTX
Reconnaissance and Social Engineering
PPTX
Bullet trains
Natural Language Processing
Transistors and Applications
Expert Systems
Production System
Tic Tac Toe
Simple Harmonic Motion
SCSI Interfaces
Video DIsplay Technologies
Reconnaissance and Social Engineering
Bullet trains

Recently uploaded

PDF
The partnership effect: Libraries and publishers on collaborating and thrivin...
PDF
Top 10 AI Development Companies in UK 2025
PPTX
Leon Brands - Intro to GPU Occlusion (Graphics Programming Conference 2024)
PDF
MuleSoft Meetup: Dreamforce'25 Tour- Vibing With AI & Agents.pdf
PDF
Mastering Agentic Orchestration with UiPath Maestro | Hands on Workshop
PDF
Beyond Basics: How to Build Scalable, Intelligent Imagery Pipelines
PDF
Dev Dives: Build smarter agents with UiPath Agent Builder
PDF
Crane Accident Prevention Guide: Key OSHA Regulations for Safer Operations
PDF
[BDD 2025 - Mobile Development] Exploring Apple’s On-Device FoundationModels
PPTX
Support, Monitoring, Continuous Improvement & Scaling Agentic Automation [3/3]
PDF
How Much Does It Cost to Build an eCommerce Website in 2025.pdf
PDF
[BDD 2025 - Artificial Intelligence] AI for the Underdogs: Innovation for Sma...
PDF
Oracle MySQL HeatWave - One Page - Version 3
PDF
The Necessity of Digital Forensics, the Digital Forensics Process & Laborator...
PDF
Transcript: The partnership effect: Libraries and publishers on collaborating...
PDF
Running Non-Cloud-Native Databases in Cloud-Native Environments_ Challenges a...
PDF
"DISC as GPS for team leaders: how to lead a team from storming to performing...
 
PDF
ODSC AI West: Agent Optimization: Beyond Context engineering
PDF
[BDD 2025 - Artificial Intelligence] Building AI Systems That Users (and Comp...
PPTX
How to Choose the Right Vendor for ADA PDF Accessibility and Compliance in 2026
The partnership effect: Libraries and publishers on collaborating and thrivin...
Top 10 AI Development Companies in UK 2025
Leon Brands - Intro to GPU Occlusion (Graphics Programming Conference 2024)
MuleSoft Meetup: Dreamforce'25 Tour- Vibing With AI & Agents.pdf
Mastering Agentic Orchestration with UiPath Maestro | Hands on Workshop
Beyond Basics: How to Build Scalable, Intelligent Imagery Pipelines
Dev Dives: Build smarter agents with UiPath Agent Builder
Crane Accident Prevention Guide: Key OSHA Regulations for Safer Operations
[BDD 2025 - Mobile Development] Exploring Apple’s On-Device FoundationModels
Support, Monitoring, Continuous Improvement & Scaling Agentic Automation [3/3]
How Much Does It Cost to Build an eCommerce Website in 2025.pdf
[BDD 2025 - Artificial Intelligence] AI for the Underdogs: Innovation for Sma...
Oracle MySQL HeatWave - One Page - Version 3
The Necessity of Digital Forensics, the Digital Forensics Process & Laborator...
Transcript: The partnership effect: Libraries and publishers on collaborating...
Running Non-Cloud-Native Databases in Cloud-Native Environments_ Challenges a...
"DISC as GPS for team leaders: how to lead a team from storming to performing...
 
ODSC AI West: Agent Optimization: Beyond Context engineering
[BDD 2025 - Artificial Intelligence] Building AI Systems That Users (and Comp...
How to Choose the Right Vendor for ADA PDF Accessibility and Compliance in 2026
In this document
Powered by AI

The Tower of Hanoi consists of three rods and disks of different sizes stacked in ascending order.

The mission is to move disks between towers with restrictions on movement and arrangement. Minimum steps for n disks is 2n−1.

Details the step-by-step process to move disks recursively from source to destination and auxiliary rods.

Presents a recursive procedure for the Tower of Hanoi, demonstrating the algorithm in a structured format.

Shows a C++ implementation of the Tower of Hanoi algorithm, including code for moving disks and user interaction.

Placeholding slide for displaying program output.

Final slide thanking the audience.

Tower of Hanoi

  • 2.
    • It consistsof three rods, and a number of disks ofdifferent sizes which can slide onto any rod.• The puzzle starts with the disks in a neat stack inascending order of size on one rod, the smallest atthe top, thus making a conical shape.
  • 3.
    RULES• The missionis to move all the disks to some anothertower without violating the sequence of arrangement.A few rules to be followed for Tower of Hanoi are −1. Only one disk can be moved among the towers at anygiven time.2. Only the "top" disk can be removed.3. No large disk can sit over a small disk.• Following is an animated representation of solving aTower of Hanoi puzzle with three disks.• Tower of Hanoi puzzle with n disks can be solved inminimum 2n−1 steps. It is shows that a puzzle with 3disks has taken 23 - 1 = 7 steps.
  • 4.
    ALGORITHM• If wehave only one disk ,then it can easily be moved fromsource to destination peg.• If we have 2 disks −• First, we move the smaller (top) disk to aux peg.• Then, we move the larger (bottom) disk to destinationpeg.• And finally, we move the smaller disk from aux todestination peg.• To move n disks from source to destination, The steps tofollow are -• Step 1 − Move n-1 disks from source to aux• Step 2 − Move nth disk from source to dest• Step 3 − Move n-1 disks from aux to dest
  • 5.
    A recursive algorithmfor Tower of Hanoi can bedriven as follows −• START• ProcedureHanoi(disk, source,dest, aux)• IF disk ==1, THEN– move disk from source to dest• ELSE• Move(disk -1, source, dest, aux)// Step 1• Move(1, source, aux,dest)// Step 2– move disk from source to dest• Move(disk -1, aux, source, dest)// Step 3• END IF• ENDProcedure• STOP
  • 8.
    PROGRAM TO IMPLEMENTTOWEROF HANOI:• #include <iostream.h>• #include <conio.h>• void tower(int a, char source, char aux, char dest)• {• if(a==1)• {• cout<<"ttMove disc 1 from "<<source<<" to "<<dest<<"n";• return;• }• else{• tower(a-1,source,dest,aux);• cout<<"ttMove disc "<<a<<" from "<<souce<<" to "<<dest<<"n";• tower(a-1,aux,source,dest);• }• }
  • 9.
    • void main()•{• clrscr();• int n;• cout<<"ntt*****Tower of Hanoi*****n";• cout<<"ttEnter number of discs : ";• cin>>n;• cout<<"nn";• tower(n,'A','B','C');• getch();• }
  • 10.
  • 11.

[8]ページ先頭

©2009-2025 Movatter.jp