Skip to content

Commit b1a49eb

Browse files
authored
Merge pull request kodecocodes#305 from joligario/BST
Fix for kodecocodes#246: Invalid tree in MinimumMaximum.png and update README.ma…
2 parents f27c4aa + 653452a commit b1a49eb

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed
-238 Bytes
Loading

Binary Search Tree/README.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ To see how this works, take the following tree:
412412

413413
![Example](Images/MinimumMaximum.png)
414414

415-
For example, if we look at node `10`, its leftmost descendent is `6`. We get there by following all the `left` pointers until there are no more left children to look at. The leftmost descendent of the root node `7` is `1`. Therefore, `1` is the minimum value in the entire tree.
415+
For example, if we look at node `10`, its leftmost descendent is `7`. We get there by following all the `left` pointers until there are no more left children to look at. The leftmost descendent of the root node `6` is `1`. Therefore, `1` is the minimum value in the entire tree.
416416

417417
We won't need it for deleting, but for completeness' sake, here is the opposite of `minimum()`:
418418

@@ -426,7 +426,7 @@ We won't need it for deleting, but for completeness' sake, here is the opposite
426426
}
427427
```
428428

429-
It returns the rightmost descendent of the node. We find it by following `right` pointers until we get to the end. In the above example, the rightmost descendent of node `2` is `5`. The maximum value in the entire tree is `11`, because that is the rightmost descendent of the root node `7`.
429+
It returns the rightmost descendent of the node. We find it by following `right` pointers until we get to the end. In the above example, the rightmost descendent of node `2` is `5`. The maximum value in the entire tree is `11`, because that is the rightmost descendent of the root node `6`.
430430

431431
Finally, we can write the code that removes a node from the tree:
432432

@@ -500,11 +500,11 @@ if let node2 = tree.search(2) {
500500

501501
First you find the node that you want to remove with `search()` and then you call `remove()` on that object. Before the removal, the tree printed like this:
502502

503-
((1) <- 2 -> (5)) <- 7 -> ((9) <- 10)
503+
((1) <- 2 -> (5)) <- 6 -> ((9) <- 10)
504504

505505
But after `remove()` you get:
506506

507-
((1) <- 5) <- 7 -> ((9) <- 10)
507+
((1) <- 5) <- 6 -> ((9) <- 10)
508508

509509
As you can see, node `5` has taken the place of `2`.
510510

0 commit comments

Comments
 (0)