Problem of the Day  Solve this equation by moving the numbers: 76 = 24.

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.
Trees Chapter 25 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
General Info Check out gilgarn.org. QUIZ DO YOU: – Love CSC 171 ? – Want a job? – Like to exert power over others? – Want to improve CSC UR?
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.
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.
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
CS261 Data Structures Trees Introduction and Applications.
Introduction Of Tree. Introduction A tree is a non-linear data structure in which items are arranged in sequence. It is used to represent hierarchical.
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; } 
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Binary Trees. Binary Tree Finite (possibly empty) collection of elements A nonempty binary tree has a root element The remaining elements (if any) are.
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.
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.
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.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
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.
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.
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Symbol tables.
CH 7 : TREE ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY.
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.
1 Trees. Objectives To understand the concept of trees and the standard terminology used to describe them. To appreciate the recursive nature of a tree.
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.
TREE Ahsan Ahmed College of Computer and Information Science Majma’ah University 1.
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.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
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.
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.
Lecture 36 Section 12.2 Mon, Apr 23, 2007
CS210- Lecture 9 June 20, 2005 Announcements
Binary Trees.
Trees Trees are a very useful data structure. Many different kinds of trees are used in Computer Science. We shall study just a few of these.
Trees.
Presentation transcript:

Problem of the Day  Solve this equation by moving the numbers: 76 = 24

Problem of the Day  Solve this equation by moving the numbers: 76 = = 49

CSC 212 – Data Structures

Trees  Represent hierarchical relationships  Parent-child basis of this abstract data type  Real-world example: directories & types csc212/ 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  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  B 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  B root of this subtree  D 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  B root of this subtree  D 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  B root of this subtree  D root of this subtree  Trees are like professors  Some are tall & thin  Short & boring a possibility  Others can be empty & useless

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 Monday  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?  Programming Assignment #2  Programming Assignment #2 due today  To get help, do not delay; end of week gets crazy