Difference between recursive function and stack usage in terms of memory usage

I want to know the difference between a recursive function and use the stack in terms of memory usage. Say for large DFS , which will be more efficient.

+3
source share
3 answers

The explicit data structure of the stack should theoretically use a little less memory, since a recursive function will always have additional overhead for each call, for the return address, etc.

+5
source

, . G = (V, E), V - , E - , (DFS) :

  • , visit .
  • .

, , , O (d), d - DFS ( .

, . , call-stack , . , , . , . , , , . .

+1

, , . , , , . , - , , - .

This view is supported by “Garbage collection is fast, but the stack is faster,” James S. Miller and Guillermo Rozaz: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.2789

+1
source

Source: https://habr.com/ru/post/1795270/


All Articles