Problem_Set_03_Solutions

Problem_Set_03_Solutions - Problem Set 3 Solutions Jerey M....

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

Problem Set 3 Solutions Jeﬀrey M. Radcliﬀe November 16, 2000 Exercise 2 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 Using1 peg, which is sadly containing discs already, all of which are smaller than any from the bottom half. b. While Fruity Freddie correctly identiﬁed the error in Sloppy Joe’s algorithm, this correction does not completely address the problem. Using1 is still occupied, and when the time comes to do recursion, there will be a violation of the rules. c. The Scheme code for Sloppy Joe’s original algorithm is as follows: (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)))) Fruity Freddie’s changes change the commented line to (faulty-towers m from to using1 using2) When evaluated at n = 4, the algorithm solved the puzzle correctly. At n = 8, an error was made: 1

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

View Full Document
(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!! d. The recurrence equation for Sloppy Joe’s algorithm is T n = 3 T n 2 . e. Since we know that T 1 = 1, we can solve the equation solves as follows: T n = 3 T n 2 = 3 2 T n 2 2 = 3 3 T n 2 3 . . . = 3 log 2 n T n n log 2 n = 3 log 2 n T 1 = 3 log 2 n (1) = 3 log 2 n = n log 2 3 Exercise 3 a.
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 / 8

Problem_Set_03_Solutions - Problem Set 3 Solutions Jerey M....

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

View Full Document
Ask a homework question - tutors are online