{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

E7_Su2010_Solutions5_4-5

E7_Su2010_Solutions5_4-5 - Lab 5 Partial Solutions Lab 5...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab 5, Partial Solutions Contents Problem 4 (Towers of Hanoi) (a) (b) (c) (d) Problem 5 (Fibonacci Sequence) (a) (b) (c) Problem 4 (Towers of Hanoi) (a) According to Figure 12, It takes _S(N)_ steps to uncover disk _N+1_. It takes just one step to move disk _N+1_ to its final position. It takes another _S(N)_ steps to put the remaining _N_ disks back on top of disk _N+1_. Therefore, _S(N+1) = S(N) + 1 + S(N) = 2*S(N) + 1_. (b) type towersteps function S = towersteps(N) if N == 1 S = 1; else % Use the recurrence relation from part (a) S = 2*towersteps(N-1) + 1; end towersteps(1) ans = 1 towersteps(2) ans = 3 7/19/2010 Lab 5, Partial Solutions C:/…/lab05soln.html 1/5
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
towersteps(3) ans = 7 towersteps(10) ans = 1023 towersteps(64) ans = 1.8447e+019 (c) numDisks = towersteps(64); disksPerSecond = 1; secondsPerMin = 60; secondsPerHour = 60*secondsPerMin; secondsPerDay = 24*secondsPerHour; secondsPerYear = 365*secondsPerDay; numYears = numDisks/disksPerSecond/secondsPerYear numYears = 5.8494e+011 (d) type towers function towers(n,initialTower,finalTower) if n == 1 % If we only have one disk to move, that disk is always 'Disk 1'.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.
  • Summer '08
  • Patzek
  • Fibonacci number, Tower Tower Tower, Tower Tower Tower Tower Tower Tower Tower Tower Tower Tower Tower Tower Tower Tower Tower

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern