Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8543013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:12:12+00:00 2026-06-11T12:12:12+00:00

I am reading algorithms in C++ book by RobetSedwick. Here author is explaning about

  • 0

I am reading algorithms in C++ book by RobetSedwick. Here author is explaning about Towers of Hanoi using divide and conquer design and recurrence.

Followin code is recursion solution to the proble. It specifies which disk should be shifted at each step, and in which direction (+ means move one peg to the right, cycling to the leftmost peg when on the right most peg; and – means move one peg to the left, cycling to the right most peg when on the left most peg).

Disk3          
Disk2
Disk1

Peg1      Peg2   Peg3

My question what does author mean above “cycling to the leftmost peg” when disk is on left peg (ie., Peg 1) how do we cyclic to left most peg?

Author also mentioned that Recursion is based on following idea: To move N disks one peg to the right, we first move top N-1 disk one peg to the left, then shift disk N one peg to the right, then move N-1 disks one more peg to the left (on to disk N).

I am confused with left and right terminology above. Can any one please explain.

void hanoi(int N, int d)
  {
    if (N == 0) return;
    hanoi(N-1, -d);
    shift(N, d);    
    hanoi(N-1, -d);
  } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:12:14+00:00Added an answer on June 11, 2026 at 12:12 pm

    It just means:

    Cycling to the right:

    peg1 -> peg2
    peg2 -> peg3
    peg3 -> peg1
    

    Cycling to the left

    peg1 -> peg3
    peg2 -> peg1
    peg3 -> peg2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading my algorithms text book, and I'm reading about recurrence relations and finding
I'm reading about STL algorithms and the book pointed out that algorithms like find
I'm reading Introduction to Algorithms book, second edition, the chapter about Medians and Order
I am reading about Dynamic programming in Cormen etc book on algorithms. following is
I am reading about list traversals in Algorithms book by RobertSedwick. Function definitions are
Reading algorithms by self using Robert Sedwick book in C++ A recursive function that
I am reading about string algorithms in Cormen's book Introduction to Algorithms. For Transition
I am reading about queues in robert sedwick book on algorithms When the items
I am reading about network flow algorithms in Robert Sedwicks book on Graph algorithms.
I'm reading book about php, and here is task to print elements of array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.