introduction to trees

9
Introduction to Trees Lecture 16 1107186 – Estrutura de Dados – Turma 02 Prof. Christian Azambuja Pagot CI / UFPB Universidade Federal da Paraíba Centro de Informática

Upload: rajendranjrf

Post on 17-Aug-2015

24 views

Category:

Education


0 download

TRANSCRIPT

Introduction to TreesLecture 16

1107186 – Estrutura de Dados – Turma 02

Prof. Christian Azambuja PagotCI / UFPB

Universidade Federal da ParaíbaCentro de Informática

What is a Tree?

In graph theory, a tree is defined as a●

connected

Example:

acyclic graph.●

Node4

However, one suchgraph may generate

different treedata structures!

2

Edge1 5

3 6

2Universidade Federal da ParaíbaCentro de Informática

What is a Tree?

In graph theory, a tree is defined as aRoot node

connected

Example:

acyclic graph.●

4

4

12

1 5 2 5

4

3 6 3

3Universidade Federal da ParaíbaCentro de Informática

What is a Tree?

In graph theory, a tree is defined as a●

connected

Example:

acyclic graph.Root node●

14

2

25 641 5

33 6

4Universidade Federal da ParaíbaCentro de Informática

Definitions

Path Length●

Number of edges on a path.–1

Depth of a Node●

Equal to the path length to the root.–

83 72Height of a Node●

Equal to the path length from thenode to its deepest descendant.

Height of a Tree

4 9●

Equal to the height of the root.–

5 6

5Universidade Federal da ParaíbaCentro de Informática

Definitions

Child Node●

Each node canchild nodes.

Parent Node

have n 1–

● 83 72

It is unique fornode.

The root does parent node.

each–

4 9

not have–

5 6

6Universidade Federal da ParaíbaCentro de Informática

Definitions

Leaf Node●

Has no child node.– 1

Siblings●

Nodes with the same parent.– 83 72

Ancestors●

All nodes on the path to the root.–4 9

Descendants of a node n●

All nodes that share n as anancestor.

–5 6

7Universidade Federal da ParaíbaCentro de Informática

Definitions

Subtree●

Tree formed by a node 1–

and all its descendants.

83 72

4 9

5 6

8Universidade Federal da ParaíbaCentro de Informática

Definitions

Tree Arity● 11

n-ary.

Binary.

2 3–83 72

44 9

5 65 6

n-ary tree binary tree

9Universidade Federal da ParaíbaCentro de Informática