Tower of Hanoi Complexity of solutions of interesting

  • Slides: 24
Download presentation
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

Joint work with Prof. Daniel Berend CS , BGU

Joint work with Prof. Daniel Berend CS , BGU

The known game • Three sticks (pegs, posts) • n (64? ) disks, different

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. )

Some pictures

Some pictures

 הגרסה הידועה • Tower(N, src, dest, aux) • If |N| ≥ 1 –

הגרסה הידועה • 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 = 2 an-1 + 1 – a 1 = 1 – an = 2 n – 1 • Best possible

What is it good for? • Limited budget research – 3 research tools; 3

What is it good for? • Limited budget research – 3 research tools; 3 9. 99 • Other reasons – Fun – Teaching recursion in programming – Next?

Graphs for 3 pegs 1 Cyclic 2 מעגלי Cyclic++ Complete-- 3 Complete שלם Path

Graphs for 3 pegs 1 Cyclic 2 מעגלי Cyclic++ Complete-- 3 Complete שלם Path 1 2 3 מסילה

Cyclic++ • פעולות – T 12, {n} T 13, {n-1} T 12, n T

Cyclic++ • פעולות – T 12, {n} T 13, {n-1} T 12, n T 32, {n-1} – T 13, {n} T 13, {n-1} T 12, n T 31, {n-1} T 23, n T 13, {n-1} – T 21, {n} T 23, {n-1} T 21, n T 31, {n-1} – T 23, {n} T 21, {n-1} T 23, n T 13, {n-1} – T 31, {n} T 32, {n-1} T 31, n T 21, {n-1} – T 32, {n} T 32, {n-1} T 31, n T 23, {n-1} T 21, n T 32, {n-1}

 עמודים 3 פתרון עבור • If n 1 האלגוריתם – If (src, dest)

עמודים 3 פתרון עבור • If n 1 האלגוריתם – 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 • נכונות • אופטימליות