Why a DOM tree or pre-order, depth crossing?

Why is the DOM tree oder preorder , depth-first traversal ?

What are the advantages of this design over other workarounds such as BFT?

I just looked at the DOM standard and found a definition of the previous and the following:

Object A precedes object B if A and B are in the same tree and A goes up to B in tree order.

Object A follows object B if A and B are in the same tree and A comes after B in tree order.

Like most programming paradigms, the web platform has finite hierarchical tree structures, simply named trees. Order trees pre-order, depth crossing.

+6
source share
2 answers

Depth traversal is usually the easiest traversal style since you can do it recursively or with an explicit stack; in the first case, a queue is required, which in a sense is a more complex data structure. But I think there is a simpler answer than tradition or simplicity: a depth search in the (X) HTML tree causes the text nodes to intersect in the order of presentation.

Consider this relatively simple HTML subtree.

Or in raw form:

 <p>Consider this <emph>relatively</emph> simple <a href="...">HTML</a> subtree</p> 

Like a tree (excluding spaces and attributes):

  <P> | +-----------+----+----+-----+------+ ______|______ __|___ ___|__ _|_ ___|___ Consider this <EMPH> simple <A> subtree | | ____|_____ __|__ relatively HTML 

Depth Trace:

 <P>, Consider this, <EMPH>, relatively, simple, <A>, HTML, subtree 

First step:

 <P>, Consider this, <EMPH>, simple, <A>, subtree, relatively, HTML 
+11
source

For depth searches, memory is required in order of tree height, but width searches require memory in order of power for tree vertices. In other words, a breadth-first search is a burst of memory compared to a depth search at the beginning.

+2
source

All Articles