Lecture 18. Basics and types of Trees

Slides:



Advertisements
Similar presentations
COSC2007 Data Structures II Chapter 10 Trees I. 2 Topics Terminology.
Advertisements

Trees Types and Operations
Introduction to Trees Chapter 6 Objectives
Data Structures: A Pseudocode Approach with C 1 Chapter 6 Objectives Upon completion you will be able to: Understand and use basic tree terminology and.
1 abstract containers hierarchical (1 to many) graph (many to many) first ith last sequence/linear (1 to 1) set.
TREES Chapter 6. Trees - Introduction  All previous data organizations we've studied are linear—each element can have only one predecessor and successor.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
1 abstract containers hierarchical (1 to many) graph (many to many) first ith last sequence/linear (1 to 1) set.
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.
COSC2007 Data Structures II
Advanced Algorithms Analysis and Design Lecture 8 (Continue Lecture 7…..) Elementry Data Structures By Engr Huma Ayub Vine.
Ceng-112 Data Structures I 1 Chapter 7 Introduction to Trees.
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.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
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.
Data Structures and Algorithms Lecture (BinaryTrees) Instructor: Quratulain.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
TREES. What is a tree ? An Abstract Data Type which emulates a tree structure with a set of linked nodes The nodes within a tree are organized in a hierarchical.
Data Structures TREES.
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
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.
Foundation of Computing Systems Lecture 4 Trees: Part I.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
Tree Representation and Terminology Binary Trees Binary Search Trees Pointer-Based Representation of a Binary Tree Array-Based Representation of a Binary.
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.
Instructor: Lilian de Greef Quarter: Summer 2017
Chapter 12 Abstract Data Type.
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Data Structures and Design in Java © Rick Mercer
Trees Chapter 15.
CSCE 210 Data Structures and Algorithms
Lecture 1 (UNIT -4) TREE SUNIL KUMAR CIT-UPES.
Tree.
Chapter 5 : Trees.
Lecture Trees Chapter 9 of textbook 1. Concepts of trees
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Tree.
Section 8.1 Trees.
Tree traversal from Introduction to Trees Chapter 6 Objectives
Data Structures & Algorithm Design
abstract containers sequence/linear (1 to 1) hierarchical (1 to many)
Binary Trees, Binary Search Trees
Binary Tree and General Tree
Chapter 7 TREES.
TREES General trees Binary trees Binary search trees AVL trees
Introduction to Trees IT12112 Lecture 05.
Trees 7/14/2009.
Trees and Binary Trees.
Find in a linked list? first last 7  4  3  8 NULL
Trees.
(2,4) Trees (2,4) Trees (2,4) Trees.
CSE 373, Copyright S. Tanimoto, 2002 Binary Trees -
CMSC 202 Trees.
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Binary Trees, Binary Search Trees
Trees.
CSE 373, Copyright S. Tanimoto, 2001 Binary Trees -
(2,4) Trees (2,4) Trees (2,4) Trees.
Tree.
Binary Trees.
Binary Trees, Binary Search Trees
8.2 Tree Traversals Chapter 8 - Trees.
Introduction to Trees Chapter 6 Objectives
Tree (new ADT) Terminology: A tree is a collection of elements (nodes)
Presentation transcript:

Lecture 18. Basics and types of Trees

Hash function can map integer or string key into integer address. Recap The function of hashing is to map a key into an index To support insertion, deletion and search in average-case constant time. The performance of hashing technique depends on the designing of hash function. Hash function can map integer or string key into integer address. When more than one key map into single index then collision occur. Linear probing, quadratic probing, chaining and rehashing are techniques to reduce collision.

Basic Tree Concepts A tree consists of finite set of elements, called nodes, and a finite set of directed lines called branches, that connect the nodes. The number of branches associated with a node is the degree of the node.

Basic Tree Concepts When the branch is directed toward the node, it is indegree branch. When the branch is directed away from the node, it is an outdegree branch. The sum of the indegree and outdegree branches is the degree of the node. If the tree is not empty, the first node is called the root.

Basic Tree Concepts The indegree of the root is, by definition, zero. With the exception of the root, all of the nodes in a tree must have an indegree of exactly one; that is, they may have only one predecessor. All nodes in the tree can have zero, one, or more branches leaving them; that is, they may have outdegree of zero, one, or more.

