Trees CS 105. L9: Trees Slide 2 Definition The Tree Data Structure stores objects (nodes) hierarchically nodes have parent-child relationships operations.

Slides:



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

Introduction to Trees Chapter 6 Objectives
TREES Chapter 6. Trees - Introduction  All previous data organizations we've studied are linear—each element can have only one predecessor and successor.
Binary Trees CS 110: Data Structures and Algorithms First Semester,
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
Trees Chapter 8.
ITEC200 – Week08 Trees. 2 Chapter Objectives Students can: Describe the Tree abstract data type and use tree terminology such as.
Data Structures: Trees i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
Fall 2007CS 2251 Trees Chapter 8. Fall 2007CS 2252 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
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.
© 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.
1 Chapter 7 Trees. 2 What is a Tree In computer science, a tree is an abstract model of a hierarchical structure A tree consists of nodes with a parent-child.
Trees CMSC 433 Chapter 8.1 Nelson Padua-Perez Bill Pugh.
1 Trees What is a Tree? Tree terminology Why trees? General Trees and their implementation N-ary Trees N-ary Trees implementation Implementing trees Binary.
Binary Trees Chapter 6.
Trees CS /02/05 L7: Trees Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Definition.
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.
COSC2007 Data Structures II
Trees. Tree Terminology Chapter 8: Trees 2 A tree consists of a collection of elements or nodes, with each node linked to its successors The node at the.
CS Data Structures Chapter 15 Trees Mehmet H Gunes
Saturday, 04 Apr 2010 University of Palestine Computer Science II Trees.
Trees Chapter 8. Chapter 8: Trees2 Chapter Objectives To learn how to use a tree to represent a hierarchical organization of information To learn how.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
COMP20010: Algorithms and Imperative Programming Lecture 1 Trees.
Tree Data Structures.
Binary Trees PS4 due 1:30pm Tuesday, April 10 Wellesley College CS230 Lecture 17 Thursday, April 5 Handout #28.
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.
Lecture11: Tree I Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
CS-2852 Data Structures LECTURE 11 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Data Structures TREES.
CSE 326: Data Structures Lecture #6 From Lists to Trees Henry Kautz Winter 2002.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
Data Structure II So Pak Yeung Outline Review  Array  Sorted Array  Linked List Binary Search Tree Heap Hash Table.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 6.
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.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
24 January Trees CSE 2011 Winter Trees Linear access time of linked lists is prohibitive  Does there exist any simple data structure for.
Data Structures Lakshmish Ramaswamy. Tree Hierarchical data structure Several real-world systems have hierarchical concepts –Physical and biological systems.
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.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
18-1 Chapter 18 Binary Trees Data Structures and Design in Java © Rick Mercer.
CSC 213 – Large Scale Programming. Trees  Represent hierarchical relationships  Parent-child basis of this abstract data type  Real-world example:
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.
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Fundamentals of Programming II Introduction to Trees
Binary search tree. Removing a node
University of Palestine
CISC220 Fall 2009 James Atlas Lecture 13: Binary Trees.
Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb.
Section 8.1 Trees.
Trees What is a Tree? Tree terminology Why trees?
Binary Trees, Binary Search Trees
Trees and Binary Trees.
Trees.
Trees (Part 1, Theoretical)
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Binary Trees, Binary Search Trees
Tree and its terminologies
Binary Trees, Binary Search Trees
Cs212: Data Structures Lecture 7: Tree_Part1
Presentation transcript:

Trees CS 105

L9: Trees Slide 2 Definition The Tree Data Structure stores objects (nodes) hierarchically nodes have parent-child relationships operations include accessing the parent or children of a given node A tree T is a set of nodes such that there is a distinguished node r (called the root) of T that has no parent each node v of T except r has a parent node

L9: Trees Slide 3 Visualizing a Tree N AP T M I O R G Root Child

L9: Trees Slide 4 Sample Uses A company’s organizational structure Family tree The Java class hierarchy O/S directory structure Book (parts, chapters, sections) Arithmetic expressions Web page links Priority queues and search trees

L9: Trees Slide 5 Tree Terminology Root the only node that has no parent Leaf (External node) node that has no children Internal node node that has at least one child Siblings nodes that have a common parent

L9: Trees Slide 6 More Tree Terminology Ancestor recursive definition: ancestors of a node v are v itself and the ancestors of its parent proper ancestors: ancestors excluding itself Descendant v is a descendant of u if u is an ancestor of v Subtree of T rooted at v set of all descendants of v

L9: Trees Slide 7 Even More Terminology Ordered Tree children of a node have a strict linear order Binary Tree an ordered tree where nodes have at most two children (left and right) Depth and Height of a node depth: distance from node to root height: from node to its farthest descendant

L9: Trees Slide 8 Tree Implementations Array-based implementation elements (or references to them) are stored in an array parent-child relationships derived from indices Linked implementation elements stored in nodes nodes contain pointers to parent and children

L9: Trees Slide 9 Tree Operations Get the root node of the tree Go to parent or children from a given node Add a root to an empty tree Add a child to a node Remove a node (can impose that the node be a leaf, for simplicity) Get the element associated to a node Replace the element associated to a node Others …

L9: Trees Slide 10 Binary Tree operations For a binary tree, a node has at most two children and are ordered Could distinguish between the left and right child of a node Implementations are simpler for binary trees but many concepts apply to general trees

L9: Trees Slide 11 Implementing trees Array implementation Array indices are used to navigate from parent to children or from children to parent Node implementation Node contains data and references to children and parent

L9: Trees Slide 12 Data structures that use trees Priority queues Heap: tree structure (usually array-based) where the hierarchy imply the priorities of the elements Dictionary Binary Search Tree: tree structure (usually node-based) that facilitates “binary search” of the nodes