Top Banner
SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search data structure and algorithms
92

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

Dec 14, 2015

Download

Documents

Hanna Isabel
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Binary Search Tree

A running demonstration of binary search data structure and algorithms

Page 2: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

First value is the 'Root' of the tree.

87

Page 3: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

Since 50 is Less than 87, we move to the left sub-tree

**Since no sub-tree, 50 is now added as the left leaf**

50

Page 4: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

Since 27 is Less than 87, we move to the left sub-tree

Since 27 is Less than 50, we move to the left sub-tree

**Since no sub-tree, 27 is now added as the left leaf**

27

Page 5: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

27

Since 111 is Greater than 87, we move to the right sub-tree

**Since no sub-tree, 111 is now added as the right leaf**

111

Page 6: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

27

111

Since 99 is Greater than 87, we move to the right sub-tree

Since 99 is Less than 111, we move to the left sub-tree

**Since no sub-tree, 99 is now added as the left leaf**

99

Page 7: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

27

111

99

Since 42 is Less than 87, we move to the left sub-tree

Since 42 is Less than 50, we move to the left sub-tree

Since 42 is Greater than 27, we move to the right sub-tree

**Since no sub-tree, 42 is now added as the right leaf**

42

Page 8: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

27

111

99

42

Since 90 is Greater than 87, we move to the right sub-tree

Since 90 is Less than 111, we move to the left sub-tree

Since 90 is Less than 99, we move to the left sub-tree

**Since no sub-tree, 90 is now added as the left leaf**

90

Page 9: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

27

111

99

42 90

Since 105 is Greater than 87, we move to the right sub-tree

Since 105 is Less than 111, we move to the left sub-tree

Since 105 is Greater than 99, we move to the right sub-tree

**Since no sub-tree, 105 is now added as the right leaf**

105

Page 10: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

27

111

99

42 90 105

Since 58 is Less than 87, we move to the left sub-tree

Since 58 is Greater than 50, we move to the right sub-tree

**Since no sub-tree, 58 is now added as the right leaf**

58

Page 11: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

27

111

99

42 90 105

58

Since 32 is Less than 87, we move to the left sub-tree

Since 32 is Less than 50, we move to the left sub-tree

Since 32 is Greater than 27, we move to the right sub-tree

Since 32 is Less than 42, we move to the left sub-tree

**Since no sub-tree, 32 is now added as the left leaf**

32

Page 12: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

27

111

99

42 90 105

58

32

Since 68 is Less than 87, we move to the left sub-tree

Since 68 is Greater than 50, we move to the right sub-tree

Since 68 is Greater than 58, we move to the right sub-tree

**Since no sub-tree, 68 is now added as the right leaf**

68

Page 13: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

27

111

99

42 90 105

58

32

68

Since 43 is Less than 87, we move to the left sub-tree

Since 43 is Less than 50, we move to the left sub-tree

Since 43 is Greater than 27, we move to the right sub-tree

Since 43 is Greater than 42, we move to the right sub-tree

**Since no sub-tree, 43 is now added as the right leaf**

43

Page 14: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

27

111

99

42 90 105

58

32

68

43

Since 60 is Less than 87, we move to the left sub-tree

Since 60 is Greater than 50, we move to the right sub-tree

Since 60 is Greater than 58, we move to the right sub-tree

Since 60 is Less than 68, we move to the left sub-tree

**Since no sub-tree, 60 is now added as the left leaf**

60

Page 15: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

27

111

99

42 90 105

58

32

68

43 60

Since 70 is Less than 87, we move to the left sub-tree

Since 70 is Greater than 50, we move to the right sub-tree

Since 70 is Greater than 58, we move to the right sub-tree

Since 70 is Greater than 68, we move to the right sub-tree

**Since no sub-tree, 70 is now added as the right leaf**

70

Page 16: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

27

111

99

42 90 105

58

32

68

43 60 70

Since 51 is Less than 87, we move to the left sub-tree

Since 51 is Greater than 50, we move to the right sub-tree

Since 51 is Less than 58, we move to the left sub-tree

**Since no sub-tree, 51 is now added as the left leaf**

51

Page 17: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

27

111

99

42 90 105

58

32

68

43 60 70

51

Since 1 is Less than 87, we move to the left sub-tree

Since 1 is Less than 50, we move to the left sub-tree

Since 1 is Less than 27, we move to the left sub-tree

**Since no sub-tree, 1 is now added as the left leaf**

1

Page 18: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Insert

87

50

27

111

99

42 90 105

58

32

68

43 60 70

511

Since 11 is Less than 87, we move to the left sub-tree

Since 11 is Less than 50, we move to the left sub-tree

