Tree Representation and Terminology Binary Trees Binary Search Trees Pointer-Based Representation of a Binary Tree Array-Based Representation of a Binary.

Slides:



Advertisements
Similar presentations
Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
Advertisements

Binary Trees Chapter 6. Linked Lists Suck By now you realize that the title to this slide is true… By now you realize that the title to this slide is.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
CS 171: Introduction to Computer Science II
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
1 Trees & More Tables (Walls & Mirrors - Chapter 10 & Beginning of 11)
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Marc Smith and Jim Ten Eyck
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Trees.
Binary Trees Chapter 6.
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.
COSC2007 Data Structures II
Tree.
Introduction Of Tree. Introduction A tree is a non-linear data structure in which items are arranged in sequence. It is used to represent hierarchical.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 10: Trees Data Abstraction & Problem Solving with C++
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
Tree A connected graph that contains no simple circuits is called a tree. Because a tree cannot have a simple circuit, a tree cannot contain multiple.
Binary Trees. Binary Tree Finite (possibly empty) collection of elements A nonempty binary tree has a root element The remaining elements (if any) are.
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
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.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Tree Data Structures.
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:
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.
Starting at Binary Trees
Topics Definition and Application of Binary Trees Binary Search Tree Operations.
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.
Discrete Mathematics Chapter 5 Trees.
Binary Tree. Some Terminologies Short review on binary tree Tree traversals Binary Search Tree (BST)‏ Questions.
Trees Chapter 10. CS 308 2Chapter Trees Preview: Preview: The data organizations presented in previous chapters are linear, in that items are one.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
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:
Trees (Unit 7).
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 General trees Binary trees Binary search trees AVL trees Balanced and Threaded trees.
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.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
Binary Trees.
CSCE 210 Data Structures and Algorithms
Binary Trees.
CS 302 Data Structures Trees.
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Tree.
Csc 2720 Instructor: Zhuojun Duan
Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb.
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
Binary Trees.
Binary Trees.
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Binary Trees, Binary Search Trees
Trees Chapter 10.
Trees.
Binary Trees.
Chapter 20: Binary Trees.
Binary Trees.
Binary Trees, Binary Search Trees
Data Structures Using C++ 2E
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
NATURE VIEW OF A TREE leaves branches root. NATURE VIEW OF A TREE leaves branches root.
Presentation transcript:

Tree Representation and Terminology Binary Trees Binary Search Trees Pointer-Based Representation of a Binary Tree Array-Based Representation of a Binary Tree

A tree is a collection of nodes and directed edges, satisfying the following properties: –There is one specially designated node called the root, which has no edges pointing to it. –Every node except the root has exactly one edge pointing to it. –There is a unique path (of nodes and edges) from the root to each node.

Trees, as defined on the preceding slide, are typically drawn with circles (or rectangles) representing the nodes and arrows representing the edges. The root is typically placed at the top of the diagram, with the rest of the tree below it. Trees : Not Trees : root edge node Leaf nodes

If an edge goes from node a to node b, then a is called the parent of b, and b is called a child of a. Children of the same parent are called siblings. If there is a path from a to b, then a is called an ancestor of b, and b is called a descendent of a. A node with all of its descendants is called a subtree. If a node has no children, then it is called a leaf of the tree. If a node has no parent (there will be exactly one of these), then it is the root of the tree.

A BC DE F GH I JK A is the root D, E, G, H, J & K are leaves B is the parent of D, E & F D, E & F are siblings and children of B I, J & K are descendants of B A & B are ancestors of I subtree

Intuitively, a binary tree is LIKE a tree in which each node has no more than two children. Formally, a binary tree is a set T of nodes such that either: – T is empty, or –T consists of a single node, r, called the root, and two (non- overlapping) binary trees, called the left and right subtrees of r. UNLIKE trees, binary trees may be empty, and they distinguish between left and right subtrees. (These two binary trees are distinct.)

Data Left_child Right_child Data null Data null Data null Data null Data Left_child Right_child Data Left_child Right_child Root

A binary search tree is a binary tree in which each node, n, has a value satisfying the following properties: –n’s value is > all values in its left subtree, T Left, –n’s value is < all values in its right subtree, T Right, and –T Left and T Right are both binary search trees. John Peter Brenda AmyMaryTom

Intuitively, the level of a node is the number of nodes on a path from the root to the node. Formally, level of node, n: – If n is the root of a tree, then it is at level 1. – Otherwise, its level is 1 greater than the level of its parent. Height of binary tree, T: – If T is empty, its height is 0. – Otherwise, its height is the maximum level of its nodes, or, equivalently, 1 greater than the height of the root’s taller subtree. Namely, height(T) = 1 + max { height( T Left ), height(T Right ) }

Intuitively, a binary tree is full if it has no missing nodes. Formally, a binary tree of height h is full if – It is empty (h = 0). – Otherwise, the root’s subtrees are full binary trees of height h – 1. If not empty, each node has 2 children, except the nodes at level h which have no children. Alternatively, the binary tree has all of its leaves at level h.

Intuitively, a binary tree of height h is complete if it is full down to level h – 1, and level h is filled from left to right. Formally, a binary tree of height h is complete if – All nodes at level h – 2 and above have 2 children each, – If a node at level h – 1 has children, all nodes to its left at the same level have 2 children each, and – If a node at level h – 1 has 1 child, it is a left child.

A binary tree is balanced if the difference in height between any node’s left and right subtree is  1. Note that: –A full binary tree is also complete. –A complete binary tree is not always full. –Full and complete binary trees are also balanced. –Balanced binary trees are not always full or complete.

Different operations on a Tree are as follows – Insertion – Deletion – Searching – Traversal  Pre-Order  In-Order  Post- Order Please follow the Power Point Presentations on Insertion, Deletion and Traversal using Binary Search Tree.