Download presentation
Presentation is loading. Please wait.
Published byRosalyn Daniel Modified over 9 years ago
1
Emma Price 1
2
To be able to: Explain what a binary tree is. To traverse a binary tree using the three different methods. 2
3
We all should know that a Binary Tree is not a type of tree! 3
4
In computer science, a tree is a widely-used data structure that emulates a tree structure with a set of linked nodes.computer sciencedata structuretree structure 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 heapscomputer sciencetreedata structure childrenbinary search treesbinary 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
5
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
6
7
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 traversal Postorder traversal In each case, the algorithms are recursive- they call themselves. 7
8
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
9 1.Start at the root node 2.Traverse the left and subtree 3.Traverse the righthand subtree
10
10 12 11 5 15 3 7 Preordered for the above tree will be: 10, 5, 3, 7, 12, 11, 15 10 5 3 7 12 11 15
11
11 1.Traverse the lefthand tree 2.Visit the node 3.Traverse the righthand subtree
12
10 12 11 5 15 3 7 Preordered for the above tree will be: 3, 5, 7, 10, 11,12,15 10 5 3 7 12 11 15
13
13 1.Traverse the left hand subtree 2.Traverse the righthand subtree 3. Return to the root node.
14
10 12 11 5 15 3 7 Preordered for the above tree will be: 3, 7, 5, 11, 15,12, 10 10 5 3 7 12 11 15
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.sorting algorithms search algorithmsin-order traversal 15 Reminder In computer science and mathematics, a sorting algorithm is an algorithm that puts elements of a list in a certain ordercomputer science mathematicsalgorithmlistorder
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.