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.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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?
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
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education