{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

22S-Section-Solution

22S-Section-Solution - CS106X Autumn 2010 Handout 22S...

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

View Full Document Right Arrow Icon
CS106X Handout 22S Autumn 2010 October 18 th , 2010 Section Solution Solution 1: Farmers Market Memory Trace The drawing above depicts the state of memory—stack on the left, heap on the right—at the moment the problem asks for a snapshot of memory (right before the call to FarmersMarket ). All dynamically allocated memory is drawn from the heap, and all local variables (in this case, salad and currant ) are allocated on the stack. The next page includes an elaborate drawing detailing the state of memory just after a base case is detected but just before the recursive call returns. [Note that no memory is orphaned at all, since everything is accessible from some active local variable.] apple banana date cherry[0..3] salad 7 apple banana date cherry[0..3] currant false
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
2 apple banana date cherry[0..3] salad 17 apple banana date cherry[0..3] currant false stack frame for main stack frame for first call to FarmersMarket apple banana date cherry[0..3] 14 false grape lemon lime 20 true stack frame for second call to
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ 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