Talk:Tree from nesting levels: Difference between revisions
m
→Labelled an example of Node as a tuple of a possible integer with a list of Nodes
(/* a '''round-trip''' transformation, to ensure that no information is lost) |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 70:
[[User:Hout|Hout]] ([[User talk:Hout|talk]]) 12:23, 4 February 2021 (UTC)
We can obtain a self-consistent representation of these forests as lists of tuples, in which the first value is a kind of sum type – in Python terms (
A consistent recursive data structure – lets give it a name like '''Node'''.
In Python terms, '''Node''' here is a tuple of a possible integer with a list of '''Nodes''':
▲We can obtain a self-consistent representation of these forests as lists of tuples, in which the first value is a kind of sum type (Int or None), and the second value is itself a (possibly empty) forest:
<pre>Node (None|Int) :: ((None|Int), [Node])</pre>
<lang python>(None, [])
[[User:Hout|Hout]] ([[User talk:Hout|talk]]) 14:00, 4 February 2021 (UTC)
: Sorry, but what's wrong with a tree with multiple nodes at level 1? I mean, even a binary tree has got 2''!'' [oh, one node, two children.. hmm]<br>
:: Not quite sure what ''wrong'' means to you exactly here. Siblings inescapably have a parent :-) [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 17:32, 7 February 2021 (UTC)
: What is the purpose or benefit of littering up the nested structures (a better name?) with all those None?<br>
:: That's just a representation of the implicit structure. Each of these examples implies the existence of one or more parent nodes which have no explicit (integer) node value.
::* Two or more level 1 siblings implicitly share a level 0 parent:
::* Where we are given a 1 and a 3 but no 2, the 3 inescapably has a level 2 parent which '''(a)''' lacks the integer 2 as a node value and '''(b)''' is a child of a level 1 node. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 17:32, 7 February 2021 (UTC)
: What about programming languages where not everything ''has'' to be a tuple (whatever ''that'' its)?<br>
:: No problem at all :-) (Paddy3118 will explain to you what a tuple is). [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 17:32, 7 February 2021 (UTC)
: It seems to me you're trying to forcefully impose functional programming rules or something onto this task. --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 17:24, 4 February 2021 (UTC)
:: Does it ? Just exploring what the input notation really represents.
:: That's necessary, because the output shown is rejected as inconsistent by compilers of strictly-typed languages, so we need something else in those cases, and that means we need to know what we are really representing. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 17:32, 7 February 2021 (UTC)
::Aye, <strike>"You have no control of level 0, and integer zero being the unnumbered root level"</strike>. (For an alternate view, that now I've wrote it, I don't like). The task description is enough to write examples, for I think. --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 18:23, 4 February 2021 (UTC)
Line 127 ⟶ 123:
::But the key issue introduced by your examples here, which was not, I think, a component of that Stack Overflow discussion, was that of implicit intermediate levels, for which no integer is supplied in the input list.
::I believe the Stack Overflow examples are all fully saturated, with no missing nesting levels ? [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 06:36, 7 February 2021 (UTC)
::If [1, 2, 4] '''represents''' object nesting levels, as the task description tell us, then there is an implicit level 3. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 06:40, 7 February 2021 (UTC)
:: Perhaps the task could best be tightened up and filled out by also requiring, (as was already suggested elsewhere on this page, I think) a '''round-trip''' transformation, to ensure that no information is lost in the translation from list to tree (and back). [[User:Hout|Hout]] ([[User talk:Hout|talk]])
|