Skip to main content

Ordered Trees, continued

As you've seen, you can use both positive and negative integers and real numbers, and non-numeric strings, as array subscripts. In a little while, you'll learn how to use this capability to your advantage. By the way, the only prohibited subscript is the empty string.

In case you're not familiar with the tree data structure, here are some terms. The entire structure is called a tree. Like a family tree and unlike a real tree, it begins at the top and grows downwards. The root A is at the top. The root, and any other subscripted form of A, are called nodes. Nodes that have no nodes beneath them are called leaves. Nodes that have nodes beneath them are called parents or ancestors. Nodes that have parents are called children or descendants. Children with the same parents are called siblings. All siblings are automatically sorted numerically or alphabetically by their subscripts as they are added to the tree.

This tree structure allows you to create multidimensional arrays of any depth, in order to easily model hierarchies from the real world. Try drawing a picture of a six dimensional array in another way and you'll understand the benefits of this structure!

FeedbackOpens in a new tab