Published online by Cambridge University Press: 05 September 2016
Trees are one of the most pervasive data structures in Computer Science. They are also one of the most striking success stories of compact data structures: We can represent a tree of n nodes using basically 2n bits instead of pointers (or machine words). Moreover, the compact representations have much richer functionality than most classical representations.
Let us distinguish two types of trees: ordinal and cardinal. Ordinal trees allow for an arbitrary number of children per node but distinguish only their order. For example, the parse tree of a program or the structure of an XML document are ordinal trees. Cardinal trees, instead, have a fixed set [1, σ] of types of children, and each node might have one or no child of each type. The most common example of a cardinal tree is the binary tree, where each node may have a left and may have a right child. Having only a left child is not the same as having only a right child; an ordinal tree cannot make this distinction. Other examples are digital trees or tries (see Section 8.5.3), which have an alphabet [1, σ] and there can be at most one child for each alphabet symbol.
In addition, trees can be labeled, meaning that edges have an associated label from an alphabet [1, σ]. For example, an XML tree can be regarded as a labeled tree if we associate the tag names with their corresponding edges. Unlike a trie, a labeled tree node may have several children with the same label, and they can appear in any order. Thus, a cardinal tree can be regarded as a special type of labeled tree. An alternative model labels the nodes, not the edges. The two models are not very different, as we can assign the label of the node to the edge that leads to it (making an exception for the root). Thus, we will consider only labels at the edges.
We will mainly consider ordinal trees in this chapter and show how the solutions are extended to cardinal and labeled trees. In Chapter 2 we showed that bits are necessary to represent the topology of every possible ordinal tree of n nodes.
To save this book to your Kindle, first ensure no-reply@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
Find out more about the Kindle Personal Document Service.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.