On Optimal Solutions for the Bottleneck Tower of Hanoi Problem Yefim Dinitz Shay Solomon Dept. of Comp. Sci., Ben-Gurion University ISRAEL.

Slides:



Advertisements
Similar presentations
한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님
Advertisements

Analysis of Algorithms II
Algorithmic Time Complexity Basics
Tower of Hanoi Tower of Hanoi is a mathematical puzzle invented by a French Mathematician Edouard Lucas in The game starts by having few discs stacked.
CS1010: Programming Methodology
Week 6 - Wednesday CS322.
CSED101 INTRODUCTION TO COMPUTING GREEDY APPROACH, DIVIDE AND CONQUER Hwanjo Yu.
Chapter 8 Recursion. 8.1 Recursively Defined Sequences.
Chapter Recurrence Relations
Introduction to Algorithms
State Space Representation and Search
Chapter 6 Advanced Counting 6.1 Recurrence Relations.
Analyzing Algorithms and Problems Prof. Sin-Min Lee Department of Computer Science.
Problem definition The Tower of Hanoi is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can.
Recursion Lecture 18: Nov 18.
Bounds on Code Length Theorem: Let l ∗ 1, l ∗ 2,..., l ∗ m be optimal codeword lengths for a source distribution p and a D-ary alphabet, and let L ∗ be.
Complexity 15-1 Complexity Andrei Bulatov Hierarchy Theorem.
Infinite Sequences and Series
1 On a question of Leiss regarding the Towers of Hanoi problem.
Creating Difficult Instances of the Post Correspondence Problem Presenter: Ling Zhao Department of Computing Science University of Alberta March 20, 2001.
Chapter 10 Recursion. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Explain the underlying concepts of recursion.
Recursion.
The Tower of Hanoi
1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
6.Advanced Counting Techniques 1 Copyright M.R.K. Krishna Rao 2003 Ch 6. Recurrence Relations A recurrence relation for the sequence {a n } is an equation.
Lecture 3: Algorithms and Complexity Study Chapter COMP 555 Bioalgorithms Fall 2014.
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Copyright © Cengage Learning. All rights reserved.
Advanced Counting Techniques
Week 6 - Monday CS322.
Analysis of Algorithm Lecture 3 Recurrence, control structure and few examples (Part 1) Huma Ayub (Assistant Professor) Department of Software Engineering.
Recursion Chapter 7 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
The importance of sequences and infinite series in calculus stems from Newton’s idea of representing functions as sums of infinite series.  For instance,
13.2 Recursive Definitions Objective 1) Provide the recursive definition for sequences; 2) Identify the type of a sequence from a recursive definition.
CHAPTER 02 Recursion Compiled by: Dr. Mohammad Omar Alhawarat.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
CSE 2813 Discrete Structures Recurrence Relations Section 6.1.
Module #20 - Recurrences 1 Ch. 7 Recurrence Relations Rosen 6 th ed., §§7.1.
15.1 CompSci 102© Michael Frank Today’s topics Recurrence relationsRecurrence relations –Stating recurrences –LiHoReCoCo Reading: Sections Reading:
Module #17: Recurrence Relations Rosen 5 th ed., §
1 COMP3040 Tutorial 1 Analysis of algorithms. 2 Outline Motivation Analysis of algorithms Examples Practice questions.
Chapter 4 Recursion. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Explain the underlying concepts of recursion.
The Selection Problem. 2 Median and Order Statistics In this section, we will study algorithms for finding the i th smallest element in a set of n elements.
Complexity A decidable problem is computationally solvable. But what resources are needed to solve the problem? –How much time will it require? –How much.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Recurrence.
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Data Structures & Algorithms Recursion and Trees Richard Newman.
Recursive Algorithms A recursive algorithm calls itself to do part of its work The “call to itself” must be on a smaller problem than the one originally.
CHAPTER TWO RECURRENCE RELATION
Discrete Mathematics Lecture # 22 Recursion.  First of all instead of giving the definition of Recursion we give you an example, you already know the.
UNIT 17 Recursion: Towers of Hanoi.
1 In this puzzle, the player begins with n disks of decreasing diameter placed one on top of the other on one of three pegs of the game board. The player.
Recursively Defined Sequences Lecture 40 Section 8.1 Wed, Apr 11, 2007.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
1 Towers of Hanoi Three pegs, one with n disks of decreasing diameter; two other pegs are empty Task: move all disks to the third peg under the following.
Discrete Math For Computing II. Contact Information B. Prabhakaran Department of Computer Science University of Texas at Dallas Mail Station EC 31, PO.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
Algorithm Analysis 1.
Recursion.
COMP108 Algorithmic Foundations Divide and Conquer
Introduction to Recurrence Relations
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Copyright © Cengage Learning. All rights reserved.
Copyright © Cengage Learning. All rights reserved.
The Selection Problem.
Recurrence Relations Rosen 5th ed., §6.2 5/22/2019
Presentation transcript:

On Optimal Solutions for the Bottleneck Tower of Hanoi Problem Yefim Dinitz Shay Solomon Dept. of Comp. Sci., Ben-Gurion University ISRAEL

