24
Data Structures Lesson10 Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik Binary Trees & Search Trees

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

Embed Size (px)

Citation preview

Page 1: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Data StructuresLesson10

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

Binary Trees &

Search Trees

Page 2: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

INTRODUCTION • Ordered Tree: The sequence of

node is important • Unordered Tree: The sequence of

node is not important • Equal Tree: if two unordered trees

have the same subsets, then they are equal; but as ordered trees, they won’t be equal unless their equal subtrees are in the same order.

Page 3: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

INTRODUCTION (2)• A binary tree is an ordered tree in

which every internal node has degree 2 (left sub tree and right sub tree)

• An empty left sub tree is different from an empty right sub tree.

• Complete Binary Tree: Either a full binary tree or one that is full except for a segment of missing leaves on the right side of the bottom level.

• Forest: Sequence of disjoint ordered trees.

Page 4: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

EXAMPLEUnequal Ordered Tree:

Unequal Binary Tree:

Page 5: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

EXAMPLE (2)Complete binary trees:

Page 6: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

MAPPINGA COMPLETE BINARY TREE

INTO AN ARRAY

Page 7: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

MAPPINGA COMPLETE BINARY TREE

INTO AN ARRAY (2)

Page 8: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

EXPRESSION TREE

Page 9: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

SEARCH TREE

mlow = smallest key in the M (middle) subtreerlow = smallest key in the R (right) subtree

Page 10: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

SEARCH TREE EXAMPLE

Five-Way Search Tree

Page 11: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

INSERTING INTOFIVE-WAY SEARCH TREE

Page 12: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

INSERTING INTOFIVE-WAY SEARCH TREE (2)

Page 13: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

INSERTING INTOFIVE-WAY SEARCH TREE (3)

Page 14: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

B-TREE

Page 15: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

EXAMPLE OF B-TREE ORDER 5

Page 16: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

INSERTING INTO B-TREE

Page 17: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

BINARY SEARCH TREES (BST)

Page 18: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

BUILDING BST

Page 19: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

AVL TREE

Page 20: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

NON-AVL TREE

Page 21: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

BUILDING AVL TREE

Page 22: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

BUILDING AVL TREE EXAMPLE

Page 23: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

AVL TREE ROTATION

Page 24: Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

Author: Takdir, S.ST. ([email protected]) © Sekolah Tinggi Ilmu Statistik

THANK YOU