Lecture 11 -Trees - Trees (Computer Science Notes) Why...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Trees (Computer Science Notes) Why Trees? Trees are the central structure for storing and organizing data in computer science Computer programs that try to understand natural language use parse trees to represent the structure of sentences. For example, here are two possible structures for the phrase “green eggs and ham.” In the first, but not the second, the ham would be green Here’s what a medical decision tree might look like. Decision trees are also used for engineering classification problems, such as transcribing speech waveforms into the basic sounds of a natural language Defining Trees Formally, a tree is a undirected graph with a special node called the root , in which every node is connected to the root by exactly one path. When a pair of nodes are neighbors in the graph, the node nearest the root is called the parent and the other node is its child . By convention, trees are drawn with the root at the top. Two children of the same parent are known as siblings . To keep things simple, we will assume that the set of nodes in a tree is finite. We will also assume that each set of siblings is ordered from left to right, because this is common in computer science applications A leaf node is a node that has no children. A node that does have children is known as an internal node . The root is an internal node, except in the special case of a tree that consists of just one node (and no edges) The nodes of a tree can be organized into levels , based on how many edges away from the root they are. The root is defined to be level 0. Its children are level 1. Their children are level 2, and so forth. The height of a tree is the maximum level of any of its nodes or, equivalently, the maximum level of any of its leaves or, equivalently, the maximum length of a path from the root to a leaf If you can get from x to g by following one or more parent links, then g is an ancestor of x and x is a descendent of g. We will treat x as an ancestor/descendent of itself. The ancestors/descendents of x other than x itself are its proper ancestors/descendents. If you pick some random node a in a tree T, the subtree rooted at A consists of a (its root), all of a’s descendents, and all the edges linking these nodes.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
M-ary Trees Many applications restrict how many children each node can have. A binary tree (very common!) allows each node to have at most two children. An mary tree allows each node to have up to m children. Important special cases involve trees that are nicely filled out in some sense. In a full m- ary tree, each node has either zero or m children. Never an intermediate number. So in a full 3-ary tree, nodes can have zero or three children, but not one child or two children. In a
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/16/2011 for the course CS 173 taught by Professor Erickson during the Spring '08 term at University of Illinois, Urbana Champaign.

Page1 / 7

Lecture 11 -Trees - Trees (Computer Science Notes) Why...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online