SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

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
 
Graph data structure and algorithms
Graph data structure and algorithmsGraph data structure and algorithms
Graph data structure and algorithms
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
 
Discrete-Chapter 10 Trees
Discrete-Chapter 10 TreesDiscrete-Chapter 10 Trees
Discrete-Chapter 10 Trees
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Trees and graphs
Trees and graphsTrees and graphs
Trees and graphs
 
Graphs - Discrete Math
Graphs - Discrete MathGraphs - Discrete Math
Graphs - Discrete Math
 
Tree and binary tree
Tree and binary treeTree and binary tree
Tree and binary tree
 
Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Introduction to tree ds
Introduction to tree dsIntroduction to tree ds
Introduction to tree ds
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Data Structure: TREES
Data Structure: TREESData Structure: TREES
Data Structure: TREES
 
Binary tree
Binary tree Binary tree
Binary tree
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
introduction to_trees
introduction to_treesintroduction to_trees
introduction to_trees
 

Destaque

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
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentationAlizay Khan
 

Destaque (15)

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
 
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
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
 

Semelhante a Discrete Mathematics Trees

Semelhante a 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.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
 
non linear data structure -introduction of tree
non linear data structure -introduction of treenon linear data structure -introduction of tree
non linear data structure -introduction of 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
 

Último

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Último (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

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