Chapter 6 - PowerPoint PPT Presentation

Loading...

PPT – Chapter 6 PowerPoint presentation | free to download - id: 84fb13-YjMyZ



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Chapter 6

Description:

Chapter 6 Trees Notice that in a tree, there is exactly one path from the root to each node Trees linked lists, stacks, and queues which are linear data ... – PowerPoint PPT presentation

Number of Views:7
Avg rating:3.0/5.0
Slides: 12
Provided by: stf89
Learn more at: http://cse.stfx.ca
Category:
Tags: about | chapter | trees

less

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

Title: Chapter 6


1
Chapter 6 Trees
2
Notice that in a tree, there is exactly one path
from the root to each node
3
Trees
  • linked lists, stacks, and queues which are linear
    data structures
  • A tree is a nonlinear data structure a tree is a
    collection of nodes connected by edges
  • root at the top
  • the leaves (i.e., terminal nodes) at the bottom
  • The root has no parent Leaves, on the other
    hand, have no children, or rather, their children
    are empty structures

4
A Recursive Definition
  • 1. An empty structure is a tree (a tree is a
    collection of nodes and the collection can be
    empty)
  • 2. If T1, , Tk are trees, then the structure
    whose root has as its children the roots of T1,
    , Tk is also a tree
  • 3. Only structures generated by rules 1 and 2
    are trees

5
A Recursive Definition (contd)
ROOT OF TREE T
T2
T3
T1
Tk
SUBTREES
6
An Example
A
B
C
D
E
H
G
F
I
N nodes, N-1 edges in a tree.
7
Some Definitions
  • Nodes with no children are leaves (C,E,F,H,I),
    they are also called external nodes. Nodes which
    are not leaves are called internal nodes
  • Nodes with the same parents are siblings
    (B,C,D,E) and (G,H)
  • A path from node ni to node nj is the sequence of
    directed edges from ni to nj
  • The level or depth of a node ni is the number of
    edges from the root to ni. The depth of the root
    is 0

8
Some Definitions (contd)
  • The height of a node ni is the length of the
    longest path from ni to a leaf. The height of a
    leaf node is 0
  • The height of a tree is equal to the height of
    the root

9
Binary Trees An Informal Definition
  • A binary tree is a tree in which no node can have
    more than two children
  • Each node has 0, 1, or 2 children

10
Binary Trees A Recursive Definition
  • 1. An empty structure is a binary tree
  • 2. If T1 and T2 are binary trees, then the
    structure whose root has as its children the
    roots of T1 and T2 is also a binary tree
  • 3. Only structures generated by rules 1 and 2
    are binary trees

11
Trees vs. Binary Trees
  • No node in a binary tree may have more than 2
    children, whereas there is no limit on the number
    of children of a node in a tree
About PowerShow.com