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

  • SEARCH
  • Home
  • 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 8512797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:22:49+00:00 2026-06-11T04:22:49+00:00

I am reading Algorithms by Robert Sedgewick Below is an excerpt from page 213,

  • 0

I am reading Algorithms by Robert Sedgewick

Below is an excerpt from page 213, in reference to number of trailing zeros in binary representation of numbers.

For the towers of Hanoi problem, the implication of the correspondence
with n-bit numbers is a simple algorithm for the task. We can move the
pile one peg to the right by following two steps until done:

  1. Move the small disk to the right if n is odd (left if n is even)
  2. Make the only legal move not involving the small disk.

That is, after we move the small dsik, the other two pegs contain two
disks, one smaller than the other. The only legal move not involving
the small disk is to move the smaller one onto the larger one. Every
other move involves the smaller disk for the same reason that every
other number is odd and that every other mark on the rule is the
shortest.

The above text is not getting into my head, even after reading various references from goolged information.

Please help me with a simple example for example disks N = 3. Disk3 is largest and Disk1 is smallest, and they need to be moved from from PegA to PegB.

Disk1
Disk2
Disk3
-------       ------------         ------------
Peg A            Peg B                 Peg C
  • 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-11T04:22:51+00:00Added an answer on June 11, 2026 at 4:22 am

    The first thing to note here is that in this algorithm, the first peg is considered to be right of the last peg, and the last peg is considered to be left of the first peg.

    Applying the two steps listed iteratively will result in a tower of n disks being moved right by one peg.

    In the case n = 3, n is odd, so the two moves are:

    1. Move Disk1 one peg right.
    2. Make the only legal move not involving Disk1.

    Giving the following solution by repeating these moves:

    1. Disk1: PegA -> PegB (Move Disk1 one peg right)
    2. Disk2: PegA -> PegC (Only legal move not involving Disk1)
    3. Disk1: PegB -> PegC (Move Disk1 one peg right)
    4. Disk3: PegA -> PegB (Only legal move not involving Disk1)
    5. Disk1: PegC -> PegA (Move Disk1 one peg right)
    6. Disk2: PegC -> PegB (Only legal move not involving Disk1)
    7. Disk1: PegA -> PegB (Move Disk1 one peg right)

    When he writes “the correspondence with n-bit numbers”, Sedgewick is referring to the fact that the disk you move in step k of the solution is the disk that corresponds to the least significant 1 bit in the binary representation of k. i.e. for n = 3:

    step | bits | disk
    ------------------
      1  |  001 |  1
      2  |  010 |  2
      3  |  011 |  1
      4  |  100 |  3
      5  |  101 |  1
      6  |  110 |  2
      7  |  111 |  1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm reading Robert Sedgewick's Algorithms 4th ed. book and the methods for finding
Reading the MCIMX50 Application Processor Reference Manuals on page 1368 (Section 33.3) there is
I'm reading Data structures and algorithms from Aho, Hopcroft & Ullman, and I'm confused
I have question that comes from a algorithms book I'm reading and I am
I am reading Algorithms book written by Robert Sedwick. Note: s is source and
I was reading an algorithms book which had the following algorithm for binary search:
I've been reading some binary search algorithms I found on the internet, and I
Reading algorithms by self using Robert Sedwick book in C++ A recursive function that
I am reading about queues in robert sedwick book on algorithms When the items
I am reading about FIFO queue array implementeation in Algorithms in C++ by Robert

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.