Bifalgorithm post · Brisk · Chapter 1

How does recursion support tree traversal?

How does recursion support tree traversal? (Brisk · Chapter 1) — "Finally, it’s worth mentioning that all of these traversal methods make elegant use of recurs…

Ideas in this flowchart

  • La récursion dans les parcours d’arbres
  • La récursion consiste à diviser un grand problème en sous-problèmes similaires, mais plus petits.
  • Chaque sous-problème est traité de la même manière que le problème initial.
  • Une règle d’arrêt est nécessaire pour mettre fin à la division et effectuer réellement une opération.
  • Dans un parcours d’arbre, traiter un enfant comme un sous-arbre relance le parcours sur un arbre plus petit.
  • En préordre, le parcours visite la racine, parcourt récursivement le sous-arbre gauche, puis le sous-arbre droit.
  • La récursion est une méthode courante et utile pour résoudre certains problèmes complexes.
  • Les arbres offrent de nombreuses occasions d’utiliser la récursion.
Feed/

How does recursion support tree traversal?

Channel

Brisk

1 page

"Finally, it’s worth mentioning that all of these traversal methods make elegant use of recursion. Recursion is a way of taking a large problem and breaking it up into similar, but smaller, sub-problems. Then, each of those subproblems can be attacked in the same way as you attacked the larger problem: by breaking them up into subproblems. All you need is a rule for eventually stopping the “breaking up” process by actually doing something. Every time one of these traversal processes treats a left or right child as a subtree, they are “recursing” by re-initiating the whole traversal process on a smaller tree. Pre-order traversal, for instance, after visiting the root, says, “okay, let’s pretend we started this whole traversal thing with the smaller tree rooted at my left child. Once that’s finished, wake me up so I can similarly start it with my right child.” Recursion is a very common and useful way to solve certain complex problems, and trees are rife with opportunities."

Flowchart preview
Series cover
👍
0
0 comments0 shares

Sign in to view and post comments.