trees n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Trees PowerPoint Presentation
Download Presentation
Trees

Loading in 2 Seconds...

play fullscreen
1 / 47

Trees - PowerPoint PPT Presentation


  • 108 Views
  • Uploaded on

Trees. Chapter 9. Tree. graph connected undirected no simple circuits (acyclic) no multiple edges no loops. Sample Trees?. Tree Tree Not Not. Theorem 1. An undirected graph is a tree iff A simple path exists in a tree between any two vertices. Root.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

Trees


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
trees

Trees

Chapter 9

slide2
Tree
  • graph
    • connected
    • undirected
    • no simple circuits (acyclic)
    • no multiple edges
    • no loops
sample trees
Sample Trees?

Tree Tree Not Not

theorem 1
Theorem 1
  • An undirected graph is a tree iff
    • A simple path exists in a tree
    • between any two vertices
slide5
Root
  • A particular tree vertex
    • from which we assign a direction to each edge
  • Each edge is directed away from the root
rooted tree
Rooted tree
  • A tree with a designated root
  • A directed graph
  • Direction of all edges is away from root
parent
Parent
  • In a rooted tree,
  • a parent of vertex v is
    • the unique vertex u
    • such that there is a directed edge from u to v
child
Child
  • The vertex v
  • to which a directed edge exists
  • from parent u in a rooted tree
siblings
Siblings
  • vertices with the same parent
slide10
Leaf
  • a vertex of a tree that has no children
ancestors of node a
Ancestors of node A
  • nodes located on the path
  • from A to the root
descendants of node a
Descendants of node A
  • nodes located on the path
  • from A to a leaf node
internal vertices
Internal vertices
  • Vertices with children
sub tree
Sub-tree
  • a tree
  • contained in a larger tree
  • whose root may be a child node
  • in the larger tree
m ary tree
m-ary tree
  • a rooted tree
  • with no more than m children per vertex
full m ary tree
Full m-ary tree
  • a rooted tree
  • whose every internal vertex
  • has exactly m children
theorem 2
Theorem 2
  • A tree with n vertices has n - 1 edges.

7 vertices

6 edges

theorem 3
Theorem 3
  • A full m-ary tree
  • with i internal vertices
  • contains n = mi + 1 vertices.

m = 2

i = 7

15 vertices

tree height
Tree Height
  • height (level) of a node
    • the length of the path from the root to a node
  • height of a tree
    • the length of the longest path in a tree
slide20
The maximum number of nodes at any level is mh
    • h is height of a node at that level of the tree

212223

slide21
The minimum number of nodes
  • of a tree of height h is
  • h+1
slide22
The maximum number of nodes
  • in a tree of height h is
  • m(h+1) -1
  • 2(3+1) - 1
balanced tree
Balanced tree
  • A rooted m-ary tree of height h
  • is called balanced
  • if all leaves are at level h or h - 1

YES

NO

YES

slide24
If an m-ary tree of height h
  • has l leaves,
  • and the tree is full and balanced,
  • h = ceil(log m l)
  • h = ceil (log28)
  • h = 3

What does this imply about access speed if a tree is used as a data structure?

binary search tree
Binary search tree
  • A binary tree where key value in any node is
    • greater than key of its left child
    • and any of its children
      • (the nodes in the left subtree)
    • less than key of its right child
    • and any of its children
      • (the nodes in the right subtree)
      • http://math.nemcc.edu/bst/
slide28
Form a BST with the words Mathematics, Physics, Geography, Zoology, Meteorology, Geology, Psychology, Chemistry
inorder tree traversal
Inorder Tree Traversal
    • process Left subtree inorder
    • Visit a node (or process node)
    • Process Right subtree inorder
  • Processes BST vertices in ascending sequence
  • http://nova.umuc.edu/~jarc/idsv/lesson1.html
inorder traversal example lvr
Inorder Traversal Example LVR

Arps, Dietz, Egofske, Fairchild, Garth, Huston, Keith

Magillicuddy, Nathan, Perkins, Seliger, Talbot,

Underwood,Verkins, Zarda

preorder tree traversal
Preorder Tree Traversal
  • allows quickest access to the whole tree
    • VISIT a node
    • process LEFT subtree in preorder
    • process RIGHT subtree in preorder
preorder traversal example vlr
Preorder Traversal Example VLR

Magillicuddy, Fairchild, Dietz, Arps, Egofske, Huston,

Garth, Keith, Talbot, Perkins, Nathan, Selinger, Verkins,

Underwood, Zarda

postorder tree traversal
Postorder Tree Traversal
  • good for deletion of nodes; postfix notation
    • process LEFT subtree in postorder
    • process RIGHT subtree in postorder
    • VISIT a node
postorder traversal example lrv
Postorder Traversal Example LRV

Arps, Egofske, Dietz, Garth, Keith, Huston, Fairchild,

Nathan, Selinger, Perkinds, Underwood, Zarda, Verkins,

Talbot, Magillicuddy

expression tree
Expression Tree
  • An ordered rooted tree
  • associates operands & operators in a uniform way

+

give pre in postorder
Give Pre, In, Postorder
  • PreOrder:
    • - + + * 6 2 7 * 8 3 / 6 7
  • InOrder:
    • 6 * 2 + 7 + 8 * 3 - 6 / 7
  • PostOrder:
    • 6 2 * 7 + 8 3 * + 6 7 / -

+

spanning subgraph
Spanning Subgraph
  • A spanning subgraph of G is
    • G’ = (V, E’)
    • where E’ is a subset of E
    • Note every vertex of G is included
spanning tree
Spanning Tree
  • A spanning subgraph that is a tree
    • connected
    • acyclic
      • See p. 581-2
depth first search
Depth First Search
  • A procedure for constructing a spanning tree
    • by adding edges that form a path until this is not possible
    • then moving back up the tree
    • until a vertex is found where a new path can be formed
    • http://www.cs.sunysb.edu/~skiena/combinatorica/animations/search.html
breadth first search
Breadth First Search
  • A procedure for constructing a spanning tree
    • that successively adds all edges incident to the last set of edges added
    • unless a simple circuit isformed
    • http://www.cs.duke.edu/~wcp/DFSanim.html
    • http://152.3.140.5/~wcp/DFSanim.html
perform dfs bfs search
Perform DFS, BFS search

DFS: a, b, c, d, e, f, g BFS: a b c g d e f

perform dfs bfs search1
Perform DFS, BFS search

DFS: a, b, c, d, e, f BFS: a b d e c f

minimum spanning tree
Minimum Spanning Tree
  • A connected weighted graph
  • is a spanning tree that has
  • the smallest possible sum of weights of its edges.
  • http://study.haifa.ac.il/~hvaiderm/sem3.html