Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done with Program for Tower of Hanoi #510

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Done with Program for Tower of Hanoi #510

wants to merge 3 commits into from

Conversation

Eureka-Viraj
Copy link

Tower of

My Approach :
Take an example for 2 disks :
Let rod 1 = 'A', rod 2 = 'B', rod 3 = 'C'.

Step 1 : Shift first disk from 'A' to 'B'.
Step 2 : Shift second disk from 'A' to 'C'.
Step 3 : Shift first disk from 'B' to 'C'.

The pattern here is :
Shift 'n-1' disks from 'A' to 'B'.
Shift last disk from 'A' to 'C'.
Shift 'n-1' disks from 'B' to 'C'.

for better understanding
look at this image
image

issue fixed #496

My Approach : 
Take an example for 2 disks :
Let rod 1 = 'A', rod 2 = 'B', rod 3 = 'C'.

Step 1 : Shift first disk from 'A' to 'B'.
Step 2 : Shift second disk from 'A' to 'C'.
Step 3 : Shift first disk from 'B' to 'C'.

The pattern here is :
Shift 'n-1' disks from 'A' to 'B'.
Shift last disk from 'A' to 'C'.
Shift 'n-1' disks from 'B' to 'C'.

Image illustration for 3 disks :
@welcome
Copy link

welcome bot commented Oct 2, 2021

Thanks for opening this pull request! Please be sure that you have checked out our contributing guidelines.

Different STL-based representation is used that can be helpful to quickly implement graphs using vectors. The implementation is for the adjacency list representation of the graph.
Idea is to represent a graph as an array of vectors such that every vector represents the adjacency list of a vertex.
Copy link
Author

@Eureka-Viraj Eureka-Viraj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are known

  1. A finite set of vertices also called as nodes.
  2. A finite set of ordered pair of the form (u, v) called as edge. The pair is ordered because (u, v) is not the same as (v, u) in case of a directed graph(di-graph). The pair of the form (u, v) indicates that there

This is an example of an undirected graph with 5 vertices.
image

fixed #497

@amritansh22
Copy link
Owner

Please star this repository to show your support. In the meantime I am reviewing your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tower of hanoi
2 participants