Problem_Set_03_Solutions - \documentclass[12pt]cfw_article...

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

View Full Document Right Arrow Icon
\documentclass[12pt]{article} \title{Problem Set 3 Solutions} \usepackage{fullpage} \usepackage[dvips]{graphicx} \author{Jeffrey M. Radcliffe} \begin{document} \maketitle \ \section*{Exercise 2} \subsection*{a.} Sloppy Joe's solution does not work for a number of reasons. The problem lies in the second recursive call, in which the bottom half of discs is moved. The program utilizes the \emph{Using1} peg, which is sadly containing discs already, all of which are smaller than any from the bottom half. \subsection*{b.} While Fruity Freddie correctly identified the error in Sloppy Joe's algorithm, this correction does not completely address the problem. \emph{Using1} is still occupied, and when the time comes to do recursion, there will be a violation of the rules. v \subsection*{c.} The Scheme code for Sloppy Joe's original algorithm is as follows: \begin{verbatim} (define (faulty-towers n from to using1 using2) (if (= n 1) (begin (display (list 'move 'disc 'from from 'to to)) (newline)) (let ((m (quotient n 2))) (faulty-towers (- n m) from using1 to using2) (faulty-towers m from to using2 using1) ;; ** (faulty-towers (- n m) using1 to from using2)))) \end{verbatim} Fruity Freddie's changes change the commented line to \begin{verbatim} (faulty-towers m from to using1 using2) \end{verbatim} When evaluated at n = 4, the algorithm solved the puzzle correctly. At n = 8, an error was made: \begin{verbatim} (faulty-towers 8 1 2 3 4) ( (move disc from 1 to 3) (move disc from 1 to 2) (move disc from 3 to 2) (move disc from 1 to 4) (move disc from 1 to 3) (move disc from 4 to 3) (move disc from 2 to 1) (move disc from 2 to 3) (move disc from 1 to 3) ;; 4 disks have been moved to peg 3 (move disc from 1 to 2) (move disc from 1 to 4) (move disc from 2 to 4) (move disc from 1 to 3) ;; oops!! \end{verbatim} \ \subsection*{d.} The recurrence equation for Sloppy Joe's algorithm is $T_n = 3T_\frac{n}{2}.$ \subsection*{e.}
Background image of page 1

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

View Full DocumentRight Arrow Icon
Since we know that $T_1 = 1$, we can solve the equation solves as follows: $$ T_n = 3T_\frac{n}{2} = 3^2 T_\frac{n}{2^2} = 3^3 T_\frac{n}{2^3} \ldots = 3^{\log_2 n}T_\frac{n}{n^{\log_2 n}} $$ $$ = 3^{\log_2 n}T_1 = 3^{\log_2 n}{(1)} = 3^{\log_2 n} = n^{\log_2 3} $$ \section*{Exercise 3} \subsection*{a.} The problem with Sloppy and Fruity's system lies in using only 3 pegs for the second recursive call. This is easily done by calling the 3-peg version of Towers of Hanoi. While this not
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 10/01/2011.

Page1 / 6

Problem_Set_03_Solutions - \documentclass[12pt]cfw_article...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online