Algorithm for finding circular references in a spreadsheet

后端 未结 3 542
天命终不由人
天命终不由人 2021-02-06 13:13

I have a spreadsheet application with formulas. I am looking for the best algorithm for detecting circular references among the formulas. The current approach I have is slow and

相关标签:
3条回答
  • 2021-02-06 13:50

    Perhaps you have motives for checking on your own, but Excel already checks for circular references automatically. You can use the Worksheets.CircularReference property in VBA to access this information.

    0 讨论(0)
  • 2021-02-06 14:02

    Represent the dependencies between cells as a directed graph, and use Tarjan's strongly connected components algorithm (each strongly connected component of size 2 or larger contains cycles).

    0 讨论(0)
  • 2021-02-06 14:12

    You need to do a topological sorting of the cells anyway in order to be able to rapidly calculate the values of cells when something is changed. The topological sorting procedure also detect cycles as a byproduct.

    See http://en.wikipedia.org/wiki/Topological_sorting

    0 讨论(0)
提交回复
热议问题