reneargento/algorithms-sedgewick-wayne

The solution of exercise 4.3.20 seems wrong.

YRFT opened this issue · 2 comments

YRFT commented

I think the assertion is false.

For example:

  (5)
0 ---> 1

|
| (2)
|
v

2

|
| (4)
|
v

3

In the above example, 0-1 is chosen first, then 2-3 is chosen. At this time, 0, 2, 3 are in the same tree, but 1 is not. The distance between 0 and 3 is 6 and the distance between 0 and 1 is 5. So the assertion is false.

I think when the exercise says "closer to some vertex", it means closer to "any" vertex in the subtree, and not closer to "all" vertices.
So in this case we have the distance between 0 and 2 as 2, and the distance between 0 and 1 as 5. So vertex 0 is closer to some vertex (2) in its subtree than to any vertex that is not in it.

YRFT commented

I think you are right. Maybe the description of the exercise should have been more clear (e.g. use the word adjacent).