Trees 2 and Doubly Linked Lists As you arrive: Please snarf today’s code.

Slides:



Advertisements
Similar presentations
SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.
Advertisements

Lecture 16: Tree Traversal.
Advanced Data Structures
CS 171: Introduction to Computer Science II
InOrder Traversal Algorithm // InOrder traversal algorithm inOrder(TreeNode n) { if (n != null) { inOrder(n.getLeft()); visit(n) inOrder(n.getRight());
Lists and Trees (continued) CS-2301, B-Term Lists and Trees (continued) CS-2301, System Programming for Non-Majors (Slides include materials from.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Trees CMSC 433 Chapter 8.1 Nelson Padua-Perez Bill Pugh.
Trees Chapter 23 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Tree Implementations Chapter 24 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Tree Traversals & Maps Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Trees.
Data Structures Arrays both single and multiple dimensions Stacks Queues Trees Linked Lists.
Recursion Bryce Boe 2013/11/18 CS24, Fall Outline Wednesday Recap Lab 7 Iterative Solution Recursion Binary Tree Traversals Lab 7 Recursive Solution.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templatized Tree.
Chapter 19: Binary Trees. Objectives In this chapter, you will: – Learn about binary trees – Explore various binary tree traversal algorithms – Organize.
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
CS 3610 Midterm Review.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
1 Trees 2 Binary trees Section Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children –Left and.
Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
CISC220 Fall 2009 James Atlas Lecture 13: Trees. Skip Lists.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
For Monday Read Weiss, chapter 7, sections 1-3. Homework –Weiss, chapter 4, exercise 6. Make sure you include parentheses where appropriate.
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.
Review for Final Andy Wang Data Structures, Algorithms, and Generic Programming.
Topic 15 The Binary Search Tree ADT Binary Search Tree A binary search tree (BST) is a binary tree with an ordering property of its elements, such.
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
Week 7 - Friday.  What did we talk about last time?  Trees in general  Binary search trees.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
Trees 2: Section 4.2 and 4.3 Binary trees. Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children
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.
David Stotts Computer Science Department UNC Chapel Hill.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 6.
1/14/20161 BST Operations Data Structures Ananda Gunawardena.
Binary Search Trees (BST)
Trees As you arrive: 1.Snarf the code for today’s class 2.Pick up a handout 3.Go ahead and start on the first page of the handout.
1 Trees 2 Binary trees Section Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children –Left and.
COSC 2P03 Week 21 Tree Traversals – reminder Breadth-first traversal: starting from root, visit all nodes on each level in turn, from left to right Depth-first.
Tree Implementations Chapter 24 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java,
Binary Tree Implementation. Binary Search Trees (BST) Nodes in Left subtree has smaller values Nodes in right subtree has bigger values.
Foundation of Computing Systems Lecture 4 Trees: Part I.
Lecture 7: Searching a Tree Neil Ghani University of Strathclyde.
More Binary Search Trees, Project 2 Bryce Boe 2013/08/06 CS24, Summer 2013 C.
Planning & System installation
Trees Chapter 15.
Fundamentals of Programming II Introduction to Trees
Recursive Objects (Part 4)
Planning & System installation
Sections 8.7 – 8.8 Balancing a Binary Search Tree.
Week 6 - Wednesday CS221.
Binary Search Tree Chapter 10.
Tree.
Section 8.1 Trees.
Tree Traversals – reminder
ITEC 2620M Introduction to Data Structures
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Tree Traversals – reminder
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Principles of Computing – UFCFA3-30-1
Binary Tree Traversals
Chapter 9 Binary Trees.
Trees.
Chapter 20: Binary Trees.
A Binary Tree is a tree in which each node has at most 2 children
Presentation transcript:

Trees 2 and Doubly Linked Lists As you arrive: Please snarf today’s code.

3 Topics 1.Some more on height 2.Tree Traversals 3.Doubly Linked Lists 4.Big O of recursive functions

Given a tree that’s height-balanced, what is its height? Number of nodes = 7 Height = 3 Number of nodes = 5 Height = 3 A.O(n) B.O(n log n) C.O(log n) D.O(n 2 )

What is the maximum amount of time it could take to insert a node in a binary search tree? How about find a node? H = tree height N = # of tree elements 1)O(H) 2)O(N) 3)O(N + H) 4)O(log H) 5)O(H 2 )

What is the maximum amount of time it could take to insert a node in a binary search tree? How about find a node? O(tree height)

Traversals Preorder (N L R): Inorder (L N R): Postorder (L R N): Read N L R as “first visit node, then visit left subtree, then vision right subtree” Go to “Quizzes/Tests” section of Sakai and find today’s classwork – fill it out

Onward! Go to the TreeNodeExample code from Monday’s class Try to write: 1.An iterative version of containsNode that assumes the tree is a binary search tree 2.An iterative version of containsNode that does not assume the tree is a binary search tree (hint: you’ll want a stack or queue)

How do we compute the Big O of recursive functions?

Solve the problems in RecurrenceRelationProblems.java A. B. C. D. E.