Threaded Binary Tree.

Slides:



Advertisements
Similar presentations
Chapter 12 Binary Search Trees
Advertisements

Binary Trees CSC 220. Your Observations (so far data structures) Array –Unordered Add, delete, search –Ordered Linked List –??
S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.
Data Structures: A Pseudocode Approach with C
David Luebke 1 5/4/2015 Binary Search Trees. David Luebke 2 5/4/2015 Dynamic Sets ● Want a data structure for dynamic sets ■ Elements have a key and satellite.
Introduction to Trees. Tree example Consider this program structure diagram as itself a data structure. main readinprintprocess sortlookup.
Data Structures and Algorithms Session 16 Ver. 1.0 Objectives In this session, you will learn to: Implement a threaded binary tree Implement a height balanced.
Chapter 15 B External Methods – B-Trees. © 2004 Pearson Addison-Wesley. All rights reserved 15 B-2 B-Trees To organize the index file as an external search.
Data Structures: Trees i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
Binary Trees Terminology A graph G = is a collection of nodes and edges. An edge (v 1,v 2 ) is a pair of vertices that are directly connected. A path,
©Brooks/Cole, 2003 Chapter 11 Data Structures. ©Brooks/Cole, 2003 Data Structure Data structure uses collection of related variables that can be accessed.
Summary of lectures (1 to 11)
More Trees COL 106 Amit Kumar and Shweta Agrawal Most slides courtesy : Douglas Wilhelm Harder, MMath, UWaterloo
Binary Trees Chapter 6.
Types of Binary Trees Introduction. Types of Binary Trees There are several types of binary trees possible each with its own properties. Few important.
CHAPTER 71 TREE. Binary Tree A binary tree T is a finite set of one or more nodes such that: (a) T is empty or (b) There is a specially designated node.
Foundation of Computing Systems Lecture 6 Trees: Part III.
Tree.
Data Structures - CSCI 102 Binary Tree In binary trees, each Node can point to two other Nodes and looks something like this: template class BTNode { public:
Review Binary Tree Binary Tree Representation Array Representation Link List Representation Operations on Binary Trees Traversing Binary Trees Pre-Order.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 7.
B + TREE. INTRODUCTION A B+ tree is a balanced tree in which every path from the root of the tree to a leaf is of the same length, and each non leaf node.
9/17/20151 Chapter 12 - Heaps. 9/17/20152 Introduction ► Heaps are largely about priority queues. ► They are an alternative data structure to implementing.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Binary Trees Chapter Definition And Application Of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two.
For Monday Read Weiss, chapter 7, sections 1-3. Homework –Weiss, chapter 4, exercise 6. Make sure you include parentheses where appropriate.
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.
Chapter 13 B Advanced Implementations of Tables – Balanced BSTs.
Tree Data Structures.
Binary Tree. Contiguous versus Linked List Insertion in Contiguous list needs a lot of move. For big chunks of records it is time consuming. Linked List.
Tree Implementations Chapter 16 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Lecture 9 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Marwan Al-Namari Hassan Al-Mathami. Indexing What is Indexing? Indexing is a mechanisms. Why we need to use Indexing? We used indexing to speed up access.
Lecture - 10 on Data Structures. 6:05:57 PM Prepared by, Jesmin Akhter, Lecturer, IIT,JU.
Chapter 4: Trees Part I: General Tree Concepts Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
1. Circular Linked List In a circular linked list, the last node contains a pointer to the first node of the list. In a circular linked list,
Types of Binary Trees Expression Tree A binary tree can store anything where the number ‘2’ comes into picture. In an arithmetic expression: So an arithmetic.
Copyright © 2012 Pearson Education, Inc. Chapter 20: Binary Trees.
Linked Lists. Introduction In linked list each item is embedded in a link Each item has two parts – Data – Pointer to the next item in the list Insert,
BINARY TREES A BINARY TREE t IS EITHER EMPTY OR CONSISTS OF AN ITEM, CALLED THE ROOT ITEM, AND TWO DISTINCT BINARY TREES, CALLED THE LEFT SUBTREE AND.
Binary Tree.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 20: Binary Trees.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 20: Binary 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
LINKED LISTS.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
CSE 373 Data Structures Lecture 7
UNIT – I Linked Lists.
Data Structure Interview Question and Answers
Data Structure and Algorithms
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Problems with Linked List (as we’ve seen so far…)
Lecture 22 Binary Search Trees Chapter 10 of textbook
External Methods Chapter 15 (continued)
Tonga Institute of Higher Education
Lecture 7 Algorithm Analysis
Lecture 25 Splay Tree Chapter 10 of textbook
Chapter 20: Binary Trees.
Threaded Trees Binary trees have a lot of wasted space: the leaf nodes each have 2 null pointers We can use these pointers to help us in inorder traversals.
Data Structures Lecture 27 Sohail Aslam.
Chapter 21: Binary Trees.
Lecture 7 Algorithm Analysis
Chapter 12: Binary Search Trees
Lecture 7 Algorithm Analysis
2018, Fall Pusan National University Ki-Joune Li
Binary Search Trees Chapter 7 Objectives
Chapter 20: Binary Trees.
Presentation transcript:

Threaded Binary Tree

Threaded Binary Tree In a linked representation of a binary tree, the number of null links (null pointers) are actually more than non-null pointers. Consider the following binary tree:

Threaded Binary Tree In above binary tree, there are 7 null pointers & actual 5 pointers. In all there are 12 pointers. We can generalize it that for any binary tree with n nodes there will be (n+1) null pointers and 2n total pointers. The objective here to make effective use of these null pointers. A. J. perils & C. Thornton jointly proposed idea to make effective use of these null pointers. According to this idea we are going to replace all the null pointers by the appropriate pointer values called threads.

Threaded Binary Tree And binary tree with such pointers are called threaded tree. In the memory representation of a threaded binary tree, it is necessary to distinguish between a normal pointer and a thread.

Threaded Binary Tree Therefore we have an alternate node representation for a threaded binary tree which contains five fields as show bellow:

Threaded Binary Tree Also one may choose a one-way threading or a two-way threading. Here, our threading will correspond to the in order traversal of T.

Threaded Binary Tree One-Way Accordingly, in the one way threading of T, a thread will appear in the right field of a node and will point to the next node in the in-order traversal of T. See the bellow example of one-way in-order threading.

Threaded Binary Tree: One-Way Inorder of bellow tree is: D,B,F,E,A,G,C,L,J,H,K

Threaded Binary Tree Two-Way In the two-way threading of T. A thread will also appear in the left field of a node and will point to the preceding node in the in-order traversal of tree T. Furthermore, the left pointer of the first node and the right pointer of the last node (in the in-order traversal of T) will contain the null value when T does not have a header node.

Threaded Binary Tree Bellow figure show two-way in-order threading. Here, right pointer=next node of in-order traversal and left pointer=previous node of in-order traversal Inorder of bellow tree is: D,B,F,E,A,G,C,L,J,H,K

Threaded Binary Tree

Threaded Binary Tree Two-way Threading with Header node Again two-way threading has left pointer of the first node and right pointer of the last node (in the inorder traversal of T) will contain the null value when T will point to the header nodes is called two-way threading with header node threaded binary tree.

Threaded Binary Tree Bellow figure to explain two-way threading with header node.

Threaded Binary Tree Bellow example of link representation of threading binary tree. In-order traversal of bellow tree: G,F,B,A,D,C,E

Threaded Binary Tree

Threaded Binary Tree Advantages of threaded binary tree: Threaded binary trees have numerous advantages over non-threaded binary trees listed as below: The traversal operation is more faster than that of its unthreaded version, because with threaded binary tree non-recursive implementation is possible which can run faster and does not require the botheration of stack management.

Threaded Binary Tree Advantages of threaded binary tree: The second advantage is more understated with a threaded binary tree, we can efficiently determine the predecessor and successor nodes starting from any node. In case of unthreaded binary tree, however, this task is more time consuming and difficult. For this case a stack is required to provide upward pointing information in the tree whereas in a threaded binary tree, without having to include the overhead of using a stack mechanism the same can be carried out with the threads.

Threaded Binary Tree Advantages of threaded binary tree: Any node can be accessible from any other node. Threads are usually more to upward whereas links are downward. Thus in a threaded tree, one can move in their direction and nodes are in fact circularly linked. This is not possible in unthreaded counter part because there we can move only in downward direction starting from root. Insertion into and deletions from a threaded tree are although time consuming operations but these are very easy to implement.

Threaded Binary Tree Disadvantages of threaded binary tree: Insertion and deletion from a threaded tree are very time consuming operation compare to non-threaded binary tree. This tree require additional bit to identify the threaded link.