Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

19
Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras

Transcript of Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Page 1: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

Trees

Sir Joseph LindoUniversity of the Cordilleras

Page 2: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

BST

Cases

Traversals

Binary Tree

Trees

Course TitleTree

In computer science, a tree is an abstract model of a hierarchical structure

Trees

Page 3: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

BST

Cases

Traversals

Binary Tree

Trees

Course TitleBinary Tree

A binary tree is a finite set of elements that is either empty or is partitioned into three disjoint subsets.

The other two subsets are themselves binary trees called the left and right subtrees.

Binary Trees

Page 4: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

BST

Cases

Traversals

Binary Tree

Trees

Course TitleBinary Tree

The other two subsets are themselves binary trees called the left and right subtrees.

• Ordered Tree• Full binary tree• Skewed binary tree

Binary Trees

Page 5: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

BST

Cases

Traversals

Binary Tree

Trees

Course TitleBinary SearchTree• All identifiers in the left

subtree are less than the identifier in the root node

• All identifiers in the right subtree are greater than the identifier in the root node

BST

Page 6: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

BST

Cases

Traversals

Binary Tree

Trees

Course TitleTraversing• It is the process of visiting

each node in a tree exactly one.

Common traversals:Traversals

Page 7: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

BST

Cases

Traversals

Binary Tree

Trees

Course TitleTraversals• Preorder

Node - Left - Right • InorderLeft - Node -Right

• PostorderLeft - Right - Node• Level - order

Traversals

Want an easy way to do INORDER

Traversal?

SQUISHING

Page 8: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

Trees

-- end --Sir Joseph Lindo

University of the Cordilleras

Page 9: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

Trees

-- end na --Sir Joseph Lindo

University of the Cordilleras

Page 10: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

Applications

Tree

Organization charts

File systems Programming

environments

Page 11: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

Terminologies

Tree

Node Root Node Parent Node Siblings Internal Node External

Node/Leaf/ Terminal

Page 12: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

Terminologies

Tree

Ancestors Descendants Subtree Level Depth Height Degree Weigth

Page 13: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

Properties

Binary Tree

• 2i-1: maximum number of nodes on level I of a binary tree

• 2k-1: maximum number of nodes in a binary tree of height k

Page 14: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

Examples

Traversals

Page 15: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

Squishing

INORDER Traversal

Page 16: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

Level - Order

Traversal

Page 17: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

Trees

-- end --Sir Joseph Lindo

University of the Cordilleras

Page 18: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

Trees

-- end na --Sir Joseph Lindo

University of the Cordilleras

Page 19: Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.

Joseph Lindo

Examples