Metainformationen zur Seite
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung | |||
start:visualstudio2017:programmieren:dotnetgrundlagen:tipps_tricks:searchingtreeofobjectswithlinq [2022/06/22 10:15] wikiadmin [Tree to IEnumerable<T> Extension methods] |
start:visualstudio2017:programmieren:dotnetgrundlagen:tipps_tricks:searchingtreeofobjectswithlinq [2022/06/22 10:31] (aktuell) wikiadmin [Tree to IEnumerable<T> Extension methods] |
||
---|---|---|---|
Zeile 148: | Zeile 148: | ||
As a final note, you may wonder, **why bother with depth-first vs. breadth first?** After all, in the end we do examine every node! There is however one particular case where the choice of algorithm can be very important: **You are looking for one match or a particular number of matches**. Since we are using yield, we can terminate the traversal at any time. Using the **FirstOrDefault()** extension on our Linq expression, the traversal would stop as soon as one match is found. And if have any knowledge where that node might be in the tree, the choice of search algorithm can be a significant performance factor. | As a final note, you may wonder, **why bother with depth-first vs. breadth first?** After all, in the end we do examine every node! There is however one particular case where the choice of algorithm can be very important: **You are looking for one match or a particular number of matches**. Since we are using yield, we can terminate the traversal at any time. Using the **FirstOrDefault()** extension on our Linq expression, the traversal would stop as soon as one match is found. And if have any knowledge where that node might be in the tree, the choice of search algorithm can be a significant performance factor. | ||
+ | [[http:// | ||