emma price 1. to be able to: explain what a binary tree is. to traverse a binary tree using the...
TRANSCRIPT
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
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
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
6
52
29 75
10 37 62 92
17 58 68
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
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
9
1.Start at the root node2.Traverse the left and
subtree3.Traverse the righthand
subtree
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
11
1.Traverse the lefthand tree2.Visit the node3.Traverse the righthand subtree
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
13
1.Traverse the left hand subtree2.Traverse the righthand subtree3. Return to the root node.
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
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