2015-T2 Lecture 20 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,

Slides:



Advertisements
Similar presentations
COSC2007 Data Structures II Chapter 10 Trees I. 2 Topics Terminology.
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.
TREES Chapter 6. Trees - Introduction  All previous data organizations we've studied are linear—each element can have only one predecessor and successor.
2014-T2 Lecture 25 School of Engineering and Computer Science, Victoria University of Wellington  Lindsay Groves, Marcus Frean, Peter Andreae, and Thomas.
CS 171: Introduction to Computer Science II
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.
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.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
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.
Binary Trees Chapter 6.
CSC 205 Java Programming II Lecture 25 Binary Tree.
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
COMP 103 Introduction to Trees.
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary search trees.
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.
2014-T2 Lecture 24 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, and Thomas.
CS261 Data Structures Trees Introduction and Applications.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
2013-T2 Lecture 22 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, and Thomas.
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.
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.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, VUW B Trees and B+ Trees COMP 261.
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.
2011-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, and Peter Andreae, VUW.
2014-T2 Lecture 19 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, and John.
2013-T2 Lecture 18 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, and John.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
2015-T2 Lecture 17 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,
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.
24 January Trees CSE 2011 Winter Trees Linear access time of linked lists is prohibitive  Does there exist any simple data structure for.
2014-T2 Lecture 29 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae and Thomas.
2015-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, and Thomas.
2014-T2 Lecture 27 School of Engineering and Computer Science, Victoria University of Wellington  Lindsay Groves, Marcus Frean, Peter Andreae, and Thomas.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
2015-T2 Lecture 19 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, and John.
2014-T2 Lecture 18 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, and John.
Chapter 6 – Trees. Notice that in a tree, there is exactly one path from the root to each node.
18-1 Chapter 18 Binary Trees Data Structures and Design in Java © Rick Mercer.
2015-T2 Lecture 28 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae and Thomas.
Trees A non-linear implementation for collection classes.
(c) University of Washington20-1 CSC 143 Java Trees.
COMP 103 Binary Search Trees II Marcus Frean 2014-T2 Lecture 26
CSE 373 Data Structures Lecture 7
Data Structures and Design in Java © Rick Mercer
CC 215 Data Structures Trees
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Fundamentals of Programming II Introduction to Trees
COMP 103 Introduction to Trees Thomas Kuehne 2013-T2 Lecture 19
COMP 103 Tree Traversals Lindsay Groves 2016-T2 Lecture 22
COMP 103 Sorting with Binary Trees: Tree sort, Heap sort Alex Potanin
COMP 103 HeapSort Thomas Kuehne 2013-T1 Lecture 27
CSE 373 Data Structures Lecture 7
Binary Search Trees (I)
More complexity analysis & Binary Search
Depth-first vs breadth-first traversals
Tonga Institute of Higher Education
Trees and Binary Trees.
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Copyright ©2012 by Pearson Education, Inc. All rights reserved
CSC 143 Java Trees.
Cs212: Data Structures Lecture 7: Tree_Part1
Presentation transcript:

2015-T2 Lecture 20 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis, and Thomas Kuehne, VUW COMP 103 Thomas Kuehne Introduction to Trees

2 RECAP  Used linked lists to implement linear data structures  Efficiency issues still remain TODAY  Introduction to Trees  Reading: Chapter 16 in textbook

3 Remaining Efficiency Challenge  Linear Linked Structures (LinkedList, LinkedStack, … )  adding / removal operations are O(1)   but random access is expensive   Why?  reducing a search or access problem by 1 and leaving a subproblem of size n-1 is not a good divide & conquer strategy  This is why a naïve QuickSort implementation can be slow (O(n 2 ) in the worst case)

4 Divide & Conquer  Challenge  Guess the secret animal with as few questions as possible  Strategy  eliminate as many as possible in each step Toby Tiger Lea Lion Bully Bulldog Carrie Collie Tanja Tui Kurt Kaka Tim Turtle Sally Snake Egg Laying Mammal Reptile Bird 

5 Divide & Conquer  Linear access is slow  only one candidate eliminated at a time Toby Tiger Lea Lion Bully Bulldog Carrie Collie Tanja Tui Kurt Kaka Tim Turtle Sally Snake

6 Divide & Conquer  Linear access is slow  only one candidate eliminated at a time  Hierarchical access is fast  many (proportional to total amount) eliminated at a time Toby Tiger Lea Lion Bully Bulldog Carrie Collie Tanja Tui Kurt Kaka Tim Turtle Sally Snake Egg Laying Mammal Reptile Feline Canine Bird

