General Trees A general tree T is a finite set of zero or more nodes such that there is one designated node r, called the root of T, and the remaining.

Slides:



Advertisements
Similar presentations
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R4. Disjoint Sets.
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.
Computer Science C++ High School Level By Guillermo Moreno.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Introduction to Data Structure, Spring 2007 Slide- 1 California State University, Fresno Introduction to Data Structure Introduction of Concepts Ming Li.
Binary Tree Properties & Representation. Minimum Number Of Nodes Minimum number of nodes in a binary tree whose height is h. At least one node at each.
Joseph Lindo Trees Sir Joseph Lindo University of the Cordilleras.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Trees.
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.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Trees CS212 & CS-240 D.J. Foreman. What is a Tree A tree is a finite set of one or more nodes such that: –There is a specially designated node called.
Sets of Digital Data CSCI 2720 Fall 2005 Kraemer.
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
Lecture - 10 on Data Structures. 6:05:57 PM Prepared by, Jesmin Akhter, Lecturer, IIT,JU.
Binary Tree 10/22/081. Tree A nonlinear data structure Contain a distinguished node R, called the root of tree and a set of subtrees. Two nodes n1 and.
Binary Search Trees Lecture 5 1. Binary search tree sort 2.
General Trees A tree T is a finite set of one or more nodes such that there is one designated node r called the root of T, and the remaining nodes in (T-{r})
Binary Tree.
Foundation of Computing Systems Lecture 4 Trees: Part I.
 Array is a data structure were elements are stored in consecutive memory location.in the array once the memory is allocated.it cannot be extend any more.
Trees CSIT 402 Data Structures II 1. 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical.
CSE 373 Data Structures Lecture 7
Partially Ordered Data ,Heap,Binary Heap
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
AA Trees.
Recursive Objects (Part 4)
Data Structure Interview Question and Answers
CS522 Advanced database Systems
Binary search tree. Removing a node
Problems with Linked List (as we’ve seen so far…)
Trees 8/7/2018 2:27 PM Binary Trees © 2010 Goodrich, Tamassia Trees.
Best-fit bin packing in O(n log n) time
Trees Another Abstract Data Type (ADT)
Lecture 22 Binary Search Trees Chapter 10 of textbook
Csc 2720 Instructor: Zhuojun Duan
Trees Trees are a very useful data structure. Many different kinds of trees are used in Computer Science. We shall study just a few of these.
CSE 373 Data Structures Lecture 7
External Methods Chapter 15 (continued)
Binary Trees, Binary Search Trees
Chapter 20: Binary Trees.
TREES General trees Binary trees Binary search trees AVL trees
Chapter 21: Binary Trees.
Trees and Binary Trees.
Chapter 15 Lists Objectives
Binary Heaps Text Binary Heap Building a Binary Heap
Arrays and Linked Lists
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Trees CSE 373 Data Structures.
Trees Another Abstract Data Type (ADT)
Data Structures: Trees and Binary Trees
Trees & Forests D. J. Foreman.
Forests D. J. Foreman.
Trees Another Abstract Data Type (ADT)
CMSC 202 Trees.
Higher Order Tries Key = Social Security Number.
CS-240 Dick Steflik D.J. Foreman
Binary Trees: Motivation
Binary Trees, Binary Search Trees
Trees.
Binary Tree Properties & Representation
Tree.
Chapter 20: Binary Trees.
LINKED LIST Dr. T. Kokilavani Assistant Professor
Trees CSE 373 Data Structures.
Trees CSE 373 Data Structures.
Binary Trees, Binary Search Trees
General Trees A general tree T is a finite set of one or more nodes such that there is one designated node r, called the root of T, and the remaining nodes.
NATURE VIEW OF A TREE leaves branches root. NATURE VIEW OF A TREE leaves branches root.
Presentation transcript:

General Trees A general tree T is a finite set of zero or more nodes such that there is one designated node r, called the root of T, and the remaining nodes are partitioned into n  0 disjoint subsets T1, T2, …, Tn, each of which is a tree, and whose roots r1, r2, …, rn, respectively, are children of r. r r1 r2 r3 Computer Science Dept Va Tech December 2005 ©2000-2005 McQuain WD

Representing General Trees The representation of a general tree poses some hard choices: - May the number of children per node vary over a large range (possibly with no logical upper limit)? - Setting an upper limit renders some trees unrepresentable. - Even with an upper limit, allocating a fixed number of pointers within each node may waste a huge amount of space. - Supporting a variable number of pointers also raises performance issues. - How can the pointers be organized for easy traversal? Does this require a secondary data structure within the node? - Does the scheme provide for efficient search? node insertion? node deletion? r Computer Science Dept Va Tech December 2005 ©2000-2005 McQuain WD

Linked Nodes Implementation The binary node type presented earlier can be extended for a general tree representation. The pointers can be managed by: - allocating a uniform-sized array of node pointers and limiting the number of children a node is allowed to have; - allocating a dynamically-sized array of node pointers, custom-fit to the number of children the node currently has (and re-sizing manually as needed); - using a linked list of node pointers; - using a vector of node pointers, growing as needed. Each approach has pros and cons. r Computer Science Dept Va Tech December 2005 ©2000-2005 McQuain WD

List of Children Representation For each tree node, store its data element, a (logical) pointer to its parent node, and a list of (logical) pointers to its children, using a array as the underlying physical structure: Data Par Chld a null 1 b 2 c 3 d 4 e 5 f 6 g 1 2  3 4 5 6 a c g f e d b Could use a dynamic list of nodes instead… Computer Science Dept Va Tech December 2005 ©2000-2005 McQuain WD

Left-Children/Right-Sibling Representation For each tree node, store its data element, a (logical) pointer to its parent node, and (logical) pointers to its left child and its right sibling, using a array as the underlying physical structure: Data Par Left Child Right Sibling a null 1 b 3 2 c 6 d 4 e 5 f g a c g f e d b Computer Science Dept Va Tech December 2005 ©2000-2005 McQuain WD

Parent Pointer Representation For each tree node, store its data element and a (logical) pointer to its parent node, using a array as the underlying physical structure: a null 1 b 2 c 3 d 4 e 5 f 6 g a c g f e d b Computer Science Dept Va Tech December 2005 ©2000-2005 McQuain WD