Contents of the lecture 1. Background on the Tower of Hanoi. 2. The Bottleneck Tower of Hanoi (BTH) problem. 3. The family of all optimal solutions to BTH. 4. Investigation of the configuration graph of BTH: its diameter and average distance.

1. Background The first version of the puzzle was marketed by Edouard Lucas in 1883, under the name "Tower of Hanoi: - Given are 3 pegs, denoted by A,B and C, and n disks of distinct sizes placed on peg A in decreasing order, largest at the bottom to the smallest at the top. - The goal of the puzzle is to transfer all disks to peg C, placed in the same order, by the minimum possible number of moves. - The rules are to move a single disk from (the top of) one peg to (the top of) another one at each step, following the "divine rule": to never have a larger disk above a smaller one.

1 2 … n-1 n A B C Example for general n Move number

1 2 … n-1 A B C The optimal transfer for general n n Move number C n-1

1 2 … n-1 A B C n Move number C n The optimal transfer for general n

1 2 … n-1 n A B C Move number 2 C n The optimal transfer for general n

The recurrence formula is c n = 2c n-1 + 1, c 1 = 1. Hence, c n = 2^n -1. This classical Tower of Hanoi problem with three pegs is a basic problem, taught as a basic example of a recursion program.

There is a great proliferation of new ToH puzzles posed over the last twenty years. There is a bibliography made by Paul Stockmeyer, which covers over 350 papers on the subject.

In 1981, D. Wood posed the following generalization of ToH, which we call the Bottleneck Tower of Hanoi Problem, BTH n= BTH n,k, depending on an integer parameter k, k>0. 2. The Bottleneck ToH problem

The k-relaxed Placement Rule: Besides the usual placement of smaller disks above bigger ones, a bigger disk j may be placed above a smaller disk i, if their size difference j - i < k. i+k …. i

A placement of the n disks [1..n] on a single peg is called a tower of n disks. The decreasing bottom-top placement of the n disks [1..n] on a peg is called the perfect tower … n-2 n-1 n Definitions

Description of BTH n : There are 3 pegs: A,B, and C. The goal is to transfer the perfect tower on peg A to the perfect tower on peg C. The placement rule is k-relaxed. (Note that if k=1, we arrive at the classical problem.)

Example: k=4, n=7 Legal We note that there are many legal towers for a given k. As k grows, there are more legal towers. (The two extreme) examples: k=1, one legal tower (perfect tower). kn, n! possible towers.

D.Poole [1992] suggested the sequence of moves α n (described in the next slide), which solves BTH n. He showed its optimality within just one simple strategy. Beneditkis, Berend, and Safro [1998] proved its optimality for the case k=2. We proved optimality of α n for the general case [ISAAC2006]. Remark: another proof of optimality of α n for BTH n, by different techniques, was suggested independently by Xiaomin Chen et al. (unpublished).

α n (A,C) (not explicitly) 1.(*) Move disks [1..(n-1)] from A, by the minimum possible number of moves, to any (legal) state on B. 2. Move disk n from A to C. 3.(*) Move disks [1..(n-1)] from B to the perfect tower on C, by the minimum possible number of moves.

…. n-1 n A C B

[1..n-1] n A C B

A C B n

n A C B …. n-1

Somehow tower-move(*): To move a tower of m disks on one peg, to a tower of m disks on another peg, in any order. D. Poole and BBS used, for the somehow problem, the following optimal sequence of moves, β m :

β m (source,target): (for the explanation, assume that the initial configuration is perfect) If m k, move all disks from source to target one by one. Otherwise: 1. Recursively perform β m-k (source,auxiliary). 2. Move k disks [(m-k+1)..m] one by one from source to target. 3. Recursively perform β m-k (auxiliary,target).

K=4, m=7 source auxiliary target

K=4, m=11 source auxiliary target

source auxiliary target

source auxiliary target

source auxiliary target

(**) We remark that, if we start with the perfect tower on A, and perform β m (A,B) followed by β m (B,C), the result is the perfect tower on C.

α n (A,C), reformulated 1. perform β n-1 (A,B). 2. Move disk n from A to C. 3. perform β n-1 (B,C). By earlier remark (**), α n solves BTH n.

…. n-1 n A C B

n A C B …. n-k-1 n-1 …. n-k+1 n-k

A C B …. n-k-1 n-1 …. n-k+1 n-k n

n A C B …. n-1

Notation and numerical results b m = The number of moves in β m a n = The number of moves in α n b m = 2b m-k + k ; b 1 = 1,…, b k = k. b m = r ( 2^q) + k (2^q -1), where m = qk +r. a n = 2b n ; a 1 = 1. a n = r (2^(q+1)) + k (2^(q+1) -2) + 1, where n-1=qk + r.

3. Family of all optimal solutions to BTH n We prove that, in any optimal solution to BTH n, disk n makes only one move, from peg A to C. Before that move, all disks 1,…,n-1 have been moved from peg A to peg B. After that move, all disks 1,..,n-1 will move from peg B to peg C.

