Homework 2 note

PGSS Computer Science Core

This is for those attempting level 3 of problem 2 of the homework.

Level 3

If you attempt to handle boxes referring to boxes that may refer to other boxes, and them to other boxes yet deeper, your algorithm may be one has can behave quite poorly.

Consider the following set of formulas.

  box  formula
  #0:  #1 +  #1
  #1:  #2 +  #2
  #2:  #3 +  #3
  #3:  #4 +  #4
  #4:  #5 +  #5
  #5:  #6 +  #6
  #6:  #7 +  #7
  #7:  #8 +  #8
  #8:  #9 +  #9
  #9: #10 + #10
 #10: #11 + #11
 #11: #12 + #12
 #12: #13 + #13
 #13: #14 + #14
 #14: #15 + #15
 #15:     1
A bad algorithm may take nearly a second to compute the boxes' values! (Make it 20 boxes, and the algorithm would take about 13 seconds. Make it 32, and you're talking about half a day.) More precisely, a bad algorithm will add 2^16=32,768 numbers together. Think about how many additions your algorithm will take for this example.

You'll have done well even if you use this bad algorithm. But the best answer involves an algorithm that doesn't behave so badly on any input.

Level 4

If you detect a circular reference, the proper thing to do is to make all the cells involved be undefined.