Trees. Introduction to Trees Trees are very common in computer science They come in different forms They are used as data representation in many applications.

Slides:



Advertisements
Similar presentations
Trees Chapter 11.
Advertisements

Introduction to Trees Chapter 6 Objectives
Data Structures: A Pseudocode Approach with C 1 Chapter 6 Objectives Upon completion you will be able to: Understand and use basic tree terminology and.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
1 Chapter 10 Trees. Tree Definition 1. A tree is a connected undirected graph with no simple circuits. Theorem 1. An undirected graph is a tree if and.
EC-211 DATA STRUCTURES LECTURE Tree Data Structure Introduction –The Data Organizations Presented Earlier are Linear in That Items are One After.
1 Section 9.1 Introduction to Trees. 2 Tree terminology Tree: a connected, undirected graph that contains no simple circuits –must be a simple graph:
Chapter 4: Trees General Tree Concepts Binary Trees Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Trees Chapter 25 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Trees Chapter 23 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
Binary and Other Trees CSE, POSTECH. 2 2 Linear Lists and Trees Linear lists are useful for serially ordered data – (e 1,e 2,e 3,…,e n ) – Days of week.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Trees.
Binary Trees Chapter 6.
COSC2007 Data Structures II
Tree.
Trees & Graphs Chapter 25 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
CS Data Structures Chapter 15 Trees Mehmet H Gunes
Trees Nature Lover’s View Of A Tree root branches leaves.
© University of Auckland Trees CS 220 Data Structures & Algorithms Dr. Ian Watson.
CS261 Data Structures Trees Introduction and Applications.
Introduction Of Tree. Introduction A tree is a non-linear data structure in which items are arranged in sequence. It is used to represent hierarchical.
Lecture 81 Data Structures, Algorithms & Complexity Tree Algorithms GRIFFITH COLLEGE DUBLIN.
Section 10.1 Introduction to Trees These class notes are based on material from our textbook, Discrete Mathematics and Its Applications, 6 th ed., by Kenneth.
Tree A connected graph that contains no simple circuits is called a tree. Because a tree cannot have a simple circuit, a tree cannot contain multiple.
Trees and Graphs CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Binary Trees. Binary Tree Finite (possibly empty) collection of elements A nonempty binary tree has a root element The remaining elements (if any) are.
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
1 Binary Trees Informal defn: each node has 0, 1, or 2 children Informal defn: each node has 0, 1, or 2 children Formal defn: a binary tree is a structure.
Compiled by: Dr. Mohammad Omar Alhawarat
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
TREES. What is a tree ? An Abstract Data Type which emulates a tree structure with a set of linked nodes The nodes within a tree are organized in a hierarchical.
Trees CS 105. L9: Trees Slide 2 Definition The Tree Data Structure stores objects (nodes) hierarchically nodes have parent-child relationships operations.
Data Structures TREES.
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Introduction to Trees IT12112 Lecture 05 Introduction Tree is one of the most important non-linear data structures in computing. It allows us to implement.
Discrete Mathematics Chapter 5 Trees.
1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
CH 7. TREES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY.
Chapter 10: Trees A tree is a connected simple undirected graph with no simple circuits. Properties: There is a unique simple path between any 2 of its.
1 Trees What is a Tree? Tree terminology Why trees? What is a general tree? Implementing trees Binary trees Binary tree implementation Application of Binary.
Graphs and Trees Mathematical Structures for Computer Science Chapter 5 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesGraphs and Trees.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
TREES General trees Binary trees Binary search trees AVL trees Balanced and Threaded trees.
18-1 Chapter 18 Binary Trees Data Structures and Design in Java © Rick Mercer.
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
Tree Representation and Terminology Binary Trees Binary Search Trees Pointer-Based Representation of a Binary Tree Array-Based Representation of a Binary.
What is a Tree? Formally, we define a tree T as a set of nodes storing elements such that the nodes have a parent-child relationship, that satisfies the.
Data Structures and Design in Java © Rick Mercer
CSCE 210 Data Structures and Algorithms
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Fundamentals of Programming II Introduction to Trees
CHAPTER 4 Trees.
Trees Trees are a very useful data structure. Many different kinds of trees are used in Computer Science. We shall study just a few of these.
TREES General trees Binary trees Binary search trees AVL trees
Introduction to Trees IT12112 Lecture 05.
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Trees Slides are adopted from “Discrete.
Week nine-ten: Trees Trees.
Trees.
Trees 11.1 Introduction to Trees Dr. Halimah Alshehri.
Trees Trees are a very useful data structure. Many different kinds of trees are used in Computer Science. We shall study just a few of these.
Cs212: Data Structures Lecture 7: Tree_Part1
Presentation transcript:

Trees

Introduction to Trees Trees are very common in computer science They come in different forms They are used as data representation in many applications They appear frequently in several algorithmic solutions There are several different types of trees Binary Trees Binary Search Trees AVL Trees 2-3 Trees Red-Black Trees

