Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms Post-order Traversal: Left Child - Right Child - Root Depth-First Search.

Slides:



Advertisements
Similar presentations
Chapter 12 Binary Search Trees
Advertisements

CS Fall 2012, Lab 08 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /17/2015 Tree - Data Structure  Basic.
Senem Kumova Metin Spring2009 BINARY TREES && TREE TRAVERSALS Chapter 10 in A Book on C.
Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms Breadth-First Binary Tree Traversal Algorithm.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
Computer Science 2 Data Structures and Algorithms V section 2 Introduction to Trees Professor: Evan Korth New York University.
CS2420: Lecture 13 Vladimir Kulyukin Computer Science Department Utah State University.
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.
Alyce Brady CS 510: Computer Algorithms Breadth-First Graph Traversal Algorithm.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 10 Ming Li Department of.
Basic Algorithms on Trees. If the node v is the root, then the depth of the node v is 0. Otherwise, the depth of the node v is one plus the depth of.
Alyce Brady CS 510: Computer Algorithms Depth-First Graph Traversal Algorithm.
Binary Trees. Linear data structures Here are some of the data structures we have studied so far: –Arrays –Singly-linked lists and doubly-linked lists.
CS21, Tia Newhall Binary Search Trees (BST) 1.Hierarchical data structure with a single pointer to root node 2.Each node has at most two child nodes (a.
1 Trees 3: The Binary Search Tree Section Binary Search Tree A binary tree B is called a binary search tree iff: –There is an order relation
Three Types of Depth-First Search Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms.
Binary Trees. 2 Linear data structures Here are some of the data structures we have studied so far: –Arrays –Singly-linked lists and doubly-linked lists.
1 Trees Tree nomenclature Implementation strategies Traversals –Depth-first –Breadth-first Implementing binary search trees.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Emma Price 1.  To be able to:  Explain what a binary tree is.  To traverse a binary tree using the three different methods. 2.
1 CSE 1342 Programming Concepts Trees. 2 Basic Terminology Trees are made up of nodes and edges. A tree has a single node known as a root. –The root is.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
CSE 3358 NOTE SET 10 Data Structures and Algorithms.
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.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 6.
Binary Search Trees (BSTs) 18 February Binary Search Tree (BST) An important special kind of binary tree is the BST Each node stores some information.
1/14/20161 BST Operations Data Structures Ananda Gunawardena.
Binary Search Trees (BST)
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.
Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order.
Trees. What is a tree? You know…  tall  green  leafy  possibly fruit  branches  roots  I’m sure you’ve seen them.
Binary Trees. 2 Parts of a binary tree A binary tree is composed of zero or more nodes In Java, a reference to a binary tree may be null Each node contains:
Example: Expressions Python Programming, 2/e 1 [+, [*, 3, 5], [*, 2, [-, 6, 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.
Binary Tree Implementation. Binary Search Trees (BST) Nodes in Left subtree has smaller values Nodes in right subtree has bigger values.
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Symbol tables.
Data Structures Azhar Maqsood School of Electrical Engineering and Computer Sciences (SEECS-NUST) Binary Trees.
Lecture 7: Searching a Tree Neil Ghani University of Strathclyde.
Fundamentals of Algorithms MCS - 2 Lecture # 17. Binary Search Trees.
BSTs, AVL Trees and Heaps Ezgi Shenqi Bran. What to know about Trees? Height of a tree Length of the longest path from root to a leaf Height of an empty.
Fundamentals of Programming II Introduction to Trees
Recursive Objects (Part 4)
Binary search tree. Removing a node
Binary Search Tree (BST)
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
Tree.
Lecture 22 Binary Search Trees Chapter 10 of textbook
Section 8.1 Trees.
Tree traversal from Introduction to Trees Chapter 6 Objectives
ITEC 2620M Introduction to Data Structures
Binary Tree Applications
CS223 Advanced Data Structures and Algorithms
COSC2100: Data Structures and Algorithms
Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms
Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms
Abstract Data Structures
Trees.
Trees (part 2) CSE 2320 – Algorithms and Data Structures
CS223 Advanced Data Structures and Algorithms
Principles of Computing – UFCFA3-30-1
Binary Tree Traversals
Design and Analysis of Algorithms
2018, Fall Pusan National University Ki-Joune Li
Binary Trees, Binary Search Trees
CS223 Advanced Data Structures and Algorithms
Topic 5: Heap data structure heap sort Priority queue
Binary Tree Implementation And Applications
Binary Trees, Binary Search Trees
Presentation transcript:

Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms Post-order Traversal: Left Child - Right Child - Root Depth-First Search

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root

A BC DEFG HIJKLMNO

A BC DEFG HIJKLMNO

A BC DEFG HIJKLMNO H H

A BC DEFG HIJKLMNO H H

A BC DEFG HIJKLMNO H H

A BC DEFG HIJKLMNO H I

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N O

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N O

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N O G

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N O G

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N O G C

A BC DEFG HIJKLMNO Post-order Traversal: Left Child - Right Child - Root H I D J K E B L M F N O G C

Post-order Traversal: Left Child - Right Child - Root A BC DEFG HIJKLMNO H I D J K E B L M F N O G C A

Post-order Traversal: Left Child - Right Child - Root A BC DEFG HIJKLMNO H I D J K E B L M F N O G C A

Pseudo-Code for Post-order Traversal post-traverse post-traverse left subtree post-traverse right subtree visit current node e.g., print value

Time and Space Complexity for Depth-First Search Algs. Time Complexity Time Complexity –Visit each node three timesO(n) first arrival first arrival return from left child return from left child return from right child return from right child

Space Complexity Space Complexity –Stack to handle recursion Stack length = depth of tree Stack length = depth of tree best case: lg n best case: lg n worst case: n O(n) worst case: n O(n) Time and Space Complexity for Depth-First Search Algs.