'I don't understand this tree structure
type Item = string
type tree = LEAF of Item
| NODE of tree list
I'm having trouble understanding this. For example:
Node [Node [Item "a", Item "h", Item "b"], Item "k", Node [Item "c", Item "h", Item "d"]]
Could you draw a graph of this? It would be a great help.
It's not that I don't know about trees.
Solution 1:[1]
The tree that is described by that syntax, corresponds to this visualisation:
Node
/ | \
Node k Node
/ | \ / | \
a h b c h d
The structure is such that only leaves (i.e. Item) have data (of type string). Internal nodes (Node) do not have data.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | trincot |