7 From Linear to Hierarchical Access  Linear linkage  structure split into one head and the rest Toby Tiger Lea Lion Bully Bulldog Carrie Collie Tanja Tui Kurt Kaka Tim Turtle Sally Snake

8 From Linear to Hierarchical Access  Hierarchical linkage  structure split into parts, each containing multiple elements Toby Tiger Lea Lion Bully Bulldog Carrie Collie Tanja Tui Kurt Kaka Tim Turtle Sally Snake Egg Laying Mammal Reptile Feline Canine Bird Animal

9 From Linear to Hierarchical Access  Hierarchical linkage  structure split into parts, each containing multiple elements Toby Tiger Lea Lion Bully Bulldog Carrie Collie Tanja Tui Kurt Kaka Tim Turtle Sally Snake Egg Laying Mammal Reptile Feline Canine Bird Animal

10 Trees are Hierarchical Structures  Upside Down Trees? Feline Leo Lion Toby Tiger Bully Bulldog Carrie Collie Tanja Tui Kurt Kaka Tim Turtle Sally Snake Egg Laying Mammal Reptile Canine Bird Animal

11  Some Terminology Trees are Hierarchical Structures Feline Leo Lion Toby Tiger Bully Bulldog Carrie Collie Tanja Tui Kurt Kaka Tim Turtle Sally Snake Egg Laying Mammal Reptile Canine Bird Animal root leaves branch

12 Trees are Hierarchical Structures  Same Terminology, despite different orientation Feline Leo Lion Toby Tiger Bully Bulldog Carrie Collie Tanja Tui Kurt Kaka Tim Turtle Sally Snake Egg Laying Mammal Reptile Canine Bird Animal root leaves branch  Implementation with LinkedNode++  support multiple successors, instead of just one

13 Feline Leo Lion Toby Tiger Bully Bulldog Carrie Collie Tanja Tui Kurt Kaka Tim Turtle Sally Snake Egg Laying Mammal Reptile Canine Bird Animal Implementation as a Linked Structure  Implementation with LinkedNode++  support multiple successors, instead of just one

14  Generalised LinkedNode Representing trees in Java M Linked List Nodes FC

15  Generalised LinkedNode Representing trees in Java Binary Tree Nodes M FCTL

16  Generalised LinkedNode Representing trees in Java General Tree Nodes F … … … C … … … M … … … T … … … L … … … some collection type (ordered or unordered)

17  Arrays  It is possible to represent trees with arrays  No reference overhead!  Clever assignment of nodes to array indeces  We’ll probably won’t cover this (outside heaps)  Textbook → Ch Representing trees in Java

18 More Tree Examples  Other Taxonomies  e.g. game genres  Organisational Charts  CEO, managers, employees, slaves, …  Filing systems  e.g., the folder structure of your hard drive  Computer Graphics models   Octrees, for partitioning 3D space hierarchical structures naturally represented with trees (rather than using trees as an access technique) hierarchical structures naturally represented with trees (rather than using trees as an access technique)

19  Other Taxonomies  e.g. game genres  Organisational Charts  CEO, managers, employees, slaves, …  Filing systems  e.g., the folder structure of your hard drive  Computer Graphics models   Octrees, for partitioning 3D space More Tree Examples

20 More Tree Examples  Other Taxonomies  e.g. game genres  Organisational Charts  CEO, managers, employees, slaves, …  Filing systems  e.g., the folder structure of your hard drive  Computer Graphics models   Octrees, for partitioning 3D space  Decision processes ……

21 Planning  Tic Tac Toe  search tree for moves XXX XXX … OXOXX O X O X O X O … often not represented explicitly; only implicitly “created” by recursion

22 More Tree Terminology  A tree is a collection of items in a strict hierarchical structure.  Each item is in a node of the tree.  The root is at the top.  The leaves are at the bottom.  Each node may have child nodes – except a leaf, which has none.  Each node has one parent - except the root, which has none.  An edge joins a node to its parent – may be labelled.  A subtree is a node plus all its descendents.  The depth of a node is its distance from the root.  The height or depth of a tree is the depth of the lowest leaf.  Level = set/list of nodes at the same depth.  Branch = sequence of nodes on a path from root to a leaf. Children may be ordered/unordered Tree may or may not store explicit parent references

23 Terminology visualised K K G G C C I I M M Q Q O O A A E E node, root, leaf, child, parent, edge, subtree, depth, height, level, branch, siblings, ancestors, descendants, cousins, …