Is α n the unique optimal solution? In the case k=1, the answer is yes (and is well known): there exists a unique solution for the classical problem. For the case k 2, the answer is No! Let us see a different sequence of moves, of the same length as that of α n :

Example n=10, k=3 A B C

A B C

A B C

A B C

A B C

Until this point, the move- sequence is the same as α n A B C

A B C

A B C

A B C

A B C

A B C

A B C

A B C

A B C

A B C

A B C

Tower-Move tower-move – A sequence of moves that transfers a tower on one peg to a tower on another peg. For example: - α n is a shortest perfect-to-perfect tower-move of n disks. - β m is a shortest somehow tower-move of m disks.

General structure of an optimal tower-move It should be similar to the structure of the (recursive) classic Tower of Hanoi solution, but the transfer unit is a block of k disks (as in the example). Main Proposition 1: The only possible change, in an optimal solution, may be to interleave the two upper blocks. Main Observation 2: The ways of interleaving, each time, are independent.

How many optimal solutions exist? Any optimal solution (i.e., a shortest p.t.p. tower move of [1..n]) contains 2^((n-1)/k-1) tower- moves of the union of the two upper blocks. For any such even-numbered tower-move, except for the last tower-move, its final configuration can be chosen arbitrarily from a certain set (**) of C(k+r,k)-C(k+r,k+1) configurations. These are the only choices, for an optimal solution.

An auxiliary problem equivalent to (**): Let n t+p. What is the number of integer solutions that satisfy the two following conditions: xi =n, i=[0..t], xi0. xi j+p, 0j n-p, i=[0..j]. How many such configurations exist?

The number of different solutions to (**) is: C(n+t,t) – C(n+t,t+p+1)

The number of all optimal solutions to BTH n is: k 2: (C(k+r,k)-C(k+r,k+1))^[ 2^((n-1)/k-2) -1], where r= (n-1) mod k. k=1: A unique optimal solution

4.1 Diameter of the configuration graph Questions : 1. Find a pair of disk arrangements over A,B and C, requiring the longest sequence of moves in order to get from one to the other. 2. Find the length of that sequence (later referred as diameter). Let us translate these questions to the language of graphs:

For BTH n, the corresponding configuration graph, G=(V,E) is the (undirected) graph s.t.: V is the set of all legal arrangements of the n disks over A, B and C. E = {e=(u,v)| u,v in V, s.t. u and v are reachable one from the other by a single move}.

The configuration graph for the case n=2,k=2 (2,1),(),() (2),(1),() (2),(),(1) (),(1,2),() (),(1),(2) (),(),(2,1) (1),(),(2) (),(),(1,2) (1,2),(),() (),(2),(1) (),(2,1),() (1),(2),()

The diameter is 4 (2,1),(),() (2),(1),() (2),(),(1) (),(1,2),() (),(1),(2) (),(),(2,1) (1),(),(2) (),(),(1,2) (1,2),(),() (),(2),(1) (),(2,1),() (1),(2),()

We found the answer for the second question, i.e. the diameter, D(n,k), up to a constant factor. D(n,k) = Θ((k^2)2^(n/k)) This is k times the shortest length of a perfect-to-perfect tower-move. Reminder: a n = Θ(k 2^(n/k))

Tighter bounds for D(n,k): Let n k D(n,k) = Θ(nlogn). Let k n 2k D(n,k) = Θ(nlogn + (n-k)^2). For n>2k: D(n,k) = Θ((k^2)2^(n/k)).

We believe (based on similar open questions raised by D. Knuth) that both afore- mentioned questions: 1. Finding a pair of disk arrangements requiring a longest sequence of moves. 2. Finding the length of that sequence (i.e, the previously mentioned diameter) exactly. should be difficult even for the (degenerate) case nk.

4.2 Average distance We find the average number of moves required to get from one configuration to another, taken over all pairs of configurations, up to a constant factor. In other words, we bound the average distance between nodes in the configuration graph of BTHn.

We prove that the average, Avg(n,k), is asymptotically the same as the afore- mentioned diameter. For n 3k: Avg(n,k) = Θ (D(n,k)) = Θ ((k^2)2^(n/k)) This is k times the shortest length of a p.t.p. tower-move.

Avg(n,k) for some values of n vs. k: Let n k: Avg(n,k) = Θ(D(n,k)) = Θ(nlogn). For n>3k: Avg(n,k) = Θ(D(n,k)) = Θ((k^2)2^(n/k)).

In our paper at ISAAC06, we considered optimal algorithms for ToH problems with generalized placement rules. We appreciate your attention.

The w ay of proof (for diameter) Upper bound: We show an explicit way to transfer any tower of n disks in O((k^2)2^(n/k)) moves.

Lower bound Observation. When any disk out of the k biggest disks [(n-k+1)..n] moves, all n-2k disks in [1..(n- 2k)] should be on the spare peg. We show two configurations of the k biggest disks, such that any tower-move between them requires Ω(k) changes of the spare peg. As a consequence, for those configurations and the case n>2k, Ω(k) tower-moves of the n-2k smallest disks are required. As we know, each one of those tower-moves requires Ω(k2^((n-2k)/k)) moves.