Trees as tool for abstraction We often use trees in our everyday lives To keep track of our ancestors: a family tree Most of the terminology used in trees in computer science here To organize sport events: a tennis draw When describing the organization of a company: a company chart Organization of files in a computer: a directory structure In here we want to concentrate on trees as tools for the implementation of computer programs: trees as abstract data structures

Understanding the terminology One thing about studying trees (an graphs for that matter) is that there are several concepts that must be learned. Here is just a few definitions A tree is a non-empty collection of vertices (or nodes) and edges (or arcs) which carry some properties A vertex is an object that has a name or has some information associated with it An edge is a connection between two vertices which can also have some information associated with it A path is a sequence of adjacent of vertices connected by edges

A tree

Vertices

Edges

A path

Trees, Paths and Forests The main property of a tree is based on paths In a tree there is exactly one path between any two nodes If there exist more than one path between any pair or nodes or if there is no path between any of them we do not have a tree A disjoint set of trees is called a forest

Rooted Trees A rooted tree is a tree where one node is "special" and is called the root of the tree A tree where there is no root is called a free tree Rooted trees are the most common in computer applications, so common that we'll use the term tree as a synonym for rooted tree A rooted treea free tree

A subtree root of subtree Trees and subtrees In a rooted tree, any node is a root of a subtree consisting of itself and the nodes "below" it By definition there is only one path between the root and each of the other nodes. Because a root is also a node the main property applies The convention used in computer science is that roots are drawn on the top. It may seem strange at the beginning but you'll get used to it Root

More conventions Due to the fact that we organize trees with root at the top (as shown in previous slide) we will often hear Node A is below node B Node C is above node A etc. In fact, the most common way to refer to nodes based on another node is use the idea of a family tree Parent node Children Siblings etc

Another Important Characteristic Another characteristic of a tree which is that every node (except the root) has only one node immediately above it (one parent) but can have several immediately below (children) node parent children

Leaves Nodes that have no children are called leaves (or terminal) nodes Node with at least one child are called non-terminal Leaves

Tress with specific number of children It is possible that the order in which children are defined is important. We call these trees ordered trees Sometimes a node must have a maximum number of children. If a for the whole tree the maximum number of children nodes can have is M and this tree is ordered we have a M-ary tree. A binary tree is a special case of a M-ary tree where all nodes (except the leaves) have at most 2 children. Because the tree is ordered the children have a order and they are normally referred to as left and right child

Linear Lists And Trees Linear lists are useful for serially ordered data. (e 0, e 1, e 2, …, e n-1 ) Days of week Months in a year Students in this class Trees are useful for hierarchically ordered data Employees of a corporation President, vice presidents, managers, and so on Java’s classes Object is at the top of the hierarchy Subclasses of Object are next, and so on

Hierarchical Data And Trees The element at the top of the hierarchy is the root Elements next in the hierarchy are the children of the root Elements next in the hierarchy are the grandchildren of the root, and so on Elements at the lowest level of the hierarchy are the leaves

Tree applications Expression evaluations (note how different traversals result in different notation) Parsing (as part of the compilation process) Storing and retrieving information by a key Representing structured objects (e.g. the universe in an adventure game) Useful when needing to make a decision on how to proceed (tic-tac-toe, chess)

19 Jake’s Pizza Shop Owner Manager Chef Delivery Delivery Waiter Waiter Cook Cook Joe Tim Max Ted Len Dale

20 A Tree Has a Root Node Owner Manager Chef Delivery Delivery Waiter Waiter Cook Cook Joe Tim Max Ted Len Dale ROOT NODE

21 Leaf nodes have no children Owner Manager Chef Delivery Delivery Waiter Waiter Cook Cook Joe Tim Max Ted Len Dale LEAF NODES

22 Sibling nodes have same parent Owner Manager Chef Delivery Delivery Waiter Waiter Cook Cook Joe Tim Max Ted Len Dale SIBLINGS

23 Tree Terminology Owner Manager Chef Delivery Delivery Waiter Waiter Cook Cook Joe Tim Max Ted Len Dale SIBLINGS

24 Tree Terminology Owner Manager Chef Delivery Delivery Waiter Waiter Cook Cook Joe Tim Max Ted Len Dale SIBLINGS

25 A Tree Has Levels Owner Manager Chef Delivery Delivery Waiter Waiter Cook Cook Joe Tim Max Ted Len Dale LEVEL #1

26 Level Two Owner Manager Chef Delivery Delivery Waiter Waiter Cook Cook Joe Tim Max Ted Len Dale LEVEL #2

27 Level Three Owner Manager Chef Delivery Delivery Waiter Waiter Cook Cook Joe Tim Max Ted Len Dale LEVEL #3

28 A Subtree Owner Manager Chef Delivery Delivery Waiter Waiter Cook Cook Joe Tim Max Ted Len Dale A SUBTREE OF ROOT NODE

29 Another Subtree Owner Manager Chef Delivery Delivery Waiter Waiter Cook Cook Joe Tim Max Ted Len Dale ANOTHER SUBTREE OF ROOT NODE