Since 11 is Less than 27, we move to the left sub-tree

Since 11 is Greater than 1, we move to the right sub-tree

**Since no sub-tree, 11 is now added as the right leaf**

11

Page 19: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Predecessor

The node to delete is 50

Predecessor is found by finding the right most node of the 50 nodes left sub-tree

87

50

27

111

99

42 90 105

58

32

68

43 60 70

511

11

Page 20: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Sucsessor

Successor is found by finding the left most node of the 50 nodes right sub-tree

87

50

27

111

99

42 90 105

58

32

68

43 60 70

511

11

Page 21: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

How to delete 50?

There is a left child so we find predecessor

To learn more about finding predecessor insert <Fpred>starting value</Fpred> to data file

87

50

27

111

99

42 90 105

58

32

68

43 60 70

511

11

Page 22: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Delete

There is a left child so we find predecessor

This is how the new tree would appear

87

43

27

1

11

42

32

58

51 68

60 70

111

99

90 105

Page 23: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

How to delete 105?

This is a Leaf case

We just remove this node from the tree

87

43

27

1

11

42

32

58

51 68

60 70

111

99

90 105

Page 24: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Delete

This is a Leaf case

This is how the new tree would appear

87

43

27

1

11

42

32

58

51 68

60 70

111

99

90

Page 25: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

How to delete 87?

There is a left child so we find predecessor

To learn more about finding predicessor insert <Fpred>starting value</Fpred> to data file

87

43

27

1

11

42

32

58

51 68

60 70

111

99

90

Page 26: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Delete

There is a left child so we find predecessor

This is how the new tree would appear

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Page 27: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

How to delete 111?

There is only one child, so replace the node with its only child

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Page 28: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

After 111 is replaced by its only child

There is only one child, so replace the node with its only child

70

43

27

1

11

42

32

58

51 68

60

99

90

Page 29: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

PreOrder Traversal

Page 30: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PreOrder Traversal

1.Visit the root

2.Visit the left sub-tree 3.Visit the right sub-tree

Page 31: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PreOrder Traversal

1.Visit the root

2.Visit the left sub-tree 3.Visit the right sub-tree

Page 32: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PreOrder Traversal

1.Visit the root

2.Visit the left sub-tree 3.Visit the right sub-tree

Page 33: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PreOrder Traversal

1.Visit the root

2.Visit the left sub-tree 3.Visit the right sub-tree

Page 34: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PreOrder Traversal

1.Visit the root

2.Visit the left sub-tree 3.Visit the right sub-tree

Page 35: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PreOrder Traversal

1.Visit the root

2.Visit the left sub-tree 3.Visit the right sub-tree

Page 36: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PreOrder Traversal

1.Visit the root

2.Visit the left sub-tree 3.Visit the right sub-tree

Page 37: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PreOrder Traversal

1.Visit the root

2.Visit the left sub-tree 3.Visit the right sub-tree

Page 38: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PreOrder Traversal

1.Visit the root

2.Visit the left sub-tree 3.Visit the right sub-tree

Page 39: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PreOrder Traversal

1.Visit the root

2.Visit the left sub-tree 3.Visit the right sub-tree

Page 40: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PreOrder Traversal

1.Visit the root

2.Visit the left sub-tree 3.Visit the right sub-tree

Page 41: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PreOrder Traversal

1.Visit the root

2.Visit the left sub-tree 3.Visit the right sub-tree

Page 42: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PreOrder Traversal

1.Visit the root

2.Visit the left sub-tree 3.Visit the right sub-tree

Page 43: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PreOrder Traversal

1.Visit the root

2.Visit the left sub-tree 3.Visit the right sub-tree

Page 44: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

InOrder Traversal

Page 45: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

InOrder Traversal

1.Visit the left sub-tree

2.Visit the root 3.Visit the right sub-tree

Page 46: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

InOrder Traversal

1.Visit the left sub-tree

2.Visit the root 3.Visit the right sub-tree

Page 47: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

InOrder Traversal

1.Visit the left sub-tree

2.Visit the root 3.Visit the right sub-tree

Page 48: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

InOrder Traversal

1.Visit the left sub-tree

2.Visit the root 3.Visit the right sub-tree

Page 49: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

InOrder Traversal

1.Visit the left sub-tree

2.Visit the root 3.Visit the right sub-tree

Page 50: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

InOrder Traversal

1.Visit the left sub-tree

2.Visit the root 3.Visit the right sub-tree

Page 51: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

InOrder Traversal

1.Visit the left sub-tree

2.Visit the root 3.Visit the right sub-tree

Page 52: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

InOrder Traversal

1.Visit the left sub-tree

