Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Symbol tables.

Slides:



Advertisements
Similar presentations
S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
Advertisements

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.
Binary Trees Chapter 6. Linked Lists Suck By now you realize that the title to this slide is true… By now you realize that the title to this slide is.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
CS 171: Introduction to Computer Science II
CS2420: Lecture 13 Vladimir Kulyukin Computer Science Department Utah State University.
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.
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Introduction to trees.
CS 146: Data Structures and Algorithms June 18 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
1 Chapter 18 Trees Objective To learn general trees and recursion binary trees and recursion tree traversal.
Binary Tree. Binary Trees – An Informal Definition A binary tree is a tree in which no node can have more than two children Each node has 0, 1, or 2 children.
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.
Advanced Algorithms Analysis and Design Lecture 8 (Continue Lecture 7…..) Elementry Data Structures By Engr Huma Ayub Vine.
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.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
Week 6 - Wednesday.  What did we talk about last time?  Exam 1 post-mortem  Recursive running time.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
CMSC 341 Introduction to Trees. 8/3/2007 UMBC CMSC 341 TreeIntro 2 Tree ADT Tree definition  A tree is a set of nodes which may be empty  If not empty,
Week 6 - Friday.  What did we talk about last time?  Recursive running time  Fast exponentiation  Merge sort  Introduced the Master theorem.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 5 Prepared by İnanç TAHRALI.
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.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Topic 17 Introduction to Trees
Tree Data Structures.
Binary Trees Definition A binary tree is: (i) empty, or (ii) a node whose left and right children are binary trees typedef struct Node Node; struct Node.
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.
Starting at Binary Trees
CS-2852 Data Structures LECTURE 11 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Week 8 - Wednesday.  What did we talk about last time?  Level order traversal  BST delete  2-3 trees.
Week 8 - Monday.  What did we talk about last time?  BST traversals  Get range implementation.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Week 7 - Friday.  What did we talk about last time?  Trees in general  Binary search trees.
CSC 172 DATA STRUCTURES. LISTS We have seen lists: public class Node { Object data; Node next; } 
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
CMSC 341 Introduction to Trees. 2/21/20062 Tree ADT Tree definition –A tree is a set of nodes which may be empty –If not empty, then there is a distinguished.
Binary Tree. Some Terminologies Short review on binary tree Tree traversals Binary Search Tree (BST)‏ Questions.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Trees and Graphs CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
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.
1 Joe Meehean. A A B B D D I I C C E E X X A A B B D D I I C C E E X X  Terminology each circle is a node pointers are edges topmost node is the root.
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.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
18-1 Chapter 18 Binary Trees Data Structures and Design in Java © Rick Mercer.
1 CMSC 341 Introduction to Trees Textbook sections:
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.
Trees Chapter 15.
CSCE 210 Data Structures and Algorithms
Week 6 - Wednesday CS221.
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
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.
Data Structures & Algorithm Design
Week 11 - Friday CS221.
ITEC 2620M Introduction to Data Structures
Binary Trees, Binary Search Trees
Data Structures and Database Applications Binary Trees in C#
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Trees.
Binary Trees, Binary Search Trees
Chapter 20: Binary Trees.
Binary Trees, Binary Search Trees
Presentation transcript:

Week 7 - Wednesday

 What did we talk about last time?  Recursive running time  Master Theorem  Symbol tables

Infix to Postfix Converter

Student Lecture

 A tree is a data structure built out of nodes with children  A general tree node can have any non- negative number of children  Every child has exactly one parent node  There are no loops in a tree  A tree expressions a hierarchy or a similar relationship

 The root is the top of the tree, the node which has no parents  A leaf of a tree is a node that has no children  An inner node is a node that does have children  An edge or a link connects a node to its children  The depth of a node is the length of the path from the root to the node  Note that some definitions add 1 to this definition  The height of the tree is the greatest depth of any node  A subtree is a node in a tree and all of its children

Root Inner Nodes Leaves

 A binary tree is a tree such that each node has two or fewer children  The two children of a node are generally called the left child and the right child, respectively

 Full binary tree: every node other than the leaves has two children  Perfect binary tree: a full binary tree where all leaves are at the same depth  Complete binary tree: every level, except possibly the last, is completely filled, with all nodes to the left  Balanced binary tree: the depths of all the leaves differ by at most 1

 A binary search tree is binary tree with three properties: 1. The left subtree of the root only contains nodes with keys less than the root’s key 2. The right subtree of the root only contains nodes with keys greater than the root’s key 3. Both the left and the right subtrees are also binary search trees

public class Tree { private static class Node { public int key; public Object value; public Node left; public Node right; } private Node root = null; … } The book uses a generic approach, with keys of type Key and values of type Value. The algorithms we'll use are the same, but I use int keys to simplify comparison.

 Almost all the methods we call on trees will be recursive  Each will take a Node reference to the root of the current subtree  Because the root is private, assume that every recursive method is called by a public, non-recursive proxy method: public Type doSomething() calls private static Type doSomething( Node root )

private static int min(Node node)  Proxy: public int min() { return min( root ); }  What’s the code?  Use recursion!

private static int max(Node node)  Proxy: public int max() { return max( root ); }  What’s the code?  Use recursion!

private static Object get(Node node, int key)  Proxy: public Object get(int key) { return get( root, key ); }  What’s the code?  Use recursion!

private static Node put(Node node, int key, Object value)  Proxy: public void put(int key, Object value) { root = put( root, key, value ); }  What’s the code?  Use recursion!

 Implementations of other binary search tree methods  Traversals of binary search trees  Deletion

 Keep reading section 3.2  Finish Project 2  Due this Friday  CS Club tonight at 6pm right here in E281  Office hours from 3:30-5pm canceled this Friday