• Tidak ada hasil yang ditemukan

Trees

N/A
N/A
Protected

Academic year: 2025

Membagikan "Trees"

Copied!
5
0
0

Teks penuh

(1)

Department of Computer Engineering, Chulalongkorn University Discrete Structures





• Trees

– Rooted Trees – m-ary Trees

• Properties of Trees

• Spanning Trees

• Binary Search Trees

• Tree Traversal

Today’s Topics

Department of Computer Engineering, Chulalongkorn University Discrete Structures





Definition:

A tree is a connected graph with no simple circuits

T R





An undirected graph is a tree ↔ there is a unique path between any two of its vertices.

 

 

Definition:

A rooted tree is tree in which one vertex has been designated as the root and every edge is directed away from the root.

a b

c d

e

a b c

d e

f

f

a b

c

d e f

d e f

c

a b d

e f

c

a

b

(2)

Department of Computer Engineering, Chulalongkorn University Discrete Structures

 

 

a

c b

d e f

a

c b

d e f

root

leaf internal

vertex

parent, child, siblings ancestor, descendant

Department of Computer Engineering, Chulalongkorn University Discrete Structures





a

c b

d e f

rooted at a

The subtree with v as its root is the subgraph of the tree consisting of v and its descendants and all edges incident to these descendants.

       

Definition:

An m-ary tree is a rooted tree whose every internal vertex has no more than m children

  

  

Siblings are ordered from left to right

Ordered binary tree (Binary tree) a

Left child of a Right child of a

Left subtree of a Right subtree of a

(3)

Department of Computer Engineering, Chulalongkorn University Discrete Structures

  

  

A tree with n vertices has n-1 edges.

A full m-ary tree with i internal vertices contains n = mi+1 vertices.

A full 4-ary tree has 13 vertices.

How many leaves are there?

Department of Computer Engineering, Chulalongkorn University Discrete Structures

  

  

The level of a vertex in a rooted tree is the length of the unique path form the root to this vertex.

Height = maximum of the levels

level 0 level 1 level 2 height = 2

There are at most m h leaves in an m-ary tree of height h.

 

 

Definition:

Let G be a simple graph. A spanning tree of G is a subgraph of G that is a tree containing every vertex of G.

a

f

e d g

h c b

 

 

A simple graph is connected ↔ It has a spanning tree

(4)

Department of Computer Engineering, Chulalongkorn University Discrete Structures

  

  

• Each vertex is labeled with a key.

• The key of a vertex is:

– larger than the keys of all vertices in its left subtree.

– smaller than the keys of all vertices in its right subtree.

Department of Computer Engineering, Chulalongkorn University Discrete Structures

    

    

   

       

Visit r, then pre-orderly traverse each subtree whose root is a child of r, from left to right.

Pre-order Traversal

T 1 T 2 ………… T n

r r

T 1

T 2

(5)

Department of Computer Engineering, Chulalongkorn University Discrete Structures

     

b c a d e

f g h i j k m n

o p q l

Department of Computer Engineering, Chulalongkorn University Discrete Structures

     

In-orderly traverse the subtree whose root is the

leftmost child of r, visit r, then in-orderly traverse each subtree (excluding the leftmost one) whose root is a child of r, from left to right.

In-order Traversal

r T 1

T 2 T n

      

Post-orderly traverse each subtree whose root is a child of r, from left to right, then visit r.

Post-order Traversal

r T 1 T 2

T n

b c a d e

f g h i j k m n

o p q l

Referensi

Dokumen terkait

Professor, Department of Computer Engineering, Faculty of Engineering Chulalongkorn University, Bangkok, Thailand [email protected] Abstract Quantum computing is the most

Chulalongkorn University, THAILAND Mechanical Engineering Department Basic Definition • Data: Information obtained from experiment • Variable: A basic quantity - Discrete variable:

Atiwong Suchato Department of Computer Engineering, Chulalongkorn University Discrete Mathematics • Example: How many cards must be selected from a standard deck of 52 cards to

2101-611 Department of Civil Engineering Matrix Analysis of Structures Faculty of Engineering Second Semester of 2004 Chulalongkorn University 2 14.2 Course outline: Week 1-7

2101-611 Department of Civil Engineering Matrix Analysis of Structures Faculty of Engineering Second Semester of 2013 Chulalongkorn University 2 14.2 Course outline: Topic

Binary Search-Trees vs B-Trees Seach Trees B-Trees... Secondary Storages Cost measure

Application of Node Based Coincidence Algorithm for Flow Shop Scheduling Problems Ornrumpha Srimongkolkul Department of Computer Engineering, Faculty of Engineering, Chulalongkorn

Department of Computer Engineering Chulalongkorn University • Security & Privacy: the definitions • Security Components • Supporting Concepts • Authentication Security and Privacy