UMBC CS 201, Fall 98
UMBC CMSC 201 & 201H Fall '98 CSEE | 201 | 201 F'98 | lectures | news | help

Trees

A tree is a two-dimensional data structure, where each tree node contains two or more links. An example of this might be a family tree.

A family tree node would contain an individual and their spouse and links to each of their children. So the definition of a node might look like this:

typedef struct tag* nodePtr; typedef struct tag { char person[25]; char spouse[25]; nodePtr child1; nodePtr child2; nodePtr child3; nodePtr child4; nodePtr child5; nodePtr child6; nodePtr child7; nodePtr child8; nodePtr child9; nodePtr child10; nodePtr child11; nodePtr child12; }node; (Drawing to be supplied in class).

You can write trees like this to suit specific items you're trying to model. They would have more, or less, links in them and more, or less data memebers in them depending upon what you're modeling.

Nomenclature

  • Trees are drawn upside-down from the way trees grow in nature. The nomenclature for trees come from both analogies with trees and analogies with families.
  • The node at the top of the drawing is known as the root. If a tree has only one node in it, there will typically be a pointer to that node called root

    The nodes at the bottom of the tree that have both pointers NULL, are known as leaves.

    If a node has a link to another node, the one higer in the tree is known as the parent. The one pointed to by the link is known as the child. Nodes that are pointed to by the same parent are known as siblings.



    CSEE | 201 | 201 F'98 | lectures | news | help

    Wednesday, 09-Dec-1998 09:04:11 EST