COMP 103 Introduction to Trees Thomas Kuehne 2013-T2 Lecture 19

Slides:



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

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.
EC-211 DATA STRUCTURES LECTURE Tree Data Structure Introduction –The Data Organizations Presented Earlier are Linear in That Items are One After.
Data Structures: Trees i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
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
B+ Trees COMP
COMP 103 Introduction to 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,
2013-T2 Lecture 22 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, and Thomas.
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.
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.
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.
2015-T2 Lecture 20 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,
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.
2015-T2 Lecture 28 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae and Thomas.
COMP 103 Binary Search Trees II Marcus Frean 2014-T2 Lecture 26
CSE 373 Data Structures Lecture 7
COMP261 Lecture 23 B Trees.
ADT description Implementations
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 Linked Structures Marcus Frean 2014-T2 Lecture 17
COMP 103 Tree Traversals Lindsay Groves 2016-T2 Lecture 22
Objective: Understand Concepts related to trees.
Lecture 18. Basics and types of Trees
COMP 103 SORTING Lindsay Groves 2016-T2 Lecture 26
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
i206: Lecture 13: Recursion, continued Trees
Trees and Binary Trees.
Trees CSE 373 Data Structures.
Week nine-ten: Trees Trees.
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Trees.
CS 261 – Data Structures Trees.
CSC 143 Java Trees.
CS210- Lecture 9 June 20, 2005 Announcements
Tree and its terminologies
Trees CSE 373 Data Structures.
Heaps Chapter 6 Section 6.9.
Cs212: Data Structures Lecture 7: Tree_Part1
Presentation transcript:

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

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

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(n2) in the worst case)

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

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

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

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

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

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

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

Trees are Hierarchical Structures Some Terminology leaves 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 branch

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

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

Representing trees in Java Generalised LinkedNode Linked List Nodes M F C

Representing trees in Java Generalised LinkedNode Binary Tree Nodes M F C T L

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

Representing trees in Java 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 Textbook → Ch. 16.3

More Tree Examples Other Taxonomies Organisational Charts 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 Other Taxonomies Organisational Charts 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 Other Taxonomies Organisational Charts 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 …

Planning Tic Tac Toe search tree for moves X … O X …

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.

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