SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Discrete Mathematics

NOR AIDAWATI BINTI ABDILLAH


         TREES

                              1
Tree

Definition 1. A tree is a connected
 undirected graph with no simple circuits.

Theorem 1. An undirected graph is a tree if
  and only if there is a unique simple path
  between any two of its vertices.



                                              2
Which graphs are trees?
a)                 b)




       c)




                               3
Is it a tree?


                          NO!
yes!                 All the nodes are         yes! (but not
                      not connected             a binary tree)




            NO!
       There is a cycle                  yes! (it’s actually
         and an extra                    the same graph as
        edge (5 nodes                    the blue one) – but
        and 5 edges)                       usually we draw
                                          tree by its “levels”4
Rooted Trees

q   Rooted tree is a tree in which one vertex is
    distinguished and called a root
q   Level of a vertex is the number of edges
    between the vertex and the root
q   The height of a rooted tree is the
    maximum level of any vertex
q   Children, siblings and parent vertices in a
    rooted tree
q   Ancestor, descendant relationship
    between vertices
                                               5
q   The parent of a non-root vertex is the unique vertex
    u with a directed edge from u to v.
q   A vertex is called a leaf if it has no children.
q   The ancestors of a non-root vertex are all the
    vertices in the path from root to this vertex.
q   The descendants of vertex v are all the vertices that
    have v as an ancestor.
q   The level of vertex v in a rooted tree is the length of
    the unique path from the root to v.
q   The height of a rooted tree is the maximum of the
                                                     6
    levels of its vertices.
A Tree Has a Root
                                  root node
                          a
internal vertex                               parent of g
          b                             c


    d             e           f             g

   leaf
                                     siblings
              h       i
                                                            7
a


    b                             c


d           e            f            g

                        ancestors of h and i
        h       i
The level of a vertex v in a rooted tree is
the length of the unique path from the root
to this vertex.

          level 2

     level 3
a


    b                              c


d           e           f              g

                            subtree with b as its
        h       i           root
                            subtree with c as its
                            root
Tree Properties

q   There is one and only one path between
    every pair of vertices in a tree, T.
q   A tree with n vertices has n-1 edges.
q   Any connected graph with n vertices and n-1
    edges is a tree.
q   A graph is a tree if and only if it is minimally
    connected.                                   11
Tree Properties

Theorem . There are at most 2 H leaves in a
  binary tree of height H.

Corallary. If a binary tree with L leaves is
 full and balanced, then its height is
              H =  log2 L  .


                                               12
Properties of Trees

There are at most mh leaves in an m-ary
tree of height h.
A rooted m-ary tree of height h is called
balanced if all leaves are at levels h or h-1.
Properties of Trees

 A full m-ary tree with
(i) n vertices has i = (n-1)/m internal
vertices and l = [(m-1)n+1]/m leaves.
(ii) i internal vertices has n = mi + 1
vertices and l = (m-1)i + 1 leaves.
(iii) l leaves has n = (ml - 1)/(m-1) vertices
and i = (l-1)/(m-1) internal vertices.
Properties of Trees

A full m-ary tree with i internal vertices
contains n = mi+1 vertices.
Proof

q We know n = mi+1 (previous
  theorem) and n = l+i,
q n – no. vertices
q i – no. internal vertices
q l – no. leaves
q For example, i = (n-1)/m
Binary Tree
A rooted tree in which each vertex has either
no children, one child or two children.
 The tree is called a full binary tree if every
internal vertex has exactly 2 children.
                               A



                       B               C right child of A

left subtree
        of A       D       E       F       G
                                                   right
                                                   subtree of
               H                                   C            17
                                       I       J
Ordered Binary Tree

Definition 2’’. An ordered rooted tree is a
 rooted tree where the children of each
 internal vertex are ordered.

  In an ordered binary tree, the two
  possible children of a vertex are called
  the left child and the right child, if they
  exist.

                                                18
