Tree.

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

SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
CS 171: Introduction to Computer Science II
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Trees CMSC 433 Chapter 8.1 Nelson Padua-Perez Bill Pugh.
CS 240: Data Structures Monday, July 30 th Binary Search Trees.
Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.
Types of Binary Trees Introduction. Types of Binary Trees There are several types of binary trees possible each with its own properties. Few important.
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.
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
CS Data Structures Chapter 15 Trees Mehmet H Gunes
S EARCHING AND T REES COMP1927 Computing 15s1 Sedgewick Chapters 5, 12.
CISC220 Fall 2009 James Atlas Lecture 13: Trees. Skip Lists.
Binary Trees 2 Overview Trees. Terminology. Traversal of Binary Trees. Expression Trees. Binary Search Trees.
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.
Tree Data Structures.
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.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
Binary Search Tree Traversal Methods. How are they different from Binary Trees?  In computer science, a binary tree is a tree data structure in which.
 Trees Data Structures Trees Data Structures  Trees Trees  Binary Search Trees Binary Search Trees  Binary Tree Implementation Binary Tree Implementation.
Week 7 - Friday.  What did we talk about last time?  Trees in general  Binary search trees.
Binary Search Trees Data Structures Ananda Gunawardena
Discrete Mathematics Chapter 5 Trees.
1 Chapter 7 Objectives Upon completion you will be able to: Create and implement binary search trees Understand the operation of the binary search tree.
Binary Tree. Some Terminologies Short review on binary tree Tree traversals Binary Search Tree (BST)‏ Questions.
Binary Search Trees (BST)
DATA STRUCTURE BS(IT)3rd. Tree An Introduction By Yasir Mustafa Roll No. BS(IT) Bahauddin Zakariya University, Multan.
Foundation of Computing Systems Lecture 4 Trees: Part I.
Lecture 7: Searching a Tree Neil Ghani University of Strathclyde.
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.
Trees By JJ Shepherd. Introduction Last time we discussed searching and sorting in a more efficient way Divide and Conquer – Binary Search – Merge Sort.
Chapter 7 Trees_ Part2 TREES. Depth and Height 2  Let v be a node of a tree T. The depth of v is the number of ancestors of v, excluding v itself. 
Question 4 Tutorial 8. Part A Insert 20, 10, 15, 5,7, 30, 25, 18, 37, 12 and 40 in sequence into an empty binary tree
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.
DS.T.1 Trees Chapter 4 Overview Tree Concepts Traversals Binary Trees Binary Search Trees AVL Trees Splay Trees B-Trees.
Trees. Trees: – A trunk from the roots – Divides into branches – Ends in leaves.
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Trees Chapter 15.
CSCE 210 Data Structures and Algorithms
Fundamentals of Programming II Introduction to Trees
Recursive Objects (Part 4)
Binary search tree. Removing a node
Week 6 - Wednesday CS221.
Binary Search Tree (BST)
Section 8.1 Trees.
Binary Trees, Binary Search Trees
TREES General trees Binary trees Binary search trees AVL trees
CS223 Advanced Data Structures and Algorithms
Abstract Data Structures
Trees.
Binary Trees.
Principles of Computing – UFCFA3-30-1
CSE 373, Copyright S. Tanimoto, 2002 Binary Trees -
Binary Tree Chapter 8 (cont’) Part2.
Binary Trees, Binary Search Trees
Trees.
CSE 373, Copyright S. Tanimoto, 2001 Binary Trees -
Chapter 20: Binary Trees.
Binary Trees.
Non-Linear data structures
Binary Trees, Binary Search Trees
Data Structures Using C++ 2E
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
A Binary Tree is a tree in which each node has at most 2 children
Introduction to Trees Chapter 6 Objectives
Presentation transcript:

Tree

Tree A tree is a collection of nodes and edges A tree has only one root Trees are hierarchical: Parent-child relationship between two nodes basic operations of a tree: tree traversals insert node delete node searching

Level E R T L P M A S 1 2 3 root Child (of root) Leaves or terminal nodes Child (of root) Depth of T: 2 Tree height: 4 1 2 3

Binary Trees A tree in which no node can have more than two children

A General Tree & A Binary Tree

Balanced Binary Trees A binary tree is balanced if the heights of any node’s two subtrees differ by no more than 1 Complete binary trees are balanced Full binary trees are complete and balanced B = HL - HR

Example: A A B A A B B C D E Balance Balance Balance Balance 2-1=1 1-1=0 3-2=1 1-2=-1 A A B Balance Balance A A B B C D E Balance Balance

+ 3 2 Example of tree application: Represent algebraic formulas Q: Write the following operations as binary tree and determine the (tree Depth, tree height, number of levels). A. 2+3 + 1 Tree depth 2 Tree height Number of levels 2 3

* / - 6 2 6 2 B. (6/2) * (20-4) 2 Tree depth 3 Tree height Number of levels B. (6/2) * (20-4) * / - 6 2 6 2

Tree traversal Type of Traversal Inorder traversal Preorder traversal Postorder traversal

Inorder traversal Recursively print out all data in the left subtree Print the data at the root Recursively print out all data in the right subtree Pre-order traversal Print the data at the root Recursively print out all data in the left subtree Recursively print out all data in the right subtree Postorder traversal Recursively print out all data in the left subtree Recursively print out all data in the right subtree Print the data at the root

Traverse the following binary tree using the three types of tree traversal 6 Preorder (NLR) 6, 2, 1, 4, 3, 7, 10 , 9, 11 b. Postorder (LRN) 1, 3, 4, 2, 9, 11 ,10, 7, 6 c. Inorder (LNR) 1, 2, 3, 4, 6, 7, 9, 10, 11 7 2 1 4 10 3 9 11