Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do spreadsheets update cells correctly / know what to update?

Tags:

spreadsheet

Spreadsheets are so beautiful! Cells can be linked on top of each other and if any formula / value / whatever changes in one of the cells everything updates correctly!

Does anyone know the general concept on how spreadsheets do this? What I'm talking about is if A1 = 1, A2 = 2 and A3 = A1+A2. Then I change A1 or A2 and A3 knows to update and does it correctly. Of course it can't update it wrong in this example but in more complicated examples it has to update "lower" cells first before updating things built on top of it.

When programming myself I am having such a hassle of updating everything correctly after the underlying data changes. Sometimes not everything has to be updated so I don't want to update everything. It's just a mess.

I hope my tags are correct, and that discussions like these are allowed. Thanks!

like image 474
user1594138 Avatar asked Oct 18 '12 18:10

user1594138


People also ask

How do I get Excel to automatically update cells?

Automatically refresh data at regular intervals Click a cell in the external data range. On the Data tab, in the Connections group, click Refresh All, and then click Connection Properties. Click the Usage tab. Select the Refresh every check box, and then enter the number of minutes between each refresh operation.

Why are my Excel cells not updating?

When Excel formulas are not updating automatically, most likely it's because the Calculation setting has been changed to Manual instead of Automatic. To fix this, just set the Calculation option to Automatic again.

How do you update values in Excel?

Go to Data > Queries & Connections > Edit Links. In the Source list, click the linked object that you want to update. You can select individual workbooks with Ctrl+click, or all of them with Ctrl+A. Click Update Values.


1 Answers

I don't know how spreadsheets do this in practice. But my idea here is inspired from topological sorting on graphs. Consider formula A3 = A1+A2. Cells will become nodes for graph. Formulas will govern the edge. Edge represent dependency. e.g. A3 depends on A1. Therefore we have two edges from A3 to A1 and A3 to A2. Now a topological sort of above graph will give you exact evaluation order. ie A1 A2 and A3.

Also note this graph needs to be Directed Acyclic Graph (DAG) if one uses this algorithm. ie it doesn't contain any cycles. As far as I know excel does detect circular dependency in it's formulas.

The underlying algorithm of topo-sort uses DFS (depth first search) which can detect cycles too. Hence one can report such cycles.

like image 62
Ankush Avatar answered Oct 14 '22 06:10

Ankush