Foundation of Computing Systems - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Foundation of Computing Systems

Description:

(ii) remaining nodes are partitioned into n (n 0) disjoint sets T1, T2, ... Height balanced tree (also known as AVL tree) Red black tree. Splay tree. Decision tree ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 23
Provided by: informat1696
Category:

less

Transcript and Presenter's Notes

Title: Foundation of Computing Systems


1
Foundation of Computing Systems
  • Lecture 4
  • Trees Part I

2
Tree Example
3
Tree Definition
  • A tree is a finite set of one or more nodes such
    that
  • (i) there is a specially designated node called
    the root
  • (ii) remaining nodes are partitioned into n (n gt
    0) disjoint sets T1, T2, . . ., Tn, where each Ti
    (i 1, 2, . . ., n) is a tree T1, T2, . . ., Tn
    are called sub trees of the root.

T (A(B(E, F(K, L))), C(G), D(H, I, J))
4
Binary Tree
  • A binary tree is a special form of a tree
  • A binary tree T is a finite set of nodes, such
    that
  • (i) T is empty (called empty binary tree), or
  • (ii) T contains a specially designated node
    called the root of T, and the remaining nodes of
    T form two disjoint binary trees T1 and T2 which
    are called left sub-tree and the right sub-trees,
    respectively.

5
Full Binary Tree
6
Complete Binary Tree
7
Skewed Binary Tree
8
Properties of Binary Trees
  • Property 1
  • In any binary tree, maximum number of nodes on
    level l is 2l, where l 0.
  • Property 2
  • Maximum number of nodes possible in a binary tree
    of height h is 2h 1.
  • Property 3
  • Minimum number of nodes possible in a binary tree
    of height h is h.
  • Property 4
  • For any non-empty binary tree, if n is the number
    of nodes and e is the number of edges, then n e
    1.

9
Properties of Binary Trees
  • Property 5
  • For any non-empty binary tree T, if n0 is the
    number of leaf nodes (degree 0) and n2 is the
    number of internal node (degree 2), then n0
    n2 1.
  • Property 6
  • Height of a complete binary tree with n number of
    nodes is
  • Property 7
  • Total number of binary tree possible with n nodes
    is



10
Representation of Binary Trees
  • Linear representation
  • Using array
  • Linked representation
  • Using linked list structure

11
Linear Representation of Binary Trees
  • The root node is at location 1.
  • For any node with index i, 1 lt i n, (for some
    n)
  • (a) PARENT(i)

  • For the node when i 1, there is no
    parent.
  • (b) LCHILD(i) 2 i

  • If 2 i gt n, then i has no left child.
  • (c) RCHILD(i) 2 i 1

  • If 2 i 1 gt n, then i has no right child.

12
Linked Representation of Binary Trees
13
Linked Representation of Binary Trees
14
Binary Tree Operations
  • Major operations on a binary tree can be listed
    as
  • Insertion.  To include a node into an existing
    (may be empty) binary tree.
  • Deletion.  To delete a node from a non-empty
    binary tree.
  • Traversal.  To visit all the nodes in a binary
    tree.
  • Merge.  To merge two binary trees into a larger
    one.

15
Binary Tree Insertion
16
Binary Tree Deletion
17
Binary Tree Traversals
  • Depth-first search
  • Breadth-first search (level-by search)
  • Recursive search

1. R Tl Tr 4. Tr Tl R 2. Tl R Tr 5. Tr R Tl
3. Tl Tr R 6. R Tr Tl
18
Binary Tree Traversals
- A B C / E F
F E / C B A
A B C E / F
F / E C B A
A B C E F /
/ F E C B A
19
Binary Tree Traversals
R Tl Tr (Preorder) Tl R Tr
(Inorder) Tl Tr R (Postorder)
- A B C / E F
F E / C B A
A B C E / F
F / E C B A
A B C E F /
/ F E C B A
20
Binary Tree Traversals
  • Preorder traversal
  • Visit the root node R.
  • Traverse the left sub-tree of R in preorder.
  • Traverse the right sub-tree of R in preorder.
  • Inorder traversal
  • Traverse the left sub-tree of the root node R
    is inorder.
  • Visit the root node R.
  • Traverse the right sub-tree of the root node R
    is inorder.
  • Postorder traversal
  • Traverse the left sub-tree of the root R in
    postorder
  • Traverse the right sub-tree of the root R in
    postorder
  • Visit the root node R.

21
Binary Tree Merging
22
Different Binary Trees
  • There are several types of binary trees possible
    each with its own properties.
  • Expression tree
  • Binary search tree
  • Heap tree
  • Threaded binary tree
  • Huffman tree
  • Height balanced tree (also known as AVL tree)
  • Red black tree
  • Splay tree
  • Decision tree
Write a Comment
User Comments (0)
About PowerShow.com