Class 8: Trees. cis 335 Fall 2001 Barry Cohen Definitions n A tree is a nonlinear hierarchical structure (more than one successor) n Consists of nodes.

Slides:



Advertisements
Similar presentations
COSC2007 Data Structures II Chapter 10 Trees I. 2 Topics Terminology.
Advertisements

CS Fall 2012, Lab 08 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /17/2015 Tree - Data Structure  Basic.
Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
Introduction to Trees Chapter 6 Objectives
Binary Search Trees. John Edgar  Understand tree terminology  Understand and implement tree traversals  Define the binary search tree property  Implement.
TREES Chapter 6. Trees - Introduction  All previous data organizations we've studied are linear—each element can have only one predecessor and successor.
EC-211 DATA STRUCTURES LECTURE Tree Data Structure Introduction –The Data Organizations Presented Earlier are Linear in That Items are One After.
Binary Tree Terminology Linear versus hierarchical data Tree – connected graph with no cycles Child Parent Descendant Sibling Ancestor Leaf vs. internal.
1 Introduction to Binary Trees. 2 Background All data structures examined so far are linear data structures. Each element in a linear data structure has.
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.
Class 9: Review. cis 335 Fall 2001 Barry Cohen Big O Complexity n Complexity of problem, complexity of algorithm (Sum (n)) n Intuition: worst case rate.
Trees Chapter 25 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
2/10/03Tucker, Sec Tucker, Applied Combinatorics, Sec. 3.2, Important Definitions Enumeration: Finding all of the possible paths in a rooted tree.
Trees and Tree Traversals Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
Chapter 11 A Trees. © 2004 Pearson Addison-Wesley. All rights reserved 11 A-2 Terminology A tree consists of vertices and edges, –An edge connects to.
Trees & Graphs Chapter 25 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
CS Data Structures Chapter 15 Trees Mehmet H Gunes
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 10: Trees Data Abstraction & Problem Solving with C++
CISC220 Fall 2009 James Atlas Lecture 13: Trees. Skip Lists.
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.
Binary Trees 2 Overview Trees. Terminology. Traversal of Binary Trees. Expression Trees. Binary Search Trees.
Tree (new ADT) Terminology:  A tree is a collection of elements (nodes)  Each node may have 0 or more successors (called children)  How many does a.
Compiled by: Dr. Mohammad Omar Alhawarat
Trees Chapter 8. 2 Tree Terminology A tree consists of a collection of elements or nodes, organized hierarchically. The node at the top of a tree is called.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
CS-2852 Data Structures LECTURE 11 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 6.
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.
Trees By P.Naga Srinivasu M.tech,(MBA). Basic Tree Concepts A tree consists of finite set of elements, called nodes, and a finite set of directed lines.
Discrete Mathematics Chapter 5 Trees.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
DATA STRUCTURE BS(IT)3rd. Tree An Introduction By Yasir Mustafa Roll No. BS(IT) Bahauddin Zakariya University, Multan.
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.
Data Structures Lakshmish Ramaswamy. Tree Hierarchical data structure Several real-world systems have hierarchical concepts –Physical and biological systems.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
1 Trees General Trees  Nonrecursive definition: a tree consists of a set of nodes and a set of directed edges that connect pairs of nodes.
This Lecture Intro to Tree ADT Terminologies Tree Types Tree Traversals Binary Search Tree Expression Trees.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
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.
TREES From root to leaf. Trees  A tree is a non-linear collection  The elements are in a hierarchical arrangement  The elements are not accessible.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
Trees Chapter 15.
CSCE 210 Data Structures and Algorithms
Fundamentals of Programming II Introduction to Trees
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Tree.
Section 8.1 Trees.
Data Structures & Algorithm Design
Lecture 18. Basics and types of Trees
Ch. 11 Trees 사실을 많이 아는 것 보다는 이론적 틀이 중요하고, 기억력보다는 생각하는 법이 더 중요하다.
CS223 Advanced Data Structures and Algorithms
Introduction to Trees IT12112 Lecture 05.
Trees Definitions Implementation Traversals K-ary Trees
CSE 373, Copyright S. Tanimoto, 2002 Binary Trees -
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Trees.
CSE 373, Copyright S. Tanimoto, 2001 Binary Trees -
Chapter 20: Binary Trees.
Trees.
Presentation transcript:

Class 8: Trees

cis 335 Fall 2001 Barry Cohen Definitions n A tree is a nonlinear hierarchical structure (more than one successor) n Consists of nodes (vertices) and edges n Parent, child and sibling relations parent left child right child

cis 335 Fall 2001 Barry Cohen Not all hierarchies are trees n A tree must satisfy these conditions: * At most one node -- the root -- has no ancestor * Every other node has exactly one parent n Each edge has a direction (from parent to child) n A parent may have multiple children n Therefore, a tree is connected

cis 335 Fall 2001 Barry Cohen More definitions n Root -- node with no parent n Leaf -- node with no children n Ancestor, descendant -- generalization of parent-child relationship n Subtree -- a node and its descendants n Binary tree -- each node has 0, 1 or 2 children

cis 335 Fall 2001 Barry Cohen Things which are not trees n Directed acyclic graph (dag). Node may have multiple parents.

cis 335 Fall 2001 Barry Cohen Geneological trees n Can the family’s parent-child relation be the same as the tree’s? Why (or why not)? n Can the family parent-child relation be inverted? Why or why not? n What about the matrilineal line? n Other hierarchical relations? Organization chart. Algebraic expression.

cis 335 Fall 2001 Barry Cohen Height and level n Height -- number of nodes on longest path n Level -- number of nodes on path to root n Full binary tree -- every leaf on same level n If there are n nodes in a full binary tree, now many levels are there?

cis 335 Fall 2001 Barry Cohen Binary search tree n Each node has a value n Each node has value greater than its left child n Each node has a value less than its right child

cis 335 Fall 2001 Barry Cohen Binary tree ops n createBT() n destroyBT() n bool isEmpty() n btType getRootData() n setRootData(item:btType) n attachLeft(item:btType) n attachRight(item:btType) n attachLeftTree(item:bt) n attachRightTree(item:bt) n bt detachLeftTree() n bt detachRightTree()

cis 335 Fall 2001 Barry Cohen Preorder traversal Preorder(binTree:BinaryTree) if (binTree not empty) { visit root preorder(left subtree) preorder(right subtree) }

cis 335 Fall 2001 Barry Cohen Inorder traversal Inorder(binTree:BinaryTree) if (binTree not empty) { inorder(left subtree) visit root inorder(right subtree) }

cis 335 Fall 2001 Barry Cohen Postorder traversal Postorder(binTree:BinaryTr ee) if (binTree not empty) { postorder(left subtree) postorder(right subtree) visit root }