34-Section-Handout

34-Section-Handout - CS106A Handout 34 May 16th 2011 Spring...

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

View Full Document Right Arrow Icon
CS106A Handout 34 Spring 2011 May 16 th , 2011 Section Handout Discussion Problem 1: Heap/Stack Diagrams [courtesy of Eric Roberts] Using the style of heap/stack diagram introduced in Chapter 7, show the state of both the heap and the stack at the point in the computation indicated by the arrow in the following code, where the Rational class is the one defined in Chapter 6. public void run() { Rational r = new Rational(1, 2); r = raiseToPower(r, 3); println("r ^ 3 = " + r); } private Rational raiseToPower(Rational x, int n) Rational result = new Rational(1); for (int i = 0; i < n; i++) { result = result.multiply(x); } return result; } ! Diagram at this point Indicate which values in the heap are garbage at this point in the calculation. Discussion Problem 2: Maximizing Game Score [challenging, but worth it] Consider the one-player puzzle where you’re presented with a 2 by n board of small positive integers like the following (a smaller version of the MaximumSelection game in Handout 33):
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/28/2011 for the course CS 106A taught by Professor Sahami,m during the Spring '08 term at Stanford.

Page1 / 2

34-Section-Handout - CS106A Handout 34 May 16th 2011 Spring...

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

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