Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.

Slides:



Advertisements
Similar presentations
CS Fall 2012, Lab 08 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /17/2015 Tree - Data Structure  Basic.
Advertisements

Introduction to Trees Chapter 6 Objectives
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
EC-211 DATA STRUCTURES LECTURE Tree Data Structure Introduction –The Data Organizations Presented Earlier are Linear in That Items are One After.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
CS 206 Introduction to Computer Science II 09 / 22 / 2008 Instructor: Michael Eckmann.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Trees Chapter 25 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Trees Chapter 23 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
CSC 2300 Data Structures & Algorithms February 6, 2007 Chapter 4. Trees.
Chapter 18 - basic definitions - binary trees - tree traversals Intro. to Trees 1CSCI 3333 Data Structures.
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.
Chapter 11 A Trees. © 2004 Pearson Addison-Wesley. All rights reserved 11 A-2 Terminology A tree consists of vertices and edges, –An edge connects to.
Trees & Graphs Chapter 25 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
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.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Data Structures and Algorithms Lecture (BinaryTrees) Instructor: Quratulain.
Compiled by: Dr. Mohammad Omar Alhawarat
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.
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
CS-2852 Data Structures LECTURE 11 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
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.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 6.
Trees By P.Naga Srinivasu M.tech,(MBA). Basic Tree Concepts A tree consists of finite set of elements, called nodes, and a finite set of directed lines.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
DATA STRUCTURE BS(IT)3rd. Tree An Introduction By Yasir Mustafa Roll No. BS(IT) Bahauddin Zakariya University, Multan.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Tree Implementations Chapter 24 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java,
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 General Trees  Nonrecursive definition: a tree consists of a set of nodes and a set of directed edges that connect pairs of nodes.
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Trees A non-linear implementation for collection classes.
DS.T.1 Trees Chapter 4 Overview Tree Concepts Traversals Binary Trees Binary Search Trees AVL Trees Splay Trees B-Trees.
TREES From root to leaf. Trees  A tree is a non-linear collection  The elements are in a hierarchical arrangement  The elements are not accessible.
Trees Saurav Karmakar
Data Structures and Design in Java © Rick Mercer
CSCE 210 Data Structures and Algorithms
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Fundamentals of Programming II Introduction to Trees
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Tree.
Csc 2720 Instructor: Zhuojun Duan
CMSC 341 Introduction to Trees.
Section 8.1 Trees.
Lecture 18. Basics and types of Trees
Binary Trees, Binary Search Trees
Data Structures and Database Applications Binary Trees in C#
CS223 Advanced Data Structures and Algorithms
Binary Trees.
Trees 7/14/2009.
Trees and Binary Trees.
Abstract Data Structures
Trees.
Binary Trees.
CSE 373, Copyright S. Tanimoto, 2002 Binary Trees -
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Binary Trees, Binary Search Trees
Trees.
CSE 373, Copyright S. Tanimoto, 2001 Binary Trees -
Chapter 20: Binary Trees.
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Binary Trees.
Binary Trees, Binary Search Trees
Data Structures Using C++ 2E
Introduction to Trees Chapter 6 Objectives
Trees.
Presentation transcript:

Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.

Overview 10.1 10.2 Introduces tree terminology Discusses the implementation of binary trees 10.2 Traversing trees

Binary Trees

Binary Trees

Binary Trees

Binary Trees Binary tree Empty or, A node with a left and right subtree. Each of these subtrees is itself a binary tree. Children The nodes directly below a node In a binary tree, no node can have more than two children.

Binary Trees Parent Siblings Root Every node in a binary tree has exactly once parent, except for one a the top. Siblings Nodes with the same parent. Root Node at the top of a tree.

Binary Trees Leaves Internal nodes Depth Nodes with no children. Nodes that are not leaves. Depth Number of lines along the path back to the root. Root is a depth 0.

Binary Trees Level Height A level of the tree is the set of nodes at a particular depth. Height The height of a tree is the depth of the deepest node.

Binary Trees

Binary Trees

Binary Trees Descendants Proper descendants A node's descendants are itself, its children, their children, and so on. Every node is a descendant of the root. Proper descendants All of it descendants except itself.

Binary Trees Ancestors Proper ancestors Itself, its parents, its grandparent, and so on. Proper ancestors All of its ancestors except itself.

Binary Trees The number of nodes in a binary tree depends on the height of the tree and on how “skinny” or “busy” the tree is. Linear tree Every internal node has only one child. Perfect or Complete All of the leaves are at the same depth. Every internal node has exactly two children.

Binary Trees The number of nodes in a binary tree of height h can be any between h + 1 (for a linear tree). (for a perfect binary tree)

Binary Trees A binary tree with n nodes log2(n + 1) – 1 (for a perfect binary tree) n-1 (for a linear tree) h Θ(log n) for a perfect binary trees.

Binary Trees

Binary Trees

Binary Trees

Binary Trees

Binary Trees

Binary Trees

Binary Trees

Binary Trees

Binary Trees

Binary Trees

Binary Trees

Tree Traversal Four meaningful orders in which to traverse a binary tree. Preorder Inorder Postorder Level order

Tree Traversal

Tree Traversal

Tree Traversal

Tree Traversal

Tree Traversal

Tree Traversal

Tree Traversal Level order traversal is sometimes called breadth-first. The other traversals are called depth-first. Traversal takes Θ(n) in both breadth-first and depth-first. Memory usage in a perfect tree is Θ(log n) in depth-first and Θ(n) in breadth-first traversal.

Tree Traversal

Summary A tree is a branching, hierarchical structure. A binary tree either is empty or consists of a node, a left subtree, and a right subtree. A general tree (which cannot be empty) consists of a node and zero or more subtrees.

Summary In the widest possible binary tree, called a perfect tree, the number of nodes is exponential in the height of the tree. The height of such a tree is logarithmic in the number of nodes.

Summary Binary trees can be traversed Preorder Inorder Postorder Level order The first three have very elegant recursive algorithms, but level order traversal requires a queue.