day18 - Data Structures: Binary Trees A binary tree is a...

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

View Full Document Right Arrow Icon
A binary tree is a data structure that is made up of nodes and pointers, much in the same way that a linked list is structures. The difference between them lies in how they are organized. A linked list represents a linear or predecessor/successor relationship between the nodes of the list. A tree represents a hierarchical or ancestral relationship between the nodes. In general, a node in a tree can have several successors (called children). In a binary tree this number is limited to a maximum of 2. The top node in the tree is called the root. Every node in a binary tree has 0, 1, or 2 children. There are actually two different approaches to defining a tree structure, one is a recursive definition and the other is a non-recursive definition. The non-recursive definition basically considers a tree as a special case of a more general data structure, the graph . In this definition the tree is viewed to consist of a set of nodes which are connected in pairs by directed edges such that the resulting graph is connected (every node is connected to a least one other node – no node exists in isolation) and cycle-free. This general definition does not specify that the tree have a root and thus a rooted-tree is a further special case of the general tree such every one of the node except the one designated as the root is connected to at least one other node. In certain situations the non-recursive definition of a tree has certain advantages, however, for our purposes we will focus on the recursive definition of a tree which is: Binary Trees - 1 Data Structures: Binary Trees Definition: A tree t is a finite, nonempty set of nodes, t = {r} U T 1 U T 2 U U T n with the following properties: 1. A designated node of the set, r , is called the root of the tree; and 2. The remaining nodes are partitioned into n 0 subsets T 1 , T 2 , …, T n each of which is a tree (called the subtrees of t ). For convenience, the notation t = {r, T 1 , T 2 , …, T n } is commonly used to denote the tree t .
Background image of page 1

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

View Full DocumentRight Arrow Icon
A complete set of terminology has evolved for dealing with trees and we’ll look at some of this terminology so that we too can discuss tree structures with some degree of sophistication. As you will see the terminology of trees is derived from mathematical, genealogical, and botanical disciplines. Rooted Tree: (from the non-recursive definition) A tree in which one node is specified to be the root , (call it node c ). Every node (other than c ), call it b is connected by exactly one edge to exactly one other node, call it p . Given this situation, p is b ’s parent. Further, b is one of p ’s children. Degree of a node: The number of subtrees associated with a particular node is the degree of that node. For example, using our definition of a tree the node designated as the root node r has a degree of n .
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 document was uploaded on 06/12/2011.

Page1 / 19

day18 - Data Structures: Binary Trees A binary tree is a...

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