2.Visit the root 3.Visit the right sub-tree

Page 53: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

InOrder Traversal

1.Visit the left sub-tree

2.Visit the root 3.Visit the right sub-tree

Page 54: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

InOrder Traversal

1.Visit the left sub-tree

2.Visit the root 3.Visit the right sub-tree

Page 55: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

InOrder Traversal

1.Visit the left sub-tree

2.Visit the root 3.Visit the right sub-tree

Page 56: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

InOrder Traversal

1.Visit the left sub-tree

2.Visit the root 3.Visit the right sub-tree

Page 57: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

InOrder Traversal

1.Visit the left sub-tree

2.Visit the root 3.Visit the right sub-tree

Page 58: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

InOrder Traversal

1.Visit the left sub-tree

2.Visit the root 3.Visit the right sub-tree

Page 59: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

PostOrder Traversal

Page 60: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PostOrder Traversal

1.Visit the left sub-tree

2.Visit the right sub-tree 3.Visit the root

Page 61: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PostOrder Traversal

1.Visit the left sub-tree

2.Visit the right sub-tree 3.Visit the root

Page 62: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PostOrder Traversal

1.Visit the left sub-tree

2.Visit the right sub-tree 3.Visit the root

Page 63: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PostOrder Traversal

1.Visit the left sub-tree

2.Visit the right sub-tree 3.Visit the root

Page 64: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PostOrder Traversal

1.Visit the left sub-tree

2.Visit the right sub-tree 3.Visit the root

Page 65: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PostOrder Traversal

1.Visit the left sub-tree

2.Visit the right sub-tree 3.Visit the root

Page 66: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PostOrder Traversal

1.Visit the left sub-tree

2.Visit the right sub-tree 3.Visit the root

Page 67: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PostOrder Traversal

1.Visit the left sub-tree

2.Visit the right sub-tree 3.Visit the root

Page 68: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PostOrder Traversal

1.Visit the left sub-tree

2.Visit the right sub-tree 3.Visit the root

Page 69: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PostOrder Traversal

1.Visit the left sub-tree

2.Visit the right sub-tree 3.Visit the root

Page 70: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PostOrder Traversal

1.Visit the left sub-tree

2.Visit the right sub-tree 3.Visit the root

Page 71: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PostOrder Traversal

1.Visit the left sub-tree

2.Visit the right sub-tree 3.Visit the root

Page 72: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PostOrder Traversal

1.Visit the left sub-tree

2.Visit the right sub-tree 3.Visit the root

Page 73: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

PostOrder Traversal

1.Visit the left sub-tree

2.Visit the right sub-tree 3.Visit the root

Page 74: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Breadth First Traversal

Page 75: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Breadth First Traversal

1.Visit the root

2.Visit both Children 3.Visit Their Children

Visit

Page 76: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Breadth First Traversal

1.Visit the root

2.Visit both Children 3.Visit Their Children

Visit

Page 77: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Breadth First Traversal

1.Visit the root

2.Visit both Children 3.Visit Their Children

Visit

Page 78: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Breadth First Traversal

1.Visit the root

2.Visit both Children 3.Visit Their Children

Visit

Page 79: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Breadth First Traversal

1.Visit the root

2.Visit both Children 3.Visit Their Children

Visit

Page 80: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Breadth First Traversal

1.Visit the root

2.Visit both Children 3.Visit Their Children

Visit

Page 81: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Breadth First Traversal

1.Visit the root

2.Visit both Children 3.Visit Their Children

Visit

Page 82: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Breadth First Traversal

1.Visit the root

2.Visit both Children 3.Visit Their Children

Visit

Page 83: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Breadth First Traversal

1.Visit the root

2.Visit both Children 3.Visit Their Children

Visit

Page 84: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Breadth First Traversal

1.Visit the root

2.Visit both Children 3.Visit Their Children

Visit

Page 85: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Breadth First Traversal

1.Visit the root

2.Visit both Children 3.Visit Their Children

Visit

Page 86: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Breadth First Traversal

1.Visit the root

2.Visit both Children 3.Visit Their Children

Visit

Page 87: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Breadth First Traversal

1.Visit the root

2.Visit both Children 3.Visit Their Children

Visit

Page 88: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Breadth First Traversal

1.Visit the root

2.Visit both Children 3.Visit Their Children

Visit

Page 89: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Size

Page 90: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Size

Size is the amount of nodes in a tree

1

2

3

4

5

6

7

8

9 10

11

12

13

14

Size = 14

Page 91: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Height

Page 92: SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group

Height

Hight is the number of Levels between

the root and lowest leaf

70

43

27

1

11

42

32

58

51 68

60

111

99

90

Height = 5