Binary Tree Traversals - PowerPoint PPT Presentation

Loading...

PPT – Binary Tree Traversals PowerPoint presentation | free to download - id: 7302d6-MjRiN



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Binary Tree Traversals

Description:

There are three methods of traversing a Binary tree: Preorder traversal Inorder traversal Postorder ... a sorting algorithm is an algorithm that puts elements of a ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 16
Provided by: admin1314
Learn more at: http://www.pgce.soton.ac.uk
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Binary Tree Traversals


1
Binary Tree Traversals
  • Emma Price

2
Objectives
  • To be able to
  • Explain what a binary tree is.
  • To traverse a binary tree using the three
    different methods.

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

4
Binary Trees
  • 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.

5
Revision
  • 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.

6
Sub-tree
7
Traversing a Binary Tree
  • 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.

8
Binary Tree Traversals
  • 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.

9
Preorder
1.Start at the root node 2.Traverse the left and
subtree 3.Traverse the righthand subtree
10
Preorder
10
10
12
5
5
12
11
15
3
7
3
7
11
15
Preordered for the above tree will be 10, 5, 3,
7, 12, 11, 15
11
Inorder
1.Traverse the lefthand tree 2.Visit the
node 3.Traverse the righthand subtree
12
Inorder
10
10
12
5
5
12
11
15
3
7
3
7
11
15
Preordered for the above tree will be 3, 5, 7,
10, 11,12,15
13
Postorder
1.Traverse the left hand subtree 2.Traverse the
righthand subtree 3. Return to the root node.
14
Postorder
10
10
12
5
5
12
11
15
3
7
3
7
11
15
Preordered for the above tree will be 3, 7, 5,
11, 15,12, 10
15
Conclusion
  • 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.

Reminder In computer science and mathematics, a
sorting algorithm is an algorithm that puts
elements of a list in a certain order
About PowerShow.com