emma price 1. to be able to: explain what a binary tree is. to traverse a binary tree using the...

15
Emma Price 1

Upload: rosalyn-daniel

Post on 31-Dec-2015

216 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

Emma Price

1

Page 2: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

To be able to:

Explain what a binary tree is.

To traverse a binary tree using the three different methods.

2

Page 3: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

We all should know that a Binary Tree is not a type of tree!

3

Page 4: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

In computer science, a tree is a widely-used data structure that emulates a tree structure with a set of linked nodes.

In computer science, a binary tree is a tree data structure in which each node has at most two children. Typically the child nodes are called left and right. One common use of binary trees is binary search trees; another is binary heaps

Each node on the tree contains two links to two other trees, both referred to as subtrees. The two subtrees are often called the left and right subtree.

4

Page 5: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

Binary Composed of two parts Represents numeric values using two

symbols typically 0 and 1.

What is recursion? A function that calls itself with a similar

subset of numbers with which it began. The function must be aware that an end

state exists which terminates the recursive process.

5

Page 6: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

6

52

29 75

10 37 62 92

17 58 68

Page 7: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

Traversing a tree means visiting all the nodes of a tree in order.

There are three methods of traversing a Binary tree:

Preorder traversal Inorder traversalPostorder traversal In each case, the algorithms are

recursive-they call themselves.7

Page 8: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

The reason we transverse a binary tree is to examine each of its nodes.

Many different binary tree algorithms involve traversals.

For example if we wish o find the largest value in each node, we must examine the value contained in each mode.

8

Page 9: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

9

1.Start at the root node2.Traverse the left and

subtree3.Traverse the righthand

subtree

Page 10: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

10

12

11

5

153 7

Preordered for the above tree will be:

10, 5, 3, 7, 12, 11, 15

10

5

3 7

12

11 15

Page 11: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

11

1.Traverse the lefthand tree2.Visit the node3.Traverse the righthand subtree

Page 12: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

10

12

11

5

153 7

Preordered for the above tree will be:

3, 5, 7, 10, 11,12,15

10

5

3 7

12

11 15

Page 13: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

13

1.Traverse the left hand subtree2.Traverse the righthand subtree3. Return to the root node.

Page 14: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

10

12

11

5

153 7

Preordered for the above tree will be:

3, 7, 5, 11, 15,12, 10

10

5

3 7

12

11 15

Page 15: Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2

The major advantage of binary search trees is that the related sorting algorithms and search algorithms such as in-order traversal can be very efficient.

15

ReminderIn computer science and mathematics, a sorting

algorithm is an algorithm that puts elements of a list

in a certain order