<<

A

• Definition – A is a connected undirected graph with no Tree simple circuit

Section 10.1

prepared by Nattee Niparnan

Example More Example

• Family Tree

prepared by Nattee Niparnan prepared by Nattee Niparnan A Forest Theorem 1

• An unconnected graph such that each • An undirected graph is a tree if and only if connectdted componen tit is a tree thihere is a un ique s ilimple pat hbh between any two of its vertices

prepared by Nattee Niparnan prepared by Nattee Niparnan

Rooted Tree Example

• Pick any vertex and declare it as a – We can assign a direction to the tree as the direction from the root to every vertex – A directed graph result from such direction is the – Different root yields different

prepared by Nattee Niparnan prepared by Nattee Niparnan Terminology for a rooted tree Terminology for a rooted tree

• Parent • Definition is a parent of when there is a directed edge from u to is the child of • Any vertex having no children • Sibling – Vertices with the same parent • Ancestors of • Any vertex not being a leaf – Any vertex in the path from the root to – i.e., the parent, the parent of the parent, the parent of the parent of the parent,… • Descendant of – Any vertex having the vertex as its ancestor

prepared by Nattee Niparnan prepared by Nattee Niparnan

Example Subtree

• Definition – A with v as its root is a subgraph of a tree that consists of v and all its descendants and the corresponding edges

prepared by Nattee Niparnan prepared by Nattee Niparnan M‐ary tree Example

• Definition – A tree is call if every internal vertex has no more than m children

– A tree is called “ ” when every internal vertex has exactly m children

– And m‐ary tree where m = 2 is called a binary tree

prepared by Nattee Niparnan prepared by Nattee Niparnan

An Ordered Tree Tree as a model

• A rooted tree such that we have “ordered” on the c hildren o f an in terna l no de – When we draw an ordered tree, the children are drawn from left to right according to its order • For binary tree – The first child is called the “ ” child • The tree rooted at the left child is called the left subtree – The second child is called the “ ” child • The tree rooted at the right child is called the right subtree

prepared by Nattee Niparnan prepared by Nattee Niparnan Tree as a model Properties of Trees

• Theorem 2 – ATreewithA Tree with vertices has edges • Proof – Convert a tree into a rooted tree – we see that the arrow of the directed tree point out from root – For every directed edge, there is one vertex associated with the edge • Except the root – Since we have non‐root vertices • Then we have exactly edge

prepared by Nattee Niparnan prepared by Nattee Niparnan

Properties of Trees Properties of Trees

• Theorem 3 • Theorem 4 – A full m‐ary tree with internal vertices – A full m‐ary tree with contains vertices 1) n vertices has internal vertices and • Proof leaves 2) i internal vertices has vertices and – Every vertex , except the root, in a tree is a child of an internal vertex 3) lleaveshasl leaves has vertices and – Since the tree is “full”, every internal vertex has internal vertices exactly children • So we have vertices, exclude the root

prepared by Nattee Niparnan prepared by Nattee Niparnan Proof of theorem 4 Balanced Tree

• Let define for a full m‐ary tree • It is a desirable property to have a tree that – l = number of leaves – i = number of internal vertices i“lis “almost ”fll” full – n = total number of vertices – i.e., we could say that we like balanced tree • We use theorem 3 and a fact that (because a vertex must be either a leave or an internal – Intuitively, a tree such that each subtree are of vertex similar size • Try 1) – Solve n = mi + 1 for i • i= (n –1)/m – Put this back into n = i+ l yields • l = n –i= n –(n –1)/m • = mn/m –(n­1)/m = [nm –(n –1)]/m = [(m –1)n + 1]/m

prepared by Nattee Niparnan prepared by Nattee Niparnan

Level and Height Example

• Definition – The of a vertex is the length of the unique path from the root to • The level of the root is defined as 0 – The of a rooted tree is the maximum of the levels of its vertices

prepared by Nattee Niparnan prepared by Nattee Niparnan Balanced Tree Theorem 5

• Definition • There are at most leaves in an m‐ary tree – A balanced tree is a rooted m‐ary tree of height ofhf he ig ht such that all leaves are at level h or

• Proof – By induction on the height of a tree

prepared by Nattee Niparnan prepared by Nattee Niparnan

Proof: The basis step Proof: the Inductive Step

• The base case • Assume that the result is true for the height • TfhihTree of height 1 lhhiiifhless than h, i.e., it is true for h‐1, h‐2, h‐3, … – The root is the only internal vertex but not h – We can’t have more than m children for the root • Consider a tree of height • These children are leaves – Take out the root of • So, the number of leaves is at most – Consider the remaining subtree of the root • These subtrees are of height at most • Hence, we can say that each subtree has at most • Hence, the base case is correct leaves

prepared by Nattee Niparnan prepared by Nattee Niparnan Proof: the Inductive step Corollary 1

• Now, the leaves of these subtrees are exactly • If an m‐ary tree of height has leaves, then the leaves of • Since we have at most subtrees • If an m‐ary tree is full and balance, then – The number of leaves is at most – (note that ceil is the ceiling function (round up))

• Hence, the theorem is correct by the • The proof is simple, try to read it from the principle of mathematical induction book

prepared by Nattee Niparnan prepared by Nattee Niparnan

Decision Tree

• We use tree to describe a process involving serifdiiies of decision Application of Tree Is a lecturer? yes no Section 10.2 Grant Have an ID card? access yes no

Grant Deny

prepared by Nattee Niparnanaccess access Eight coin problem Comparing three variables

• We have 8 coins • We have a,b,c all are distinct – One o f them i s a f a ke co in, w hic h is lig hter – We whhhich to sort t hese varia ble – We have a balance scale – How to determine a fake one?

prepared by Nattee Niparnan prepared by Nattee Niparnan