golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.26k stars 17.57k forks source link

tour: Traversal order #11010

Open marslangoog opened 9 years ago

marslangoog commented 9 years ago

Context: /concurrency/8

It should be made clear that Walk function should traverse the tree in-order.

minux commented 9 years ago

I'm not quite sure what to do here.

Any of the three main traversal orders can be used to complete the exercise.

The exercise does seem to suggest in-order traversal by saying "It should be the numbers 1, 2, 3, ..., 10." However, we can also relax this to say "it should be a sequence of the integers 1, 2, 3, ..., 10" so that the traversal order is left unspecified.

Leaving for others.

marslangoog commented 9 years ago

Similar to https://github.com/golang/go/issues/11009, I think the key here is whether the exercise expects the user to

  1. read from Walk's channel and store the result in an array, sort it, then compare; or
  2. iterate on the channels and compare element by element without sorting

If 2, Walk must traverse in-order.

minux commented 9 years ago

Ahh, you're right. The New function generates a BST, so the trees must be traversed in-order so that two trees can be compared item by item from Walk.

I'm not sure what to how to best change the current text. I'm wonder if that's left as an exercise for the reader.