Problem of the Day  You drive a bus from Rotterdam to Delft.  At the 1 st stop, 33 people get in.  At the 2 nd stop, 7 add people & 11 passengers leave.

Slides:



Advertisements
Similar presentations
Introduction to Trees Chapter 6 Objectives
Advertisements

Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
CS 171: Introduction to Computer Science II
ITEC200 – Week08 Trees. 2 Chapter Objectives Students can: Describe the Tree abstract data type and use tree terminology such as.
Department of Computer Science University of Maryland, College Park
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
© 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.
CS 261 – Winter 2010 Trees. Ubiquitous – they are everywhere in CS Probably ranks third among the most used data structure: 1.Vectors and Arrays 2.Lists.
Trees CMSC 433 Chapter 8.1 Nelson Padua-Perez Bill Pugh.
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.
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Introduction to trees.
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.
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
Saturday, 04 Apr 2010 University of Palestine Computer Science II Trees.
Trees CSC 172 SPRING 2002 LECTURE 14. Lists We have seen lists: public class Node { Object data; Node next; } 
Binary Trees. Binary Tree Finite (possibly empty) collection of elements A nonempty binary tree has a root element The remaining elements (if any) are.
Problem of the Day  The place where they signed the Declaration of Independence has the same name now as it did then. What is it?
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.
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.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
Problem of the Day  Solve this equation by moving the numbers: 76 = 24.
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
CSC 212 Trees & Recursion. Announcements Midterm grades were generally good  Wide distributions of scores, however  Will hand back at end of class 
CSC 213 – Large Scale Programming Lecture 10: Tree & Binary Tree Implementation.
CSS446 Spring 2014 Nan Wang.  to study trees and binary trees  to understand how binary search trees can implement sets  to learn how red-black trees.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
Rooted Tree a b d ef i j g h c k root parent node (self) child descendent leaf (no children) e, i, k, g, h are leaves internal node (not a leaf) sibling.
CIS 068 Welcome to CIS 068 ! Lesson 12: Data Structures 3 Trees.
24 January Trees CSE 2011 Winter Trees Linear access time of linked lists is prohibitive  Does there exist any simple data structure for.
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Symbol tables.
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.
TREES General trees Binary trees Binary search trees AVL trees Balanced and Threaded trees.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
Trees CSIT 402 Data Structures II 1. 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical.
CSC 213 – Large Scale Programming. Trees  Represent hierarchical relationships  Parent-child basis of this abstract data type  Real-world example:
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.
CSE 373 Data Structures Lecture 7
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
CSCE 210 Data Structures and Algorithms
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Fundamentals of Programming II Introduction to Trees
Trees.
Binary Trees our leafy, annoying friends
Tree.
Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb.
Section 8.1 Trees.
Binary Trees, Binary Search Trees
TREES General trees Binary trees Binary search trees AVL trees
Trees and Binary Trees.
Week nine-ten: Trees Trees.
Trees (Part 1, Theoretical)
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Binary Trees, Binary Search Trees
CS 261 – Data Structures Trees.
CS210- Lecture 9 June 20, 2005 Announcements
2-3 Trees Extended tree. Tree in which all empty subtrees are replaced by new nodes that are called external nodes. Original nodes are called internal.
Binary Trees, Binary Search Trees
Trees.
Presentation transcript:

Problem of the Day  You drive a bus from Rotterdam to Delft.  At the 1 st stop, 33 people get in.  At the 2 nd stop, 7 add people & 11 passengers leave.  The 3 rd stop, sees 5 people leave and 2 get in.  After one hour, the bus arrives in Delft.  What is the name of the driver?

Problem of the Day  You drive a bus from Rotterdam to Delft.  At the 1 st stop, 33 people get in.  At the 2 nd stop, 7 add people & 11 passengers leave.  The 3 rd stop, sees 5 people leave and 2 get in.  After one hour, the bus arrives in Delft.  What is the name of the driver? It’s your name!

CSC 212 – Data Structures

Trees  Represent hierarchical relationships  Parent-child basis of this abstract data type  Real-world example: directories & types csc213/ homeworks/ ideas.todo 1M programs/ LLQueue.java 10K DLNode.java 25K hard.txt 3K impossible.txt 2K Tree.java 20K

