Skip to content

Commit c0a07b2

Browse files
authored
Shortening text
1 parent 69d5118 commit c0a07b2

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

contents/tree_traversal/tree_traversal.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ This has not been implemented in your chosen language, so here is the Julia code
3333
{% sample lang="crystal" %}
3434
[import:1-5, lang:"crystal"](code/crystal/tree-traversal.cr)
3535
{% sample lang="st" %}
36-
[import:1-20, lang:"st"](code/smalltalk/tree_traversal.st)
36+
[import:1-20, lang:"smalltalk"](code/smalltalk/tree_traversal.st)
3737
{% endmethod %}
3838

3939
Because of this, the most straightforward way to traverse the tree might be recursive. This naturally leads us to the Depth-First Search (DFS) method:
@@ -69,7 +69,7 @@ Because of this, the most straightforward way to traverse the tree might be recu
6969
{% sample lang="crystal" %}
7070
[import:7-10, lang:"crystal"](code/crystal/tree-traversal.cr)
7171
{% sample lang="st" %}
72-
[import:22-28, lang:"st"](code/smalltalk/tree_traversal.st)
72+
[import:22-27, lang:"smalltalk"](code/smalltalk/tree_traversal.st)
7373
{% endmethod %}
7474

7575
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:
@@ -113,7 +113,7 @@ Now, in this case the first element searched through is still the root of the tr
113113
{% sample lang="crystal" %}
114114
[import:12-15, lang:"crystal"](code/crystal/tree-traversal.cr)
115115
{% sample lang="st" %}
116-
[import:30-35, lang:"st"](code/smalltalk/tree_traversal.st)
116+
[import:29-34, lang:"smalltalk"](code/smalltalk/tree_traversal.st)
117117
{% endmethod %}
118118

119119
<p>
@@ -152,7 +152,7 @@ In this case, the first node visited is at the bottom of the tree and moves up t
152152
{% sample lang="crystal" %}
153153
[import:17-31, lang:"crystal"](code/crystal/tree-traversal.cr)
154154
{% sample lang="st" %}
155-
[import:37-59, lang:"st"](code/smalltalk/tree_traversal.st)
155+
[import:36-49, lang:"smalltalk"](code/smalltalk/tree_traversal.st)
156156
{% endmethod %}
157157

158158
<p>
@@ -201,7 +201,7 @@ In code, it looks like this:
201201
{% sample lang="crystal" %}
202202
[import:33-41, lang:"crystal"](code/crystal/tree-traversal.cr)
203203
{% sample lang="st" %}
204-
[import:61-73, lang:"st"](code/smalltalk/tree_traversal.st)
204+
[import:47-58, lang:"smalltalk"](code/smalltalk/tree_traversal.st)
205205
{% endmethod %}
206206

207207
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:
@@ -242,7 +242,7 @@ And this is exactly what Breadth-First Search (BFS) does! On top of that, it can
242242
{% sample lang="crystal" %}
243243
[import:43-51, lang:"crystal"](code/crystal/tree-traversal.cr)
244244
{% sample lang="st" %}
245-
[import:75-87, lang:"st"](code/smalltalk/tree_traversal.st)
245+
[import:60-71, lang:"smalltalk"](code/smalltalk/tree_traversal.st)
246246
{% endmethod %}
247247

248248
## Example Code
@@ -285,7 +285,7 @@ The code snippets were taken from this [Scratch project](https://scratch.mit.edu
285285
{% sample lang="crystal" %}
286286
[import, lang:"crystal"](code/crystal/tree-traversal.cr)
287287
{% sample lang="st" %}
288-
[import, lang:"st"](code/smalltalk/tree_traversal.st)
288+
[import, lang:"smalltalk"](code/smalltalk/tree_traversal.st)
289289
{% endmethod %}
290290

291291

0 commit comments

Comments
 (0)