Basic Tree Concepts A leaf is any node with an outdegree of zero, that is, a node with no successors. A node that is not a root or a leaf is known as an internal node. A node is a parent if it has successor nodes; that is, if it has outdegree greater than zero. A node with a predecessor is called a child.

Basic Tree Concepts Two or more nodes with the same parents are called siblings. An ancestor is any node in the path from the root to the node. A descendant is any node in the path below the parent node; that is, all nodes in the paths from a given node to a leaf are descendants of that node.

Basic Tree Concepts A path is a sequence of nodes in which each node is adjacent to the next node. The level of a node is its distance from the root. The root is at level 0, its children are at level 1, etc. …

Basic Tree Concepts The height of the tree is the level of the leaf in the longest path from the root plus 1. By definition the height of any empty tree is -1. A subtree is any connected structure below the root. The first node in the subtree is known is the root of the subtree.

Recursive definition of a tree A tree is a set of nodes that either: is empty or has a designated node, called the root, from which hierarchically descend zero or more subtrees, which are also trees.

Tree Representation General Tree – organization chart format Indented list – bill-of-materials system in which a parts list represents the assembly structure of an item

Parenthetical Listing Parenthetical Listing – the algebraic expression, where each open parenthesis indicates the start of a new level and each closing parenthesis completes the current level and moves up one level in the tree.

Parenthetical Listing A (B (C D) E F (G H I) )

Binary Trees A binary tree can have no more than two descendents. In this section we discuss the properties of binary trees, four different binary tree traversals Properties Binary Tree Traversals Expression Trees Huffman Code

Binary Trees A binary tree is a tree in which no node can have more than two subtrees; the maximum outdegree for a node is two. In other words, a node can have zero, one, or two subtrees. These subtrees are designated as the left subtree and the right subtree.

A null tree is a tree with no nodes

Some Properties of Binary Trees The height of binary trees can be mathematically predicted Given that we need to store N nodes in a binary tree, the maximum height is A tree with a maximum height is rare. It occurs when all of the nodes in the entire tree have only one successor.

Some Properties of Binary Trees The minimum height of a binary tree is determined as follows: For instance, if there are three nodes to be stored in the binary tree (N=3) then Hmin=2.

Some Properties of Binary Trees Given a height of the binary tree, H, the minimum number of nodes in the tree is given as follows:

Some Properties of Binary Trees The formula for the maximum number of nodes is derived from the fact that each node can have only two descendents. Given a height of the binary tree, H, the maximum number of nodes in the tree is given as follows:

Some Properties of Binary Trees The children of any node in a tree can be accessed by following only one branch path, the one that leads to the desired node. The nodes at level 1, which are children of the root, can be accessed by following only one branch; the nodes of level 2 of a tree can be accessed by following only two branches from the root, etc. The balance factor of a binary tree is the difference in height between its left and right subtrees:

Balance of the tree B=0 B=0 B=1 B=-1 B=1 B=0 B=-2 B=2

Some Properties of Binary Trees In the balanced binary tree (definition of Russian mathematicians Adelson-Velskii and Landis) the height of its subtrees differs by no more than one (its balance factor is -1, 0, or 1), and its subtrees are also balanced.

Complete and nearly complete binary trees A complete tree has the maximum number of entries for its height. The maximum number is reached when the last level is full. A tree is considered nearly complete if it has the minimum height for its nodes and all nodes in the last level are found on the left

Binary Tree Traversal A binary tree traversal requires that each node of the tree be processed once and only once in a predetermined sequence. In the depth-first traversal processing process along a path from the root through one child to the most distant descendant of that first child before processing a second child.

It is also called acyclic data structure. Summary Tree is a non linear data structure to present data in hierarchical form. It is also called acyclic data structure. The main component of a tree are node , branches, level, family (subtree) and path. A node may be used as root, parent, left, brother, predecessor , successor and leaf node. If every node of a tree have 0, 1 or 2 child it is called binary tree. There ar different traversing method of tree such as inorder, pre order and post order.

In Next Lecturer In next lecture, we will discuss about binary search tree and its algorithms