An Ordered Binary Tree

                 A
             B
     E               C

K        F       G       D

     L               H

                 M           I

                                 J
                                 19
Is this binary tree balanced?
                     A rooted binary tree of height
               Lou   H is called balanced if all its
                     leaves are at levels H or H-1.

       Hal           Max

Ed           Ken              Sue

         Joe                         Ted
                                              20
Searching takes time . . .
So the goal in computer programs is to find
 any stored item efficiently when all stored
 items are ordered.

A Binary Search Tree can be used to store
  items in its vertices. It enables efficient
  searches.



                                                21
A Binary Search Tree (BST) is . . .
A special kind of binary tree in which:
1. Each vertex contains a distinct key value,
2. The key values in the tree can be compared using
   “greater than” and “less than”, and
3. The key value of each vertex in the tree is
   less than every key value in its right subtree, and
   greater than every key value in its left subtree.
A Binary Expression Tree is . . .
A special kind of binary tree in which:
l   Each leaf node contains a single operand,
l   Each nonleaf node contains a single binary
    operator, and
l   The left and right subtrees of an operator
    node represent subexpressions that must be
    evaluated before applying the operator at
    the root of the subtree.

                                                23
Expression Tree
q   Each node contains an
    operator or an operand
q   Operands are stored in
    leaf nodes
q   Parentheses are not stored (x + y)*((a + b)/c)
    in the tree because the tree structure
    dictates the order of operand evaluation
q   Operators in nodes at higher levels are
    evaluated after operators in nodes at lower
    levels
                                                24
A Binary Expression Tree

                             ‘*’


                       ‘+’         ‘3’


                 ‘4’     ‘2’

What value does it have?

( 4 + 2 ) * 3 = 18
                                         25
A Binary Expression Tree

                              ‘*’


                        ‘+’         ‘3’


                  ‘4’     ‘2’

Infix:      ((4+2)*3)
Prefix:     * + 4 2 3                evaluate from right
Postfix:    4 2 + 3 *                evaluate from left
                                                           26
Levels Indicate Precedence
When a binary expression tree is used to
 represent an expression, the levels of the
 nodes in the tree indicate their relative
 precedence of evaluation.

Operations at higher levels of the tree are
 evaluated later than those below them.
 The operation at the root is always the
 last operation performed.

                                              27
Evaluate
this binary expression tree
                    ‘*’


        ‘-’                       ‘/’


 ‘8’          ‘5’          ‘+’          ‘3’


                     ‘4’         ‘2’

       What expressions does it represent?
                                              28
A binary expression tree
                            ‘*’

               ‘-’                         ‘/’

         ‘8’         ‘5’           ‘+’           ‘3’

                             ‘4’         ‘2’

