2014-T2 Lecture 25 School of Engineering and Computer Science, Victoria University of Wellington  Lindsay Groves, Marcus Frean, Peter Andreae, and Thomas.

Slides:



Advertisements
Similar presentations
Computer Science C++ High School Level By Guillermo Moreno.
Advertisements

Main Index Contents 11 Main Index Contents Week 6 – Binary Trees.
CS 171: Introduction to Computer Science II
Data Structures: Trees i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
Fall 2007CS 2251 Iterators and Tree Traversals. Fall 2007CS 2252 Binary Trees In a binary tree, each node has at most two subtrees A set of nodes T is.
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 23 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.
Lecture 06: Tree Structures Topics: Trees in general Binary Search Trees Application: Huffman Coding Other types of Trees.
Recursion and Binary Tree ICS 51 – Introductory Computer Organization.
B+ Trees COMP
Chapter 19 - basic definitions - order statistics ( findkth( ) ) - balanced binary search trees - Java implementations Binary Search Trees 1CSCI 3333 Data.
Advanced Algorithms Analysis and Design Lecture 8 (Continue Lecture 7…..) Elementry Data Structures By Engr Huma Ayub Vine.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 7.
COMP 103 Introduction to Trees.
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary search trees.
2014-T2 Lecture 24 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, and Thomas.
S EARCHING AND T REES COMP1927 Computing 15s1 Sedgewick Chapters 5, 12.
2014-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,
CISC220 Fall 2009 James Atlas Lecture 13: Trees. Skip Lists.
Introduction to C Programming CE Lecture 23 Binary Trees.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
2013-T2 Lecture 22 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, and Thomas.
CS 615: Design & Analysis of Algorithms Chapter 5: Searching Brassard & Bratley Chap.: Chapter 9 Page &
Data Structures and Algorithms Lecture (BinaryTrees) Instructor: Quratulain.
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
2011-T2 Lecture 21 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, and Peter Andreae, VUW.
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.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
COMP 103 Traversing Trees. 2 RECAP-TODAY RECAP  Building and Traversing Trees TODAY  Traversing Trees  Chapter 16, especially 16.2.
2015-T2 Lecture 17 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, John Lewis,
Binary Trees In computer science, a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left.
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.
2015-T2 Lecture 30 School of Engineering and Computer Science, Victoria University of Wellington  Lindsay Groves, Marcus Frean, Peter Andreae, and Thomas.
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 27 School of Engineering and Computer Science, Victoria University of Wellington  Lindsay Groves, Marcus Frean, 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 Tree Implementation. Binary Search Trees (BST) Nodes in Left subtree has smaller values Nodes in right subtree has bigger values.
Data Structures Azhar Maqsood School of Electrical Engineering and Computer Sciences (SEECS-NUST) Binary Trees.
Foundation of Computing Systems Lecture 4 Trees: Part I.
More Binary Search Trees, Project 2 Bryce Boe 2013/08/06 CS24, Summer 2013 C.
Hello Everyone!!! 1. Tree And Graphs 2 Features of Trees  Tree Nodes Each node have 0 or more children A node have must one parent  Binary tree Tree.
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 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
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
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Fundamentals of Programming II Introduction to Trees
Recursive Objects (Part 4)
COMP 103 Introduction to Trees Thomas Kuehne 2013-T2 Lecture 19
Binary search tree. Removing a node
Sections 8.7 – 8.8 Balancing a Binary Search Tree.
COMP 103 Tree Traversals Lindsay Groves 2016-T2 Lecture 22
Section 8.1 Trees.
COMP 103 Sorting with Binary Trees: Tree sort, Heap sort Alex Potanin
COMP 103 HeapSort Thomas Kuehne 2013-T1 Lecture 27
Binary Search Trees (I)
More complexity analysis & Binary Search
Depth-first vs breadth-first traversals
Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms
Design and Analysis of Algorithms
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Chapter 20: Binary Trees.
Non-Linear data structures
Presentation transcript:

2014-T2 Lecture 25 School of Engineering and Computer Science, Victoria University of Wellington  Lindsay Groves, Marcus Frean, Peter Andreae, and Thomas Kuehne, VUW COMP 103 Marcus Frean finishing traversals, and introducing Binary Search Trees (I)

2 RECAP-TODAY RECAP  Tree traversals TODAY  iterative in-order traversals! (two ways to proceed...)  Introduction to Binary Search Trees  Using hierarchical access to unstructured data  Reading: Chapter 17.1

3 in-order traversal? method A... D B H FCAI EG

4 in-order traversal? method B... D B H FCAI EG

5 Depth-First vs Breadth-First  Depth-First:  Visit one child and all of its descendants before its siblings  May visit root before, after, or between its children  +Requires only one branch to manage traversal!  − May find “costly” results first, and may not find results at all (infinite search trees)  Breadth-First (level-order):  Visit nodes in order of increasing depth  May choose nodes in a level in a specific order  − Requires accumulation of levels to manage traversal  +Finds minimal solutions and guarantees success!

6 Remember: Efficiency Challenge  Sorted Arrays  access: O(log(n))  modification:O(n)  Linear Linked Structures  access:O(n)  modification:O(1) [provided we know the position]  Can we have the best of both worlds?  yes, using trees!

7 Divide & Conquer  Strategy  eliminate as many as possible in each step Toby Tiger Lea Lion Bully Bulldog Tanja Tui Kurt Kaka Tim Turtle Sally Snake Egg Laying Mammal Reptile Feline Canine Bird

8 Divide & Conquer  Strategy  eliminate as many as possible in each step  what does this remind you of?  can we improve on the below? >19 <19 >51 <10 >10 <51

9 Divide & Conquer  Strategy  use existing elements for decision nodes

10 Divide & Conquer  Strategy  use existing elements for decision nodes  now we need less nodes can get “lucky” on the way down

11 Binary Search Again  Searching “50” low mid hi

12 Binary Search Trees  Properties  For every node: all items in left subtree <item item < all items in right subtree  Ascending order obtained by ___________ traversal “≤” if duplicates are allowed