You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a combination of 5 commits.
This is the 1st commit message:
Add Tree Traversal in Emojicode
This is the commit message #2:
Remove unnecessary 🤜🤛.
This was suggested by thbwd:
"No need to wrap 🤜children_count🤛 into 🤜🤛actually."
(https://github.com/algorithm-archivists/algorithm-archive/pull/
471#discussion_r223291032)
This is the commit message #3:
Extract shared logic into a method.
This was suggested by thbwd:
"This is shared logic. I’d recommend you extract it into a method."
(https://github.com/algorithm-archivists/algorithm-archive/pull/
471#discussion_r223291140)
This is the commit message #4:
Use documentation comments.
This was suggested by thbwd:
"Shouldn’t these be documentation comments? https://www.emojicode.org/
docs/reference/documentation.html"
(https://github.com/algorithm-archivists/algorithm-archive/pull/
471#discussion_r223291281)
This is the commit message #5:
Add error as a potential return value for DFS RI Binary
To be able to return an error and to apply suggestion by thbwd
(https://github.com/algorithm-archivists/algorithm-archive/pull/
471#discussion_r223597592) the following changes were made:
- Declare an enum to hold the error value.
- Rewrite the Depth-First Search Recursive Inorder Binary method to
return an optional holding the enum and adjust the returns according
to that.
- Call the rewritten method and check, if the returned optional holds
error. If it does: Print out the error message defined in the enum.
Signed-off-by: Julian Schacher <[email protected]>
At least to me, this makes a lot of sense. We fight recursion with recursion! First, we first output the node we are on and then we call `DFS_recursive(...)` on each of its children nodes. This method of tree traversal does what its name implies: it goes to the depths of the tree first before going through the rest of the branches. In this case, the ordering looks like:
@@ -114,6 +118,8 @@ Now, in this case the first element searched through is still the root of the tr
All this said, there are a few details about DFS that might not be idea, depending on the situation. For example, if we use DFS on an incredibly long tree, we will spend a lot of time going further and further down a single branch without searching the rest of the data structure. In addition, it is not the natural way humans would order a tree if asked to number all the nodes from top to bottom. I would argue a more natural traversal order would look something like this:
@@ -243,6 +253,8 @@ And this is exactly what Breadth-First Search (BFS) does! On top of that, it can
0 commit comments