Infix:         ((8-5)*((4+2)/3))
Prefix:        *-85 /+423          evaluate from right
Postfix:       85- 42+3/*          evaluate from left
                                                        29
Binary Tree for Expressions




                              30
Complete Binary Tree
Also be defined as a full binary tree in which all
leaves are at depth n or n-1 for some n.

In order for a tree to be the latter kind of complete
binary tree, all the children on the last level must
occupy the leftmost spots consecutively, with no
spot left unoccupied in between any two
                   A                                           A


           B                                   B                               C
                           C

       D               F       G       D               E               F               G
               E

                                   H       I       J       K       L       M       N       O
   H       I                                                                   31
    Complete binary tree               Full binary tree of depth 4
Difference between binary and
        complete binary tree
     BINARY TREE ISN'T NECESSARY THAT ALL OF
          LEAF NODE IN SAME LEVEL BUT
    COMPLETE BINARY TREE MUST HAVE ALL LEAF
               NODE IN SAME LEVEL.




Binary Tree

                                           32
    Complete Binary Tree
SPANNING TREES

q   A spanning tree of a connected graph G is
    a sub graph that is a tree and that includes
    every vertex of G.
q   A minimum spanning tree of a weighted
    graph is a spanning tree of least weight
    (the sum of the weights of all its edges is
    least among all spanning tree).
q   Think: “smallest set of edges needed to
    connect everything together”
                                               33
A graph G and three of its
spanning tree


  We can delete any edge without deleting any vertex (to remove
            the cycle), but leave the graph connected.




                                                           34
PRIM’S ALGORITHM

q   Choose any edge with smallest weight,
    putting it into the spanning tree.
q   Successively add to the tree edges of
    minimum weight that are incident to a
    vertex already in the tree and not forming a
    simple circuit with those edges already in
    the tree.
q   Stop when n – 1 edges have been added.

                                              35
EXAMPLE
         PRIM’S ALGORITHM
Use Prim’s algorithm to find a minimum spanning tree
in the weighted graph below:

            a   2       b   3       c   1   d

         3          1           2               5
        e       4   f       3   g       3       h

         4          2           4               3

            i   3       j   3       k   1   l       36
SOLUTION

                                             Choice   Edge      Weight
                                               1      {b, f}      1
    a   2       b           c    1   d         2      {a, b}      2
                                               3      {f, j}      2
3           1           2                      4      {a, e}      3
            f       3   g        3       h     5       {i, j}     3
e
                                               6      {f, g}      3
            2                            3     7      {c, g}      2
                                               8      {c, d}      1
    i           j                              9      {g, h}      3
        3                   k    1   l
                                              10      {h, l}      3
                                              11      {k, l}      1
                                                      Total:      24
                                                                 37
KRUSKAL’S ALGORITHM

q Choose an edge in the graph with
  minimum weight.
q Successively add edges with minimum
  weight that do not form a simple circuit
  with those edges already chosen.
q Stop after n – 1 edges have been
  selected.

                                             38
Kruskal’s Algorithm

q Pick the cheapest link (edge)
  available and mark it
q Pick the next cheapest link available
  and mark it again
q Continue picking and marking link
  that does not create the circuit

***Kruskal’s algorithm is efficient and
  optimal                                 39
EXAMPLE
     KRUSKAL’S ALGORITHM
Use Kruskal’s algorithm to find a minimum spanning
tree in the weighted graph below:

            a   2       b   3       c   1   d

         3          1           2               5
        e       4   f       3   g       3       h

         4          2           4               3

            i   3       j   3       k   1   l       40
SOLUTION

                                             Choice   Edge      Weight
                                               1      {c, d}      1
                                               2      {k, l}      1
    a   2       b   3       c   1    d         3      {b, f}      1
                                               4      {c, g}      2
3           1           2                      5      {a, b}      2
            f           g       3        h     6      {f, j}      2
e
                                               7      {b, c}      3
            2                                  8      {j, k}      3
                                               9      {g, h}      3
    i           j   3                         10       {i, j}     3
        3                   k    1   l
                                              11      {a, e}      3
                                                      Total:     24
                                                                  41
TRAVELLING SALESMAN
       PROBLEM (TSP)

The goal of the Traveling Salesman Problem
(TSP) is to find the “cheapest” tour of a select
number of “cities” with the following
restrictions:

●
  You must visit each city once and only once
●
  You must return to the original starting point



                                              42
TSP
TSP is similar to these variations of Hamiltonian Circuit
  problems:

   ●
       Find the shortest Hamiltonian cycle in a
       weighted graph.
   ●
       Find the Hamiltonian cycle in a weighted
       graph with the minimal length of the
       longest edge. (bottleneck TSP).
   A route returning to the beginning is known as a
                  Hamiltonian Circuit

   A route not returning to the beginning is known as a
                                                          43
                    Hamiltonian Path
THANK YOU


            44

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
AVL Tree Data Structure
AVL Tree Data StructureAVL Tree Data Structure
AVL Tree Data Structure
 
Red black tree
Red black treeRed black tree
Red black tree
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Discrete-Chapter 10 Trees
Discrete-Chapter 10 TreesDiscrete-Chapter 10 Trees
Discrete-Chapter 10 Trees
 
Chapter 8 ds
Chapter 8 dsChapter 8 ds
Chapter 8 ds
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
AVL tree animation.ppt
AVL tree animation.pptAVL tree animation.ppt
AVL tree animation.ppt
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
Binary tree
Binary treeBinary tree
Binary tree
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Tree (Data Structure & Discrete Mathematics)
Tree (Data Structure & Discrete Mathematics)Tree (Data Structure & Discrete Mathematics)
Tree (Data Structure & Discrete Mathematics)
 

Andere mochten auch

Discrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part IIDiscrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part IIWongyos Keardsri
 
Cinterviews Binarysearch Tree
Cinterviews Binarysearch TreeCinterviews Binarysearch Tree
Cinterviews Binarysearch Treecinterviews
 
Discrete Mathematics & Its Applications (Graphs)
Discrete Mathematics & Its Applications (Graphs)Discrete Mathematics & Its Applications (Graphs)
Discrete Mathematics & Its Applications (Graphs)Fahrul Usman
 
Chapter 4 dis 2011
Chapter 4 dis 2011Chapter 4 dis 2011
Chapter 4 dis 2011noraidawati
 
17 Trees and graphs
17 Trees and graphs17 Trees and graphs
17 Trees and graphsmaznabili
 
Tree in Discrete structure
Tree in Discrete structureTree in Discrete structure
Tree in Discrete structureNoman Rajput
 
Bsc cs ii dfs u-3 tree and graph
Bsc cs  ii dfs u-3 tree and graphBsc cs  ii dfs u-3 tree and graph
Bsc cs ii dfs u-3 tree and graphRai University
 
Relations digraphs
Relations  digraphsRelations  digraphs
Relations digraphsIIUM
 
Depth first search and breadth first searching
Depth first search and breadth first searchingDepth first search and breadth first searching
Depth first search and breadth first searchingKawsar Hamid Sumon
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)Trupti Agrawal
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentationAlizay Khan
 

Andere mochten auch (17)

Avltrees
AvltreesAvltrees
Avltrees
 
Discrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part IIDiscrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part II
 
Trees and graphs
Trees and graphsTrees and graphs
Trees and graphs
 
Cinterviews Binarysearch Tree
Cinterviews Binarysearch TreeCinterviews Binarysearch Tree
Cinterviews Binarysearch Tree
 
Discrete Mathematics & Its Applications (Graphs)
Discrete Mathematics & Its Applications (Graphs)Discrete Mathematics & Its Applications (Graphs)
Discrete Mathematics & Its Applications (Graphs)
 
Chapter 4 dis 2011
Chapter 4 dis 2011Chapter 4 dis 2011
Chapter 4 dis 2011
 
17 Trees and graphs
17 Trees and graphs17 Trees and graphs
17 Trees and graphs
 
Tree in Discrete structure
Tree in Discrete structureTree in Discrete structure
Tree in Discrete structure
 
Bsc cs ii dfs u-3 tree and graph
Bsc cs  ii dfs u-3 tree and graphBsc cs  ii dfs u-3 tree and graph
Bsc cs ii dfs u-3 tree and graph
 
Relations digraphs
Relations  digraphsRelations  digraphs
Relations digraphs
 
DFS & BFS Graph
DFS & BFS GraphDFS & BFS Graph
DFS & BFS Graph
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
The Political History Of Bangladesh
The Political History Of BangladeshThe Political History Of Bangladesh
The Political History Of Bangladesh
 
Depth first search and breadth first searching
Depth first search and breadth first searchingDepth first search and breadth first searching
Depth first search and breadth first searching
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
 

Ähnlich wie Discrete Mathematics Trees

Ähnlich wie Discrete Mathematics Trees (20)

Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 
Unit – vi tree
Unit – vi   treeUnit – vi   tree
Unit – vi tree
 
Trees
TreesTrees
Trees
 
09 binary-trees
09 binary-trees09 binary-trees
09 binary-trees
 
Farhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructureFarhana shaikh webinar_treesindiscretestructure
Farhana shaikh webinar_treesindiscretestructure
 
Lec6
Lec6Lec6
Lec6
 
Binary tree traversal ppt - 02.03.2020
Binary tree traversal   ppt - 02.03.2020Binary tree traversal   ppt - 02.03.2020
Binary tree traversal ppt - 02.03.2020
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
 
Unit 8
Unit 8Unit 8
Unit 8
 
Data structures
Data structuresData structures
Data structures
 
AD3251-Data Structures Design-Notes-Tree.pdf
AD3251-Data Structures  Design-Notes-Tree.pdfAD3251-Data Structures  Design-Notes-Tree.pdf
AD3251-Data Structures Design-Notes-Tree.pdf
 
Binary tree
Binary treeBinary tree
Binary tree
 
DSA-Unit-2.pptx
DSA-Unit-2.pptxDSA-Unit-2.pptx
DSA-Unit-2.pptx
 
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptxLecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
 
Tree
TreeTree
Tree
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2
 
Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithms
 
Trees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and AlgorithmsTrees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and Algorithms
 
Dsc++ unit 3 notes
Dsc++ unit 3 notesDsc++ unit 3 notes
Dsc++ unit 3 notes
 
NON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptxNON-LINEAR DATA STRUCTURE-TREES.pptx
NON-LINEAR DATA STRUCTURE-TREES.pptx
 

Kürzlich hochgeladen

Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEaurabinda banchhor
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 

Kürzlich hochgeladen (20)

Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSE
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 

Discrete Mathematics Trees

  • 1. Discrete Mathematics NOR AIDAWATI BINTI ABDILLAH TREES 1
  • 2. Tree Definition 1. A tree is a connected undirected graph with no simple circuits. Theorem 1. An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices. 2
  • 3. Which graphs are trees? a) b) c) 3
  • 4. Is it a tree? NO! yes! All the nodes are yes! (but not not connected a binary tree) NO! There is a cycle yes! (it’s actually and an extra the same graph as edge (5 nodes the blue one) – but and 5 edges) usually we draw tree by its “levels”4
  • 5. Rooted Trees q Rooted tree is a tree in which one vertex is distinguished and called a root q Level of a vertex is the number of edges between the vertex and the root q The height of a rooted tree is the maximum level of any vertex q Children, siblings and parent vertices in a rooted tree q Ancestor, descendant relationship between vertices 5
  • 6. q The parent of a non-root vertex is the unique vertex u with a directed edge from u to v. q A vertex is called a leaf if it has no children. q The ancestors of a non-root vertex are all the vertices in the path from root to this vertex. q The descendants of vertex v are all the vertices that have v as an ancestor. q The level of vertex v in a rooted tree is the length of the unique path from the root to v. q The height of a rooted tree is the maximum of the 6 levels of its vertices.
  • 7. A Tree Has a Root root node a internal vertex parent of g b c d e f g leaf siblings h i 7
  • 8. a b c d e f g ancestors of h and i h i
  • 9. The level of a vertex v in a rooted tree is the length of the unique path from the root to this vertex. level 2 level 3
  • 10. a b c d e f g subtree with b as its h i root subtree with c as its root
  • 11. Tree Properties q There is one and only one path between every pair of vertices in a tree, T. q A tree with n vertices has n-1 edges. q Any connected graph with n vertices and n-1 edges is a tree. q A graph is a tree if and only if it is minimally connected. 11
  • 12. Tree Properties Theorem . There are at most 2 H leaves in a binary tree of height H. Corallary. If a binary tree with L leaves is full and balanced, then its height is H =  log2 L  . 12
  • 13. Properties of Trees There are at most mh leaves in an m-ary tree of height h. A rooted m-ary tree of height h is called balanced if all leaves are at levels h or h-1.
  • 14. Properties of Trees A full m-ary tree with (i) n vertices has i = (n-1)/m internal vertices and l = [(m-1)n+1]/m leaves. (ii) i internal vertices has n = mi + 1 vertices and l = (m-1)i + 1 leaves. (iii) l leaves has n = (ml - 1)/(m-1) vertices and i = (l-1)/(m-1) internal vertices.
  • 15. Properties of Trees A full m-ary tree with i internal vertices contains n = mi+1 vertices.
  • 16. Proof q We know n = mi+1 (previous theorem) and n = l+i, q n – no. vertices q i – no. internal vertices q l – no. leaves q For example, i = (n-1)/m
  • 17. Binary Tree A rooted tree in which each vertex has either no children, one child or two children. The tree is called a full binary tree if every internal vertex has exactly 2 children. A B C right child of A left subtree of A D E F G right subtree of H C 17 I J
  • 18. Ordered Binary Tree Definition 2’’. An ordered rooted tree is a rooted tree where the children of each internal vertex are ordered. In an ordered binary tree, the two possible children of a vertex are called the left child and the right child, if they exist. 18
  • 19. An Ordered Binary Tree A B E C K F G D L H M I J 19
  • 20. Is this binary tree balanced? A rooted binary tree of height Lou H is called balanced if all its leaves are at levels H or H-1. Hal Max Ed Ken Sue Joe Ted 20
  • 21. Searching takes time . . . So the goal in computer programs is to find any stored item efficiently when all stored items are ordered. A Binary Search Tree can be used to store items in its vertices. It enables efficient searches. 21
  • 22. A Binary Search Tree (BST) is . . . A special kind of binary tree in which: 1. Each vertex contains a distinct key value, 2. The key values in the tree can be compared using “greater than” and “less than”, and 3. The key value of each vertex in the tree is less than every key value in its right subtree, and greater than every key value in its left subtree.
  • 23. A Binary Expression Tree is . . . A special kind of binary tree in which: l Each leaf node contains a single operand, l Each nonleaf node contains a single binary operator, and l The left and right subtrees of an operator node represent subexpressions that must be evaluated before applying the operator at the root of the subtree. 23
  • 24. Expression Tree q Each node contains an operator or an operand q Operands are stored in leaf nodes q Parentheses are not stored (x + y)*((a + b)/c) in the tree because the tree structure dictates the order of operand evaluation q Operators in nodes at higher levels are evaluated after operators in nodes at lower levels 24
  • 25. A Binary Expression Tree ‘*’ ‘+’ ‘3’ ‘4’ ‘2’ What value does it have? ( 4 + 2 ) * 3 = 18 25
  • 26. A Binary Expression Tree ‘*’ ‘+’ ‘3’ ‘4’ ‘2’ Infix: ((4+2)*3) Prefix: * + 4 2 3 evaluate from right Postfix: 4 2 + 3 * evaluate from left 26
  • 27. Levels Indicate Precedence When a binary expression tree is used to represent an expression, the levels of the nodes in the tree indicate their relative precedence of evaluation. Operations at higher levels of the tree are evaluated later than those below them. The operation at the root is always the last operation performed. 27
  • 28. Evaluate this binary expression tree ‘*’ ‘-’ ‘/’ ‘8’ ‘5’ ‘+’ ‘3’ ‘4’ ‘2’ What expressions does it represent? 28
  • 29. A binary expression tree ‘*’ ‘-’ ‘/’ ‘8’ ‘5’ ‘+’ ‘3’ ‘4’ ‘2’ Infix: ((8-5)*((4+2)/3)) Prefix: *-85 /+423 evaluate from right Postfix: 85- 42+3/* evaluate from left 29
  • 30. Binary Tree for Expressions 30
  • 31. Complete Binary Tree Also be defined as a full binary tree in which all leaves are at depth n or n-1 for some n. In order for a tree to be the latter kind of complete binary tree, all the children on the last level must occupy the leftmost spots consecutively, with no spot left unoccupied in between any two A A B B C C D F G D E F G E H I J K L M N O H I 31 Complete binary tree Full binary tree of depth 4
  • 32. Difference between binary and complete binary tree BINARY TREE ISN'T NECESSARY THAT ALL OF LEAF NODE IN SAME LEVEL BUT COMPLETE BINARY TREE MUST HAVE ALL LEAF NODE IN SAME LEVEL. Binary Tree 32 Complete Binary Tree
  • 33. SPANNING TREES q A spanning tree of a connected graph G is a sub graph that is a tree and that includes every vertex of G. q A minimum spanning tree of a weighted graph is a spanning tree of least weight (the sum of the weights of all its edges is least among all spanning tree). q Think: “smallest set of edges needed to connect everything together” 33
  • 34. A graph G and three of its spanning tree We can delete any edge without deleting any vertex (to remove the cycle), but leave the graph connected. 34
  • 35. PRIM’S ALGORITHM q Choose any edge with smallest weight, putting it into the spanning tree. q Successively add to the tree edges of minimum weight that are incident to a vertex already in the tree and not forming a simple circuit with those edges already in the tree. q Stop when n – 1 edges have been added. 35
  • 36. EXAMPLE PRIM’S ALGORITHM Use Prim’s algorithm to find a minimum spanning tree in the weighted graph below: a 2 b 3 c 1 d 3 1 2 5 e 4 f 3 g 3 h 4 2 4 3 i 3 j 3 k 1 l 36
  • 37. SOLUTION Choice Edge Weight 1 {b, f} 1 a 2 b c 1 d 2 {a, b} 2 3 {f, j} 2 3 1 2 4 {a, e} 3 f 3 g 3 h 5 {i, j} 3 e 6 {f, g} 3 2 3 7 {c, g} 2 8 {c, d} 1 i j 9 {g, h} 3 3 k 1 l 10 {h, l} 3 11 {k, l} 1 Total: 24 37
  • 38. KRUSKAL’S ALGORITHM q Choose an edge in the graph with minimum weight. q Successively add edges with minimum weight that do not form a simple circuit with those edges already chosen. q Stop after n – 1 edges have been selected. 38
  • 39. Kruskal’s Algorithm q Pick the cheapest link (edge) available and mark it q Pick the next cheapest link available and mark it again q Continue picking and marking link that does not create the circuit ***Kruskal’s algorithm is efficient and optimal 39
  • 40. EXAMPLE KRUSKAL’S ALGORITHM Use Kruskal’s algorithm to find a minimum spanning tree in the weighted graph below: a 2 b 3 c 1 d 3 1 2 5 e 4 f 3 g 3 h 4 2 4 3 i 3 j 3 k 1 l 40
  • 41. SOLUTION Choice Edge Weight 1 {c, d} 1 2 {k, l} 1 a 2 b 3 c 1 d 3 {b, f} 1 4 {c, g} 2 3 1 2 5 {a, b} 2 f g 3 h 6 {f, j} 2 e 7 {b, c} 3 2 8 {j, k} 3 9 {g, h} 3 i j 3 10 {i, j} 3 3 k 1 l 11 {a, e} 3 Total: 24 41
  • 42. TRAVELLING SALESMAN PROBLEM (TSP) The goal of the Traveling Salesman Problem (TSP) is to find the “cheapest” tour of a select number of “cities” with the following restrictions: ● You must visit each city once and only once ● You must return to the original starting point 42
  • 43. TSP TSP is similar to these variations of Hamiltonian Circuit problems: ● Find the shortest Hamiltonian cycle in a weighted graph. ● Find the Hamiltonian cycle in a weighted graph with the minimal length of the longest edge. (bottleneck TSP). A route returning to the beginning is known as a Hamiltonian Circuit A route not returning to the beginning is known as a 43 Hamiltonian Path
  • 44. THANK YOU 44