5. (40 points) The figures below illustrate an algorithm for a variant of the Tower of Hanoi game, played on 4 posts. The goal is the same: move a stack of n disks of increasing size from one post to another, using the other two posts for temporary storage, and during the process never place a larger disk on top of a smaller one. The procedure includes five steps, with steps (2), (3), (4) each comprising a single move, and steps (1) and (5) correspond to recursive calls. a) b) A B C C D A=1 Initially, n disks are placed on post A. The (n-2) smallest disks on top of the stack are represented as A. the two largest disks sit at the bottom (1): Recursively, move the (n-2) disks on top of the stack, from A to B, using C and D for temporary storage during the process (2): Move the second largest disk, now sitting on top of A, from A to C (3): Move the largest disk, now the only disk in A, from A to D (4): Move the second largest disk from C to D, to sit on top of the largest disk (5): Recursively, move the stack of (n-2) disks from B to D, using A and C for temporary storage during the process Write a recurrence relation to describe the complexity (in terms of the number of moves) of the recursive algorithm. Derive the solution to your recurrence relation, assume n is an even number. c) Express the solution in big O notation. d) Likewise, the problem can be solved by first recursively moving the (n-3) disks on top from A to B, then move the 3 largest disks at the bottom from A to D, then recursively move the (n-3) disks from B to D. Write the recurrence relation for the complexity for this algorithm.
5. (40 points) The figures below illustrate an algorithm for a variant of the Tower of Hanoi game, played on 4 posts. The goal is the same: move a stack of n disks of increasing size from one post to another, using the other two posts for temporary storage, and during the process never place a larger disk on top of a smaller one. The procedure includes five steps, with steps (2), (3), (4) each comprising a single move, and steps (1) and (5) correspond to recursive calls. a) b) A B C C D A=1 Initially, n disks are placed on post A. The (n-2) smallest disks on top of the stack are represented as A. the two largest disks sit at the bottom (1): Recursively, move the (n-2) disks on top of the stack, from A to B, using C and D for temporary storage during the process (2): Move the second largest disk, now sitting on top of A, from A to C (3): Move the largest disk, now the only disk in A, from A to D (4): Move the second largest disk from C to D, to sit on top of the largest disk (5): Recursively, move the stack of (n-2) disks from B to D, using A and C for temporary storage during the process Write a recurrence relation to describe the complexity (in terms of the number of moves) of the recursive algorithm. Derive the solution to your recurrence relation, assume n is an even number. c) Express the solution in big O notation. d) Likewise, the problem can be solved by first recursively moving the (n-3) disks on top from A to B, then move the 3 largest disks at the bottom from A to D, then recursively move the (n-3) disks from B to D. Write the recurrence relation for the complexity for this algorithm.
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter16: Searching, Sorting And Vector Type
Section: Chapter Questions
Problem 1TF
Related questions
Question
I am going back through a problem from the image from a previous quiz. I am wondering on 5b why is is important that n is an even or odd number?

Transcribed Image Text:5.
(40 points) The figures below illustrate an algorithm for a variant of the Tower of Hanoi game, played on 4 posts. The goal is
the same: move a stack of n disks of increasing size from one post to another, using the other two posts for temporary storage,
and during the process never place a larger disk on top of a smaller one. The procedure includes five steps, with steps (2), (3), (4)
each comprising a single move, and steps (1) and (5) correspond to recursive calls.
a)
b)
A
B C
C
D
A=1
Initially, n disks are placed on post A. The (n-2) smallest disks on top of the stack are represented as A.
the two largest disks sit at the bottom
(1): Recursively, move
the (n-2) disks on top of the stack, from A to B, using C and D for temporary
storage during the process
(2): Move the second largest disk, now sitting on top of A, from A to C
(3): Move the largest disk, now the only disk in A, from A to D
(4): Move the second largest disk from C to D, to sit on top of the largest disk
(5): Recursively, move the stack of (n-2) disks from B to D, using A and C for temporary storage
during the process
Write a recurrence relation to describe the complexity (in terms of the number of moves) of the recursive algorithm.
Derive the solution to your recurrence relation, assume n is an even number.
c)
Express the solution in big O notation.
d)
Likewise, the problem can be solved by first recursively moving the (n-3) disks on top from A to B, then move the 3 largest disks at the bottom
from A to D, then recursively move the (n-3) disks from B to D. Write the recurrence relation for the complexity for this algorithm.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Recommended textbooks for you

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr

Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr

Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning

Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage