Problem of the Day  Can you move exactly one glass to arrange the glasses containing orange juice to be next to one another?

Slides:



Advertisements
Similar presentations
A.A DA1: Binary Tree1 Binary Tree. A.A DA1: Binary Tree2 Implementazione usa Tree LinkedBinaryTree BinaryTree NodePositionList PositionList.
Advertisements

Chapter 7. Binary Search Trees
Tree representation and tree search - Ed. 2. and 3.: Chapter 6 - Ed. 4.: Chapter 10.
S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
Tree Data Structures &Binary Search Tree 1. Trees Data Structures Tree  Nodes  Each node can have 0 or more children  A node can have at most one parent.
CS 206 Introduction to Computer Science II 09 / 24 / 2008 Instructor: Michael Eckmann.
Problem of the Day  You are trapped alone in a dark room with:  Candle;  Wood stove; and  Gas lamp (with full tank).  You only have one match; what.
Lecture 8 CS203. Implementation of Data Structures 2 In the last couple of weeks, we have covered various data structures that are implemented in the.
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary trees Reading: L&C 9.1 – 9.7.
© 2004 Goodrich, Tamassia Trees1 Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery.
© 2004 Goodrich, Tamassia Priority Queues1 Heaps: Tree-based Implementation of a Priority Queue.
Trees1 Recursion Recursion is a concept of defining a method that makes a call to itself.
trees1 Binary Trees trees2 Basic terminology nodesFinite set of nodes (may be empty -- 0 nodes), which contain data rootFirst node in tree is called.
Chapter 7: Trees Objectives:
Razdan CST230http://dcst2.east.asu.edu/~razdan/cst230/ Razdan with contribution from others 1 Chapter 9 Trees Anshuman Razdan Div of Computing Studies.
CS 206 Introduction to Computer Science II 02 / 11 / 2009 Instructor: Michael Eckmann.
© 2004 Goodrich, Tamassia Trees1 this is a tree. © 2004 Goodrich, Tamassia Trees2 What is a Tree? In computer science, a tree is an abstract model of.
Trees COMP53 Oct 31, What is a Tree? A tree is an abstract model of a hierarchical structure A tree consists of nodes with a parent-child relation.
Trees1 Part-C Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery.
Version TCSS 342, Winter 2006 Lecture Notes Trees Binary Trees Binary Search Trees.
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.
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary search trees.
Lecture Objectives  To learn how to use a tree to represent a hierarchical organization of information  To learn how to use recursion to process trees.
General Trees CS 400/600 – Data Structures. General Trees2.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
Tree ADTs Tree concepts. Applications of Trees. A Tree ADT – requirements, contract. Linked implementation of Trees. Binary Tree ADTs. Binary Search.
CSC 213 – Large Scale Programming Lecture 17: Binary Search Trees.
Topic 17 Introduction to Trees
Topic 19 Binary Search Trees "Yes. Shrubberies are my trade. I am a shrubber. My name is 'Roger the Shrubber'. I arrange, design, and sell shrubberies."
 Trees Data Structures Trees Data Structures  Trees Trees  Binary Search Trees Binary Search Trees  Binary Tree Implementation Binary Tree Implementation.
CS 206 Introduction to Computer Science II 02 / 13 / 2009 Instructor: Michael Eckmann.
CIS* Quiz 2. For a large array, and in the worst case, selection sort is faster than insertion sort. False Both selection sort and insertion sort.
CSC 213 – Large Scale Programming Lecture 15: Heap-based Priority Queue.
Trees CS 105. L9: Trees Slide 2 Definition The Tree Data Structure stores objects (nodes) hierarchically nodes have parent-child relationships operations.
1 Binary Trees (7.3) CSE 2011 Winter November 2015.
Trees1 Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery © 2010 Goodrich, Tamassia.
Lecture1 introductions and Tree Data Structures 11/12/20151.
Lecture11: Tree I Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
1 Joe Meehean.  We wanted a data structure that gave us... the smallest item then the next smallest then the next and so on…  This ADT is called a priority.
Trees1 Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery © 2010 Goodrich, Tamassia.
Trees1 Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery © 2013 Goodrich, Tamassia, Goldwasser.
Binary Trees. A Binary tree is a tree in which every node has none, one, or at most, two children A Proper Binary Tree has two children or no children.
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.
Problem of the Day  Can you move exactly one glass to arrange the glasses containing orange juice to be next to one another?
CS 206 Introduction to Computer Science II 10 / 02 / 2009 Instructor: Michael Eckmann.
24 January Trees CSE 2011 Winter Trees Linear access time of linked lists is prohibitive  Does there exist any simple data structure for.
2/11/ IT 179 Recursive Definition of Tree Structures 1.Empty is a tree; the root is null 2.A node points to a finite number of the roots of some.
Problem of the Day  You are trapped alone in a dark room with:  Candle;  Wood stove; and  Gas lamp (with full tank).  You only have one match; what.
Priority Queues CS 110: Data Structures and Algorithms First Semester,
© 2004 Goodrich, Tamassia Trees1 Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery.
(c) University of Washington20c-1 CSC 143 Binary Search Trees.
1 COMP9024: Data Structures and Algorithms Week Five: Trees Hui Wu Session 1, 2015
CSCE 3110 Data Structures & Algorithm Analysis
Recursive Definition of Tree Structures
Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery Trees
Trees Tree nomenclature Implementation strategies Traversals
Lecture 22 Binary Search Trees Chapter 10 of textbook
Trees 9/21/2018 9:58 PM Trees this is a tree Trees.
Depict the Tree Structure in a picture
Trees.
Data Structures: Trees and Binary Trees
Trees Make Money Fast! Stock Fraud Ponzi Scheme Bank Robbery Trees
Non-Linear Structures
CSC 143 Binary Search Trees.
CS210- Lecture 9 June 20, 2005 Announcements
Trees.
Search Sorted Array: Binary Search Linked List: Linear Search
Tree and its terminologies
Presentation transcript:

Problem of the Day  Can you move exactly one glass to arrange the glasses containing orange juice to be next to one another?

Problem of the Day  Can you move exactly one glass to arrange the glasses containing orange juice to be next to one another?  Take the 2 nd glass & pour it into the 5 th glass!

CSC 213 – Large Scale Programming

“Node” Sounds Technical…  Links in linked list commonly called “nodes”  Nodes name for links in a T REE also  Position interface implemented by the node class  Each node’s data retrieved using element()  Node class often used by data structures  Node is not specific, but sounds better than “thingy”  Position interface implemented by node (usually)

Node Heights  Longest distance to leaf node  D's height is 0  B's height is 2  A's height is 3 A B D C G H E F I J K

Node Heights  Height 1 more than taller child  F's height is 1  B's height is 2  E's height is 0  Leaf's height always 0 A B D C G H E F I J K

Node Depths  Distance to root node of Tree  A's depth is 0  C's depth is 1  I's depth is 3 A B D C G H E F I J K

Node Depths  Depth of a node is 1 more than its parent  Root's depth always 0  B, C, & D have depth of 1  E, F, G, H have depth of 2  I, J, K have depth of 3 A B D C G H E F I J K

Tree Interface  Interesting methods from the interface Position root() Position parent(p) Iterable > children(p) boolean isInternal(p) boolean isExternal(p) boolean isRoot(p) E replace (p, e)

Tree Interface  Often include other methods beyond just these addremove  Normally want methods to add or remove data  Else use root & size fields to start in Tree

Node Class For Tree class TNode implements Position { private E element; private TNode parent; private Sequence > kids; // Besides getters & setters, often include methods like: public TNode getChild(int i) { return kids.get(i); } public void addChild(TNode kid) { kids.addLast(kid); } public TNode removeChild(int i) { return kids.remove(i); } }

Tree D  Visualization of Tree B D A CE F B AF CE Tree root size  6

D  Node Structure of the Tree B D A CE F B AF CE

D  Links Between Tree 's Nodes B D A CE F B AF CE

D  B D A CE F B AF CE

Tree D  Actual View of Tree B D A CE F B AF CE Tree root size  6

View of an Actual Tree

Linked Node for BinaryTree class BTNode implements Position { private E element; private BTNode parent; private BTNode left; private BTNode right; // Add getters & setters for each field public Iterable > children(){ IndexList > il = new … il.add(0, left); il.add(1, right); return il; } }

BinaryTree   Picturing Linked BinaryTree B C A D   BACD BinaryTree root size  4

  Nodes in Linked BinaryTree B C A D   BACD

 Pointers in Linked BinaryTree B C A D   B AC D

Array-based BinaryTree  Node at index specified for location in T REE  Root node stored at index 0  Root’s left child at index 1  Right child of root at index 2  Left child’s right child at index 4  Right child’s left child at index 5  Node at index n ’s left child is at index 2n + 1  Node at index n ’s right child is at index 2n + 2

Array-based Implementation  Tree’s depth limited by array size  Where in array determined by location  Sequence overcomes limits  null added to pad space  replace() used to add nodes

Array-based Implementation A HG FE D C B J

A HG FE D C B J

A HG FE D C B J

Node in array-based BinaryTree class BANode implements Position { private E element; private int myIndex; private boolean hasLeft; private boolean hasRight; // Add getters & setters for each field public int getLeft() { if (!hasLeft) { return -1; } return (myIndex * 2) + 1; } public void setRight() { hasRight = true; } }

Your Turn  Get into your groups and complete activity

For Next Lecture  Read GT 8.1 – for Friday's lecture  What is an Entry and why would you use Entry ?  Comparable sounds cool; what does it mean?  What if we need more complex data than elements?  Week #13 assignment posted & due Tuesday  Programming Assignment #3  Programming Assignment #3 available now