Top Banner
Tower of Hanoi Complexity of solutions of interesting variants of the known game
24

Tower of Hanoi Complexity of solutions of interesting variants of the known game.

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

Tower of Hanoi

Complexity of solutions of interesting variants of the known game

Page 2: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

Joint work with

Prof. Daniel Berend

CS , BGU

Page 3: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

The known game

• Three sticks (pegs, posts)

• n (64?) disks, different diameters

• No disk can be on top of a smaller one

• Well known initial and final configurations (regular conf.)

Page 4: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

Some pictures

Page 5: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

הכללים

בכל מהלך מזיזים בדיוק טבעת אחת •

היא חייבת להיות עליונה •באף שלב טבעת לא תהיה מונחת על קטנה •

)regular configurations(מצבים חוקיים – ממנה

Page 6: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

הגרסה הידועה

• Tower(N,src,dest,aux) • If |N| ≥ 1

– Tower(N-{|N|},src,aux,dest) – Put({|N|},src,dest) – Tower(N-{|N|},aux,dest,src)

• Time analysis – an = 2an-1 + 1 – a1 = 1 – an = 2n – 1

• Best possible

Page 7: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

What is it good for?

• Limited budget research

– 3 research tools; 3 9.99

• Other reasons

– Fun

– Teaching recursion in programming

– Next?

Page 8: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

גרסאות עיקריותגרסא מקורית

עמודי ם

...

גדולה על קטנה

Minsker

גישה

Scorer

Stockmeyer

וסיום התחלה

Er

צבעים

Minsker

קשירות לא חזקה

Leiss

Page 9: Tower of Hanoi Complexity of solutions of interesting variants of the known game.
Page 10: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

שאלות לכל גרסה

פתרון כלשהוא •

מקבילי מול איטרטיבי מולפתרון רקורסיבי •

זמן ריצה •

Page 11: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

נושאי השיחה

הקדמה

המקרה הקלאסי: חסמי מלעיל ומלרע •

מגבלות גישה בין העמודים •

דרך פתרון: דוגמא עם מסילה •

++Cyclicדוגמא מורכבת: •

אלגוריתם אחיד•

Page 12: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

נושאי השיחההקדמה

המקרה הקלאסי: חסמי מלעיל ומלרע • מגבלות גישה בין העמודים•

מיהם המקרים האפשריים? –כיצד לתאר גרסה? –כיצד לתאר פתרון? –תנאי הכרחי ומספיק לפתרון –

דרך פתרון: דוגמא עם מסילה • ++Cyclicדוגמא מורכבת: •האלגוריתם האחיד •

Page 13: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

Graphs for 3 pegs

1 2

3

1 2 3

מעגלי Cyclic Cyclic++

Complete --

Completeשלם

Pathמסילה

Page 14: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

תנאי הכרחי ומספיק

G .ק.ח G(n) .ק.ח

גרף מצבים

Page 15: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

נושאי השיחההקדמה

המקרה הקלאסי: חסמי מלעיל ומלרע •מגבלות גישה בין העמודים •דרך פתרון: דוגמא עם מסילה •

בעיות וסימטריה –נוסחאות נסיגה –פתרון מערכת נוסחאות – פתרון מדוקדק–

++Cyclicדוגמא מורכבת: • האלגוריתם האחיד•

Page 16: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

מסילה נוסחאות נסיגה •

– an = an-1 + bn-1 + 1

– bn = 3bn-1 + 2

13

132

1

nn

nn

b

a

Page 17: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

נושאי השיחההקדמה

המקרה הקלאסי: חסמי מלעיל ומלרע •מגבלות גישה בין העמודים •דרך פתרון: דוגמא עם מסילה • ++Cyclicדוגמא מורכבת: •

נוסחאות נסיגה –שקילות מענינת –פתרון מערכת נוסחאות –

האלגוריתם האחיד•

Page 18: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

פעולות •

– T12,{n} T13,{n-1} T12,n T32,{n-1}

– T13,{n} T13,{n-1} T12,n T31,{n-1} T23,n T13,{n-1}

– T21,{n} T23,{n-1} T21,n T31,{n-1}

– T23,{n} T21,{n-1} T23,n T13,{n-1}

– T31,{n} T32,{n-1} T31,n T21,{n-1}

– T32,{n} T32,{n-1} T31,n T23,{n-1} T21,n T32,{n-1}

Cyclic++

Page 19: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

נוסחאות נסיגה •

– an = 2bn-1 + 1

– bn = 2bn-1 + dn-1 + 2

– cn = 2dn-1 + 1

– dn = bn-1 + cn-1 + 1

Cyclic++

Page 20: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

Cyclic++

4

5

2

171

136

172185

2

171

136

172185

nn

nb

לדוגמא:

Page 21: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

נושאי השיחההקדמה

המקרה הקלאסי: חסמי מלעיל ומלרע •מגבלות גישה בין העמודים •דרך פתרון: דוגמא עם מסילה • ++Cyclicדוגמא מורכבת: • האלגוריתם האחיד•

הצגה –נכונות–

אופטימליות–

Page 22: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

עמודים3פתרון עבור • If n1 האלגוריתם

– If (src,dest) E(G) • Move the smallest n-1 disks from src to aux • Move disk number n from src to dest • Move the n-1 disks from aux to dest

– Else • Move the smallest n-1 disks from src to dest • Move disk number n from src to aux • Move the n-1 disks from dest to src • Move disk number n from aux to dest • Move the n-1 disks from src to dest

נכונות• אופטימליות•

Page 23: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

דוגמת ריצה ב ל-אהעברה מ-

ג ב א

Page 24: Tower of Hanoi Complexity of solutions of interesting variants of the known game.

דוגמת ריצה א ל-בהעברה מ-

ג ב א