4
Tree A set of linked nodes that form a hierarchy There is a root node at the top Each node may or may not have children In some types of trees a node may have any number of children and in other types the number of children are controlled The nodes at the bottom most level are called leaf nodes The nodes between the root and the leaf nodes are called internal nodes •A subtree is a portion of a tree that can be viewed as a complete tree in itself.

5 data structures-tree

Embed Size (px)

Citation preview

Page 1: 5 data structures-tree

Tree

• A set of linked nodes that form a hierarchy• There is a root node at the top• Each node may or may not have children• In some types of trees a node may have any number of

children and in other types the number of children are controlled

• The nodes at the bottom most level are called leaf nodes• The nodes between the root and the leaf nodes are called

internal nodes• A subtree is a portion of a tree that can be viewed as a

complete tree in itself.

Page 2: 5 data structures-tree

Tree

• Traversal– Breadth first• Visit all the nodes at a given level

before going deeper

– Depth first• Visit nodes as deep as possible

first

Page 3: 5 data structures-tree

Trees

• Binary tree– Each node has at most two

children

Page 4: 5 data structures-tree

class

title

instructor

semester

assignment*

title

instructions

grading

student*

name

first

middle?

lastfeedback?

grade?