Trees  Represent hierarchical relationships  Parent-child basis of this abstract data type  Real-world example: organism classification Mammal Cat Ape LionHumanChimpanzee ProfessorsYankees Fan

Tree Basics  Yet another Collection  Nodes are Position s  # of elements is its size  Some things are familiar  Using Position to hold elements  Others are very different  Node class has little overlap  Cannot discuss next & prev A B D C G H E F I J K

Tree Terms  Defined by relationships  Talk about parents, siblings, descendant  Nodes have no gender  Will often mix in terms like mother, father, niece, aunt, uncle, cousin, … A B D C G H E F I J K

Tree Terms  Tree rooted at node A  “Top” or “Start” of tree  B, C, D are children of A  A is parent of B, C, D  B, C, D are siblings  E, F, G, H are grandchildren of A A B D C G H E F I J K

Tree Relationships  Nodes either leaf or interior  Both or neither not options parents  A, B, C, F are parents  At least 1 child for each  Also called “interior nodes”  "Leaves"  "Leaves" name of others  Leaf node has no children A B D C G H E F I J K

Trees Recursion  Trees are recursive structure  Subtree defined by a node A B D C G H E F I J K

Trees Recursion  Trees are recursive structure  Subtree defined by a node  C is root of this subtree A B D C G H E F I J K

Trees Recursion  Trees are recursive structure  Subtree defined by a node  C is root of this subtree  D root of this subtree A B D C G H E F I J K

Trees Recursion  Trees are recursive structure  Subtree defined by a node  C is root of this subtree  D root of this subtree  B root of this subtree A B D C G H E F I J K

Trees Recursion  Trees are recursive structure  Subtree defined by a node  C is root of this subtree  D root of this subtree  B root of this subtree  Trees are like professors  Some are tall & thin

Trees Recursion  Trees are recursive structure  Subtree defined by a node  C is root of this subtree  D root of this subtree  B root of this subtree  Trees are like professors  Some are tall & thin  Short & boring a possibility

Trees Recursion  Trees are recursive structure  Subtree defined by a node  C is root of this subtree  D root of this subtree  B root of this subtree  Trees are like professors  Some are tall & thin  Short & boring a possibility  Others can be empty

Trees vs. Binary Trees  Both represent parent-child relationships  Both consist of single "root" node & its descendants  Nodes can have at most one parent  Root nodes are orphans -- do not have a parent must  All others, the non-root nodes must have parent  Children not required for any node in the tree  No limit to number of children for non-binary nodes  2 children for node in binary tree is the maximum

Binary Tree  Extends Tree interface & adds following property  2 or fewer children per node  Typically drawing of tree sets childrens' names Left child  “Left child” is name of child to left of the parent Right child  Child towards the right is called “Right child” R B D H E F I

Height and Size of a Tree Level 0 – max. 1 node  Maximum number of nodes doubles each level

Height and Size of a Tree Level 1 – max. 2 nodes Level 0 – max. 1 node  Maximum number of nodes doubles each level

Height and Size of a Tree Level 2 – max. 4 nodes Level 1 – max. 2 nodes Level 0 – max. 1 node  Maximum number of nodes doubles each level

Height and Size of a Tree Level 3 – max. 8 nodes Level 2 – max. 4 nodes Level 1 – max. 2 nodes Level 0 – max. 1 node  Maximum number of nodes doubles each level  For a level i in a binary tree  That level can have 2 i nodes  At most 2 (i+1) -1 nodes for tree to that level

Independent of Implementation A B Z F I Q M

Binary Tree, Tree, or Other?

ABCD 

Your Turn  Get into your groups and complete activity

For Next Lecture  Read parts of GT 7.2 & for Friday  Trees are Iterable, but how would it be done?  What are the types of traversals & how do they differ?  When do we do parent first & when do we do our kid?  Week #12 assignment posted & due Tuesday  Programming Assignment #2  Programming Assignment #2 due Friday  If you want help do not delay, I’m not here tomorrow