Trees. Dr. Ronaldo Menezes Hugo Serrano Ronaldo Menezes, Florida Tech

Size: px
Start display at page:

Download "Trees. Dr. Ronaldo Menezes Hugo Serrano Ronaldo Menezes, Florida Tech"

Transcription

1 Trees Dr. Ronaldo Menezes Hugo Serrano

2 Introduction to Trees Trees are very common in computer science They come in different variations They are used as data representation in many applications They appear frequently in several algorithmic solution

3 Trees Set of nodes (vertices) and edges (arcs) that connect the nodes together Nodes

4 Trees Set of nodes (vertices) and edges (arcs) that connect the nodes together Edges

5 Trees Set of nodes (vertices) and edges (arcs) that connect the nodes together A path is connected sequence of edges Path

6 Trees Set of nodes (vertices) and edges (arcs) that connect the nodes together A path is connected sequence of edges There is exactly one path between any two nodes in a tree. There is no cycles in trees Path

7 Trees Trees may have one distinguished node called the root These trees are called rooted trees. A tree with no root is called free tree. Rooted Tree

8 Trees The convention is draw the root on the top. In a rooted tree, any node is the root of a subtree. root of subtree Root A subtree

9 Relationships between nodes

10 Relationships between nodes Inspiration from family trees to determine relationships between nodes: Parent Node Children Siblings Ancestor Grandparents

11 Relationships between nodes Relationships Inspiration from family trees to name relationships between nodes: Parent Node Children Siblings Ancestors Parent node Every node except the root has one parent. The parent is the first node on path from a node to the root. Root has no parent If the node p is the c s parent, node c is p s child

12 Relationships between nodes Relationships Inspiration from family trees to name relationships between nodes: Parent Node Children Siblings Ancestors Leaf node A node can have any number of children Nodes with no children are called leaf nodes

13 Relationships between nodes Relationships Inspiration from family trees to name relationships between nodes: Parent Node Children Siblings Ancestors Siblings Nodes that have the same parent.

14 Relationships between nodes Relationships Inspiration from family trees to name relationships between nodes: Parent Node Children Siblings Ancestors Ancestors Nodes on the path from the node to the root including the root. A node is an ancestor of itself. If a node a is an ancestor of a node b, than b is a descendant of a.

15 Structural Properties Property Length of a path Depth of a node Height of a node Height of the tree Subtree rooted at a node Length of a Path Number of edges in a path

16 Structural Properties Property Length of a path Depth of a node Height of a node Height of the tree Subtree rooted at a node Depth of a node Length of the path from the node to the root

17 Structural Properties Property Length of a path Depth of a node Height of a node Height of the tree Subtree rooted at a node Height of a node Length of the path from the node to its deepest descendant.

18 Structural Properties Property Length of a path Depth of a node Height of a node Height of the tree Subtree rooted at a node Height of the tree Height of the root

19 Structural Properties Property Length of a path Depth of a node Height of a node Height of the tree Subtree rooted at a node Subtree rooted at a node Tree formed by the node a and all its descendants

20 Alternate Tree Representation There are several ways to represent a tree. Using the definition based on sets we could say that: T = {A, {G,{Y}}, {P,{K},{L}}, {W,{T},{C},{B}}} A A G P W Y K L T C B G P W Y K T C L B

21 Trees with Specific Number of Children

22 Trees with Specific Number of Children Binary Tree Each node has at most two children Quadree One left child One right child At most 4 children Octree At most 8 children M-ary tree At most M children

23 M-ary tree Examples Quadtree

24 M-ary tree Examples Octree

25 M-ary tree Examples Octree

26 The Tree Abstract Data Type Generic methods size(), isempty(), enumerate() Positional methods swapelement(p,q), replaceelement(p,n) Query methods isroot(), isleaf() Accessor methods root(), parent() children() Update methods() insert(p), delete(p)

27 The Tree Abstract Data Type parent Element childrencollection

28 Structure of a Binary Tree Node Nodes in binary trees have structure similar to linked list. Rather than a next and previous pointers, they maintain the following: Right: pointer the root of the right subtree Left: pointer to the the root of the left subtree Parent: pointer to the parent node parent left DATA right

29 Tree Traversal

30 Traversing Trees In general there are two ways of traversing trees Depth-based traversal: Level-order traversall

31 Cases of Depth-based Traversal There are three basic ways to traverse a tree using the a depth-based approach Preorder Inorder This search is better associated with binary trees Postorder This is what normally authors mean if they mention just depth-first search in the context of trees

32 Preorder Traversal A B C D E F G H I

33 Preorder Traversal A B C D E F G H I Result: A

34 Preorder Traversal A B C D E F G H I Result: AB

35 Preorder Traversal A B C D E F G H I Result: ABD

36 Preorder Traversal A B C D E F G H I Result: ABDE

37 Preorder Traversal A B C D E F G H I Result: ABDEH

38 Preorder Traversal A B C D E F G H I Result: ABDEHC

39 Preorder Traversal A B C D E F G H I Result: ABDEHCF

40 Preorder Traversal A B C D E F G H I Result: ABDEHCFG

41 Preorder Traversal A B C D E F G H I Result: ABDEHCFGI

42 Preorder Algorithm void preorder(tree t) { if (t!= null) { visit(t) preorder(t.getleft()) preorder(t.getright()) } }

43 Inorder Traversal A B C D E F G H I

44 Inorder Traversal A B C D E F G H I

45 Inorder Traversal A B C D E F G H I

46 Inorder Traversal A B C D E F G H I Result: D

47 Inorder Traversal A B C D E F G H I Result: DB

48 Inorder Traversal A B C D E F G H I Result: DB

49 Inorder Traversal A B C D E F G H I Result: DBH

50 Inorder Traversal A B C D E F G H I Result: DBHE

51 Inorder Traversal A B C D E F G H I Result: DBHEA

52 Inorder Traversal A B C D E F G H I Result: DBHEA

53 Inorder Traversal A B C D E F G H I Result: DBHEAF

54 Inorder Traversal A B C D E F G H I Result: DBHEAFC

55 Inorder Traversal A B C D E F G H I Result: DBHEAFCG

56 Inorder Traversal A B C D E F G H I Result: DBHEAFCGI

57 Inorder Algorithm void inorder(tree t) { if (t!= null) { inorder(t.getleft()) visit(t) inorder(t.getright()) } }

58 Postorder Traversal A B C D E F G H I

59 Postorder Traversal A B C D E F G H I Result:

60 Postorder Traversal A B C D E F G H I Result:

61 Postorder Traversal A B C D E F G H I Result: D

62 Postorder Traversal A B C D E F G H I Result: D

63 Postorder Traversal A B C D E F G H I Result: DH

64 Postorder Traversal A B C D E F G H I Result: DHE

65 Postorder Traversal A B C D E F G H I Result: DHEB

66 Postorder Traversal A B C D E F G H I Result: DHEB

67 Postorder Traversal A B C D E F G H I Result: DHEBF

68 Postorder Traversal A B C D E F G H I Result: DHEBF

69 Postorder Traversal A B C D E F G H I Result: DHEBFI

70 Postorder Traversal A B C D E F G H I Result: DHEBFIG

71 Postorder Traversal A B C D E F G H I Result: DHEBFIGC

72 Postorder Traversal A B C D E F G H I Result: DHEBFIGCA

73 Postorder Algorithm void postorder(tree t) { if (t!= null) { postorder(t.getleft()) postorder(t.getright()) visit(t) } }

74 Generic Traversal The depth-based traversals described are just a special case of the generic traversal for binary trees The Euler Tour Traversal It consists of walking around the tree and visiting each edge exactly 2 times times (or each node 3 times) A B C D E F G U P H R X N Q I W L

75 Level-order traversal A B C D E F G H I

76 Level-order traversal A B C D E F G H I Result: A

77 Level-order traversal A B C D E F G H I Result: AB

78 Level-order traversal A B C D E F G H I Result: ABC

79 Level-order traversal A B C D E F G H I Result: ABCD

80 Level-order traversal A B C D E F G H I Result: ABCDE

81 Level-order traversal A B C D E F G H I Result: ABCDEF

82 Level-order traversal A B C D E F G H I Result: ABCDEFG

83 Level-order traversal A B C D E F G H I Result: ABCDEFGH

84 Level-order traversal A B C D E F G H I Result: ABCDEFGHI

85 Full & Complete Trees A full binary tree is binary tree in which each node has exactly zero or two children. A perfect binary tree is one in which all the nodes except the leaves have exactly two children and all leaves are at the same level. A complete binary tree is one that is either full or full up to the last but one level, and have all the nodes in the bottommost level shifted to the left. A complete tree An incomplete tree

86 Array Implementation of Binary Trees There are several ways to implement a binary tree. Although it may appear that we must use pointers, this is not mandatory and other implementations may be more efficient depending on the tree structure. One way to represent binary trees is using arrays. For this to be possible we need to number the elements in such a way that operations to find the other nodes can be done in a systematic way One of best way to number the elements (nodes) is using a level-ordering approach. Start from the topmost number the node with 1, move down to the next level and number the nodes with 2 and 3 starting from the left, repeat the process until there are no more levels Similar to what level-order traversal does. Sequential representation is more cost-effective when the tree is complete

87 Level Order of a Binary Tree Given a complete binary tree as below if we perform the level-by-level numbering we get... Z F S G J H Q X C P

88 Level Order of a Binary Tree Given a complete binary tree as below if we perform the level-by-level numbering we get the level order numbering of all nodes. 1 2 Z 3 4 F 5 6 S 7 8 X G 9 C 1 0 P J H Q

89 Implementing Trees with Arrays By ordering a complete binary tree using level ordering we can see the relationship of the order and indexes of an array as below: Z F S G J H Q X C P Given the structure above, how do we find the nodes of the binary tree? 5 To find Use Provided The left child of bt[i] bt[2 * i] 2 * i <= n The right child of bt[i] bt[2 * i + 1] 2 * i + 1 <= n The parent of bt[i] bt[i / 2] i > 1 The root bt[1] bt is non-empty Whether bt[i] is leaf TRUE 2 * i > n

90 Binary Search Trees BSTs are binary trees where the nodes are organized as follows: All the elements in the left subtree of a node are less than the node All the elements in the right subtree of a node are greater than the node Both left and right subtrees are BSTs, meaning they have to conform to these properties Based on the description above you can see that BSTs do not accept repeated elements. The elements are all unique in value

91 Implementing Binary Search Trees The structure of a node for a binary search tree is very much like the structure for a doubly linked list. The main difference is that now from each node the references are interpreted differently: they are left or right This leads to the following definition for a node in a binary search tree (integer tree in this case) class NodeType { int data; // or other type NodeType left; NodeType right; NodeType parent; }

92 Searching in Binary Search Trees Searching is the reason we have BSTs. Like most operations in a BST, search is better described in a recursive fashion. The pseudo-code below describe the idea search (target) 1. If head of the tree is null return null; 2. Test whether the target is the same as the key in the head of the tree and return a pointer to the head if true 3. If not true, if target is less than the key in the head return the search of the target in the left subtree 4. If target is greater than the key in the head return the search of the target in the right subtree

93 search(10)

94 search(10)

95 search(10)

96 search(10)

97 search(10)

98 search(10)

99 search in (quasi-)java // Simplified idea of searching a binary search tree // You may (or may not) need to account for "special" // cases. Also the syntax is not necessarily correct it is simplified // to improve clarity NodeType search (NodeType link, int target) { if (link == null) return null; if (target == link.data) // Found the node return link; if (target < link.data) return search(link.left,target); // Try the left subtree else return search(link.right,target); // Try the right subtree }

100 Insertion in Binary Search Trees To insert an element in a BST we follow the same principle applied in the searching. Compare the value to be inserted with the current key and decide if the new element should be inserted on the left or on the right The element is always inserted as a leaf in the tree. insert (target) 1. If head of the tree is null create new node to store target; 2. Test whether the target is the same as the key in the head of the tree and return null (this means that the element cannot be added to the tree) 3. If not true, if target is less than the key in the head insert the target in the in the left subtree 4. If target is greater than the key in the head insert the target in the right subtree

101 insert(14)

102 insert(14)

103 insert(14)

104 insert(14)

105 insert(14)

106 Find Maximum Find maximum is another common operation in binary search trees and is helpful when implementing deletion. Again the recursive thinking makes this implementation much easier to understand The idea is simple. If a node has a non-null pointer to the right this node cannot be the maximum as the element in the right must be greater. findmax () 1. If head of the tree is null return null; 2. If the right pointer from the head is null head is the maximum 3. Else (it is not null) return the result of findmax in the right subtree

107 Find Minimum The idea of finding the minimum value in a binary search tree will also help the delete operation Its idea is very much like the maximum findmin () 1. If head of the tree is null return null; 2. If the left pointer from the head is null head is the minimum 3. Else (it is not null) return the result of findmin in the left subtree

108 Delete Deletion in BST is probably the least easy of the algorithms. The reason is that nodes can be deleted from anywhere, not only leaves. When inserting we know that we're not dealing with internal nodes and this make it straightforward When deleting a node we have two cases Deleting a leaf. This is easy. Since a leaf does not point to any other node we can just remove it from the tree Deleting from a internal node involves moving nodes around. The reason for this is that after the deletion the tree must still hold its's main property Let's see some examples

109 delete(10)

110 delete(10)

111 delete(10)

112 delete(10)

113 delete(10)

114 delete(10)

115 delete(9)

116 delete(9)

117 delete(9) What we need is move elements around so that the tree does not become disconnected and we keep the property of a BST This is not an option. You can see if we do this the tree is disconnected and we lose this part of the tree

118 delete(9) We can try to find an element below 9 that can be used in the position where 9 is If we want to maintain the property of the tree we have to options: either the maximum element of the left subtree or the minimum element of the right subtree

119 delete(9) Let us choose this one

120 delete(9) The number 3 is copied to the node where 9 was.

121 delete(9) This does not solve the problem because we now have two elements with the same value

122 delete(9) But we can solve the problem by deleting the number 3 from the left subtree of the current node (also 3)

123 delete(9)

124 delete(9)

125 delete(9)

126 Delete Delete can be made very simple if we implement functions like findmax, findmin and isleaf This code should make you appreciate recursion since it simplifies the job of deleting a node quite a lot. These function are used when deciding what to do. Using what we've discussed we can defined a pseudo-code for delete The elements return from findmax and findmin are equivalent to the in-order predecessor and in-order successor of the node being deleted.

127 Delete pseudo-code void delete (head,target) { if (head == null) return; if (target < head.key) delete (head.left,target); else if (target > head.key) delete(head.right,target); // element not in the list else delete if (isleaf(head)) { remove head from the tree else if (head.left!= null) { int max = findmax(head.left); head.key = max; delete(head.left,max); } else { int min = findmin(head.right); head.key = min; delete(head.right,min); } } // found the element to

128 Final comments about BSTs Desirable characteristics of a BST Most of operations can be done in O(h), where h is the height of the tree. In a random generated tree height is normally O (log n), where n is the number of nodes in the tree It can be used to help in other operations. For instance, sort a list. Undesirable characteristics The main one is that it may become unbalanced (possibly leading to something that looks like a linked list) which degrades all operations. To solve this problem we'll look at balanced trees Most of your operations are better understood recursively and we know that recursion is more expensive than iterative solutions

129 BST Exercise The concept of BST is quite common by interviewers because it is a simple concept and yet requires some thinking for some problems. Take for instance the following problem (which has been asked in at least 3 interview instances that I know of) The problem is Given an ordinary binary tree, test whether it is a BST.

130 Solution 1 Using findmin() and findmax() This is a modified version of findmax and findmin. Not the one described earlier. The tree may not be a BST. boolean isbst(tree node) { if (node==null) return true; // false if the max of the left is > than the current node if ((node.getleft()!=null) && ( findmax(node.getleft()) >= node.getvalue())) return false; // false if the min of the right is < than the current node if ((node.getright()!=null) && (findmin(node.getright()) <= node.getvalue())) return false; // false if the left node or right node are not a BST if (!isbst(node.getleft())!isbst(node.getright())) return false; // it is a BST if it gets here return true; }

131 Solution 2 Uses range of values. More efficient!!! int isbst(tree node) { // assuming MIN_VALUE and MAX_VALUE cannot be in the tree return isbstrange(node, MIN_VALUE, MAX_VALUE); } int isbstrange(tree node, int min, int max) { if (node==null) return true; // false if this value in current node violates the range constraints if (node.getvalue() <= min node.getvalue() => max) return false; // check the subtrees recursively, // range has to be modified with new range return isbstrange(node.getleft(), min, node.getvalue()) && isbstrange(node.getright(), node.getvalue(), max); }

132 Solution 3 I ll let you write the code. Do the inorder traversal of the tree and verify if the result is a sorted list.

Binary Trees, Binary Search Trees

Binary Trees, Binary Search Trees Binary Trees, Binary Search Trees Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search, insert, delete)

More information

Trees. (Trees) Data Structures and Programming Spring / 28

Trees. (Trees) Data Structures and Programming Spring / 28 Trees (Trees) Data Structures and Programming Spring 2018 1 / 28 Trees A tree is a collection of nodes, which can be empty (recursive definition) If not empty, a tree consists of a distinguished node r

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 11: Binary Search Trees MOUNA KACEM mouna@cs.wisc.edu Fall 2018 General Overview of Data Structures 2 Introduction to trees 3 Tree: Important non-linear data structure

More information

Binary Trees

Binary Trees Binary Trees 4-7-2005 Opening Discussion What did we talk about last class? Do you have any code to show? Do you have any questions about the assignment? What is a Tree? You are all familiar with what

More information

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010 Uses for About Binary January 31, 2010 Uses for About Binary Uses for Uses for About Basic Idea Implementing Binary Example: Expression Binary Search Uses for Uses for About Binary Uses for Storage Binary

More information

TREES. Trees - Introduction

TREES. Trees - Introduction TREES Chapter 6 Trees - Introduction All previous data organizations we've studied are linear each element can have only one predecessor and successor Accessing all elements in a linear sequence is O(n)

More information

Trees. CSE 373 Data Structures

Trees. CSE 373 Data Structures Trees CSE 373 Data Structures Readings Reading Chapter 7 Trees 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical relationships File directories

More information

Tree Structures. Definitions: o A tree is a connected acyclic graph. o A disconnected acyclic graph is called a forest

Tree Structures. Definitions: o A tree is a connected acyclic graph. o A disconnected acyclic graph is called a forest Tree Structures Definitions: o A tree is a connected acyclic graph. o A disconnected acyclic graph is called a forest o A tree is a connected digraph with these properties: There is exactly one node (Root)

More information

Algorithms in Systems Engineering ISE 172. Lecture 16. Dr. Ted Ralphs

Algorithms in Systems Engineering ISE 172. Lecture 16. Dr. Ted Ralphs Algorithms in Systems Engineering ISE 172 Lecture 16 Dr. Ted Ralphs ISE 172 Lecture 16 1 References for Today s Lecture Required reading Sections 6.5-6.7 References CLRS Chapter 22 R. Sedgewick, Algorithms

More information

Garbage Collection: recycling unused memory

Garbage Collection: recycling unused memory Outline backtracking garbage collection trees binary search trees tree traversal binary search tree algorithms: add, remove, traverse binary node class 1 Backtracking finding a path through a maze is an

More information

Algorithms and Data Structures

Algorithms and Data Structures Lesson 3: trees and visits Luciano Bononi http://www.cs.unibo.it/~bononi/ (slide credits: these slides are a revised version of slides created by Dr. Gabriele D Angelo) International

More information

A set of nodes (or vertices) with a single starting point

A set of nodes (or vertices) with a single starting point Binary Search Trees Understand tree terminology Understand and implement tree traversals Define the binary search tree property Implement binary search trees Implement the TreeSort algorithm 2 A set of

More information

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text) Lec 17 April 8 Topics: binary Trees expression trees Binary Search Trees (Chapter 5 of text) Trees Linear access time of linked lists is prohibitive Heap can t support search in O(log N) time. (takes O(N)

More information

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs Computational Optimization ISE 407 Lecture 16 Dr. Ted Ralphs ISE 407 Lecture 16 1 References for Today s Lecture Required reading Sections 6.5-6.7 References CLRS Chapter 22 R. Sedgewick, Algorithms in

More information

CISC 235 Topic 3. General Trees, Binary Trees, Binary Search Trees

CISC 235 Topic 3. General Trees, Binary Trees, Binary Search Trees CISC 235 Topic 3 General Trees, Binary Trees, Binary Search Trees Outline General Trees Terminology, Representation, Properties Binary Trees Representations, Properties, Traversals Recursive Algorithms

More information

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures. Trees Q: Why study trees? : Many advance DTs are implemented using tree-based data structures. Recursive Definition of (Rooted) Tree: Let T be a set with n 0 elements. (i) If n = 0, T is an empty tree,

More information

Chapter 20: Binary Trees

Chapter 20: Binary Trees Chapter 20: Binary Trees 20.1 Definition and Application of Binary Trees Definition and Application of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two other

More information

Trees, Binary Trees, and Binary Search Trees

Trees, Binary Trees, and Binary Search Trees COMP171 Trees, Binary Trees, and Binary Search Trees 2 Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search,

More information

Discussion 2C Notes (Week 8, February 25) TA: Brian Choi Section Webpage:

Discussion 2C Notes (Week 8, February 25) TA: Brian Choi Section Webpage: Discussion 2C Notes (Week 8, February 25) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs32 Trees Definitions Yet another data structure -- trees. Just like a linked

More information

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop. Tree A tree consists of a set of nodes and a set of edges connecting pairs of nodes. A tree has the property that there is exactly one path (no more, no less) between any pair of nodes. A path is a connected

More information

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge Trees (& Heaps) Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Spring 2015 Jill Seaman 1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root -

More information

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge Trees & Heaps Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Fall 2018 Jill Seaman!1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every

More information

Why Do We Need Trees?

Why Do We Need Trees? CSE 373 Lecture 6: Trees Today s agenda: Trees: Definition and terminology Traversing trees Binary search trees Inserting into and deleting from trees Covered in Chapter 4 of the text Why Do We Need Trees?

More information

a graph is a data structure made up of nodes in graph theory the links are normally called edges

a graph is a data structure made up of nodes in graph theory the links are normally called edges 1 Trees Graphs a graph is a data structure made up of nodes each node stores data each node has links to zero or more nodes in graph theory the links are normally called edges graphs occur frequently in

More information

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example. Trees, Binary Search Trees, and Heaps CS 5301 Fall 2013 Jill Seaman Tree: non-recursive definition Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every node (except

More information

CE 221 Data Structures and Algorithms

CE 221 Data Structures and Algorithms CE 221 Data Structures and Algorithms Chapter 4: Trees (Binary) Text: Read Weiss, 4.1 4.2 Izmir University of Economics 1 Preliminaries - I (Recursive) Definition: A tree is a collection of nodes. The

More information

Binary Search Trees. See Section 11.1 of the text.

Binary Search Trees. See Section 11.1 of the text. Binary Search Trees See Section 11.1 of the text. Consider the following Binary Search Tree 17 This tree has a nice property: for every node, all of the nodes in its left subtree have values less than

More information

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees Computer Science 0 Data Structures Siena College Fall 08 Topic Notes: Trees We ve spent a lot of time looking at a variety of structures where there is a natural linear ordering of the elements in arrays,

More information

Trees. Truong Tuan Anh CSE-HCMUT

Trees. Truong Tuan Anh CSE-HCMUT Trees Truong Tuan Anh CSE-HCMUT Outline Basic concepts Trees Trees A tree consists of a finite set of elements, called nodes, and a finite set of directed lines, called branches, that connect the nodes

More information

Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University

Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University U Kang (2016) 1 In This Lecture The concept of binary tree, its terms, and its operations Full binary tree theorem Idea

More information

7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w

7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w Chapter 7 Trees 7.1 Introduction A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w Tree Terminology Parent Ancestor Child Descendant Siblings

More information

March 20/2003 Jayakanth Srinivasan,

March 20/2003 Jayakanth Srinivasan, Definition : A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges. Definition : In a multigraph G = (V, E) two or

More information

Trees. Introduction & Terminology. February 05, 2018 Cinda Heeren / Geoffrey Tien 1

Trees. Introduction & Terminology. February 05, 2018 Cinda Heeren / Geoffrey Tien 1 Trees Introduction & Terminology Cinda Heeren / Geoffrey Tien 1 Review: linked lists Linked lists are constructed out of nodes, consisting of a data element a pointer to another node Lists are constructed

More information

Unit III - Tree TREES

Unit III - Tree TREES TREES Unit III - Tree Consider a scenario where you are required to represent the directory structure of your operating system. The directory structure contains various folders and files. A folder may

More information

CMSC 341. Binary Search Trees CMSC 341 BST

CMSC 341. Binary Search Trees CMSC 341 BST CMSC 341 Binary Search Trees CMSC 341 BST Announcements Homework #3 dues Thursday (10/5/2017) Exam #1 next Thursday (10/12/2017) CMSC 341 BST A Generic Tree CMSC 341 BST Binary Tree CMSC 341 BST The Binary

More information

Chapter 5. Binary Trees

Chapter 5. Binary Trees Chapter 5 Binary Trees Definitions and Properties A binary tree is made up of a finite set of elements called nodes It consists of a root and two subtrees There is an edge from the root to its children

More information

DATA STRUCTURES AND ALGORITHMS. Hierarchical data structures: AVL tree, Bayer tree, Heap

DATA STRUCTURES AND ALGORITHMS. Hierarchical data structures: AVL tree, Bayer tree, Heap DATA STRUCTURES AND ALGORITHMS Hierarchical data structures: AVL tree, Bayer tree, Heap Summary of the previous lecture TREE is hierarchical (non linear) data structure Binary trees Definitions Full tree,

More information

CSCI2100B Data Structures Trees

CSCI2100B Data Structures Trees CSCI2100B Data Structures Trees Irwin King king@cse.cuhk.edu.hk http://www.cse.cuhk.edu.hk/~king Department of Computer Science & Engineering The Chinese University of Hong Kong Introduction General Tree

More information

Lecture 6: Analysis of Algorithms (CS )

Lecture 6: Analysis of Algorithms (CS ) Lecture 6: Analysis of Algorithms (CS583-002) Amarda Shehu October 08, 2014 1 Outline of Today s Class 2 Traversals Querying Insertion and Deletion Sorting with BSTs 3 Red-black Trees Height of a Red-black

More information

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

Advanced Java Concepts Unit 5: Trees. Notes and Exercises Advanced Java Concepts Unit 5: Trees. Notes and Exercises A Tree is a data structure like the figure shown below. We don t usually care about unordered trees but that s where we ll start. Later we will

More information

[ DATA STRUCTURES ] Fig. (1) : A Tree

[ DATA STRUCTURES ] Fig. (1) : A Tree [ DATA STRUCTURES ] Chapter - 07 : Trees A Tree is a non-linear data structure in which items are arranged in a sorted sequence. It is used to represent hierarchical relationship existing amongst several

More information

TREES Lecture 10 CS2110 Spring2014

TREES Lecture 10 CS2110 Spring2014 TREES Lecture 10 CS2110 Spring2014 Readings and Homework 2 Textbook, Chapter 23, 24 Homework: A thought problem (draw pictures!) Suppose you use trees to represent student schedules. For each student there

More information

tree nonlinear Examples

tree nonlinear Examples The Tree ADT Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary tree implementation Examine a binary tree example 10-2

More information

Binary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree

Binary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree 0/2/ Preview Binary Tree Tree Binary Tree Property functions In-order walk Pre-order walk Post-order walk Search Tree Insert an element to the Tree Delete an element form the Tree A binary tree is a tree

More information

INF2220: algorithms and data structures Series 1

INF2220: algorithms and data structures Series 1 Universitetet i Oslo Institutt for Informatikk A. Maus, R.K. Runde, I. Yu INF2220: algorithms and data structures Series 1 Topic Trees & estimation of running time (Exercises with hints for solution) Issued:

More information

CS350: Data Structures Red-Black Trees

CS350: Data Structures Red-Black Trees Red-Black Trees James Moscola Department of Engineering & Computer Science York College of Pennsylvania James Moscola Red-Black Tree An alternative to AVL trees Insertion can be done in a bottom-up or

More information

Tree Structures. A hierarchical data structure whose point of entry is the root node

Tree Structures. A hierarchical data structure whose point of entry is the root node Binary Trees 1 Tree Structures A tree is A hierarchical data structure whose point of entry is the root node This structure can be partitioned into disjoint subsets These subsets are themselves trees and

More information

CS 206 Introduction to Computer Science II

CS 206 Introduction to Computer Science II CS 206 Introduction to Computer Science II 10 / 10 / 2016 Instructor: Michael Eckmann Today s Topics Questions? Comments? A few comments about Doubly Linked Lists w/ dummy head/tail Trees Binary trees

More information

Data Structures. Trees. By Dr. Mohammad Ali H. Eljinini. M.A. Eljinini, PhD

Data Structures. Trees. By Dr. Mohammad Ali H. Eljinini. M.A. Eljinini, PhD Data Structures Trees By Dr. Mohammad Ali H. Eljinini Trees Are collections of items arranged in a tree like data structure (none linear). Items are stored inside units called nodes. However: We can use

More information

BBM 201 Data structures

BBM 201 Data structures BBM 201 Data structures Lecture 11: Trees 2018-2019 Fall Content Terminology The Binary Tree The Binary Search Tree Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, 2013

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2017S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list

More information

Binary Trees. Examples:

Binary Trees. Examples: Binary Trees A tree is a data structure that is made of nodes and pointers, much like a linked list. The difference between them lies in how they are organized: In a linked list each node is connected

More information

6-TREE. Tree: Directed Tree: A directed tree is an acyclic digraph which has one node called the root node

6-TREE. Tree: Directed Tree: A directed tree is an acyclic digraph which has one node called the root node 6-TREE Data Structure Management (330701) Tree: A tree is defined as a finite set of one or more nodes such that There is a special node called the root node R. The remaining nodes are divided into n 0

More information

Design and Analysis of Algorithms Lecture- 9: Binary Search Trees

Design and Analysis of Algorithms Lecture- 9: Binary Search Trees Design and Analysis of Algorithms Lecture- 9: Binary Search Trees Dr. Chung- Wen Albert Tsao 1 Binary Search Trees Data structures that can support dynamic set operations. Search, Minimum, Maximum, Predecessor,

More information

Trees. Tree Structure Binary Tree Tree Traversals

Trees. Tree Structure Binary Tree Tree Traversals Trees Tree Structure Binary Tree Tree Traversals The Tree Structure Consists of nodes and edges that organize data in a hierarchical fashion. nodes store the data elements. edges connect the nodes. The

More information

Binary Trees. BSTs. For example: Jargon: Data Structures & Algorithms. root node. level: internal node. edge.

Binary Trees. BSTs. For example: Jargon: Data Structures & Algorithms. root node. level: internal node. edge. Binary Trees 1 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the root, which are disjoint from

More information

Trees 11/15/16. Chapter 11. Terminology. Terminology. Terminology. Terminology. Terminology

Trees 11/15/16. Chapter 11. Terminology. Terminology. Terminology. Terminology. Terminology Chapter 11 Trees Definition of a general tree A general tree T is a set of one or more nodes such that T is partitioned into disjoint subsets: A single node r, the root Sets that are general trees, called

More information

CMSC 341 Lecture 10 Binary Search Trees

CMSC 341 Lecture 10 Binary Search Trees CMSC 341 Lecture 10 Binary Search Trees John Park Based on slides from previous iterations of this course Review: Tree Traversals 2 Traversal Preorder, Inorder, Postorder H X M A K B E N Y L G W UMBC CMSC

More information

Topic 14. The BinaryTree ADT

Topic 14. The BinaryTree ADT Topic 14 The BinaryTree ADT Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary tree implementation Examine a binary tree

More information

References and Homework ABSTRACT DATA TYPES; LISTS & TREES. Abstract Data Type (ADT) 9/24/14. ADT example: Set (bunch of different values)

References and Homework ABSTRACT DATA TYPES; LISTS & TREES. Abstract Data Type (ADT) 9/24/14. ADT example: Set (bunch of different values) 9// References and Homework Text: Chapters, and ABSTRACT DATA TYPES; LISTS & TREES Homework: Learn these List methods, from http://docs.oracle.com/javase/7/docs/api/java/util/list.html add, addall, contains,

More information

CS302 - Data Structures using C++

CS302 - Data Structures using C++ CS302 - Data Structures using C++ Topic: Trees Kostas Alexis Trees List, stacks, and queues are linear in their organization of data. Items are one after another In this section, we organize data in a

More information

COMP : Trees. COMP20012 Trees 219

COMP : Trees. COMP20012 Trees 219 COMP20012 3: Trees COMP20012 Trees 219 Trees Seen lots of examples. Parse Trees Decision Trees Search Trees Family Trees Hierarchical Structures Management Directories COMP20012 Trees 220 Trees have natural

More information

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false. Name: Class: Date: CSCI-401 Examlet #5 True/False Indicate whether the sentence or statement is true or false. 1. The root node of the standard binary tree can be drawn anywhere in the tree diagram. 2.

More information

If you took your exam home last time, I will still regrade it if you want.

If you took your exam home last time, I will still regrade it if you want. Some Comments about HW2: 1. You should have used a generic node in your structure one that expected an Object, and not some other type. 2. Main is still too long for some people 3. braces in wrong place,

More information

CS211, LECTURE 20 SEARCH TREES ANNOUNCEMENTS:

CS211, LECTURE 20 SEARCH TREES ANNOUNCEMENTS: CS211, LECTURE 20 SEARCH TREES ANNOUNCEMENTS: OVERVIEW: motivation naive tree search sorting for trees and binary trees new tree classes search insert delete 1. Motivation 1.1 Search Structure continuing

More information

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology Trees : Part Section. () (2) Preorder, Postorder and Levelorder Traversals Definition: A tree is a connected graph with no cycles Consequences: Between any two vertices, there is exactly one unique path

More information

CS350: Data Structures Binary Search Trees

CS350: Data Structures Binary Search Trees Binary Search Trees James Moscola Department of Engineering & Computer Science York College of Pennsylvania James Moscola Introduction to Binary Search Trees A binary search tree is a binary tree that

More information

The tree data structure. Trees COL 106. Amit Kumar Shweta Agrawal. Acknowledgement :Many slides are courtesy Douglas Harder, UWaterloo

The tree data structure. Trees COL 106. Amit Kumar Shweta Agrawal. Acknowledgement :Many slides are courtesy Douglas Harder, UWaterloo The tree data structure 1 Trees COL 106 Amit Kumar Shweta Agrawal Acknowledgement :Many slides are courtesy Douglas Harder, UWaterloo 1 Trees The tree data structure 3 A rooted tree data structure stores

More information

Lecture: Analysis of Algorithms (CS )

Lecture: Analysis of Algorithms (CS ) Lecture: Analysis of Algorithms (CS583-002) Amarda Shehu Fall 2017 1 Binary Search Trees Traversals, Querying, Insertion, and Deletion Sorting with BSTs 2 Example: Red-black Trees Height of a Red-black

More information

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree. The Lecture Contains: Index structure Binary search tree (BST) B-tree B+-tree Order file:///c /Documents%20and%20Settings/iitkrana1/My%20Documents/Google%20Talk%20Received%20Files/ist_data/lecture13/13_1.htm[6/14/2012

More information

CSE 230 Intermediate Programming in C and C++ Binary Tree

CSE 230 Intermediate Programming in C and C++ Binary Tree CSE 230 Intermediate Programming in C and C++ Binary Tree Fall 2017 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu Introduction to Tree Tree is a non-linear data structure

More information

I2206 Data Structures TS 6: Binary Trees - Binary Search Trees

I2206 Data Structures TS 6: Binary Trees - Binary Search Trees Lebanese University BS - Computer Science Faculty of Science 2018-2019 Section I I2206 Data Structures TS 6: Binary Trees - Binary Search Trees Exercise 1 What value does the following C function return?

More information

Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College!

Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College! Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College! ADTʼs Weʼve Studied! Position-oriented ADT! List! Stack! Queue! Value-oriented ADT! Sorted list! All of these are linear! One previous item;

More information

Outline. Preliminaries. Binary Trees Binary Search Trees. What is Tree? Implementation of Trees using C++ Tree traversals and applications

Outline. Preliminaries. Binary Trees Binary Search Trees. What is Tree? Implementation of Trees using C++ Tree traversals and applications Trees 1 Outline Preliminaries What is Tree? Implementation of Trees using C++ Tree traversals and applications Binary Trees Binary Search Trees Structure and operations Analysis 2 What is a Tree? A tree

More information

Introduction to Trees. D. Thiebaut CSC212 Fall 2014

Introduction to Trees. D. Thiebaut CSC212 Fall 2014 Introduction to Trees D. Thiebaut CSC212 Fall 2014 A bit of History & Data Visualization: The Book of Trees. (Link) We Concentrate on Binary-Trees, Specifically, Binary-Search Trees (BST) How Will Java

More information

Binary Search Trees. What is a Binary Search Tree?

Binary Search Trees. What is a Binary Search Tree? Binary Search Trees What is a Binary Search Tree? A binary tree where each node is an object Each node has a key value, left child, and right child (might be empty) Each node satisfies the binary search

More information

Binary Trees. Height 1

Binary Trees. Height 1 Binary Trees Definitions A tree is a finite set of one or more nodes that shows parent-child relationship such that There is a special node called root Remaining nodes are portioned into subsets T1,T2,T3.

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College November 13, 2017 Outline Outline 1 C++ Supplement.1: Trees Outline C++ Supplement.1: Trees 1 C++ Supplement.1: Trees Uses

More information

CS24 Week 8 Lecture 1

CS24 Week 8 Lecture 1 CS24 Week 8 Lecture 1 Kyle Dewey Overview Tree terminology Tree traversals Implementation (if time) Terminology Node The most basic component of a tree - the squares Edge The connections between nodes

More information

Trees. A tree is a directed graph with the property

Trees. A tree is a directed graph with the property 2: Trees Trees A tree is a directed graph with the property There is one node (the root) from which all other nodes can be reached by exactly one path. Seen lots of examples. Parse Trees Decision Trees

More information

COSC 2011 Section N. Trees: Terminology and Basic Properties

COSC 2011 Section N. Trees: Terminology and Basic Properties COSC 2011 Tuesday, March 27 2001 Overview Trees and Binary Trees Quick review of definitions and examples Tree Algorithms Depth, Height Tree and Binary Tree Traversals Preorder, postorder, inorder Binary

More information

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1 Chapter 11!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1 2015-12-01 09:30:53 1/54 Chapter-11.pdf (#13) Terminology Definition of a general tree! A general tree T is a set of one or

More information

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1 Chapter 11!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1 2015-03-25 21:47:41 1/53 Chapter-11.pdf (#4) Terminology Definition of a general tree! A general tree T is a set of one or more

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 10: Search and Heaps MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Search and Heaps 2 Linear Search Binary Search Introduction to trees Priority Queues Heaps Linear Search

More information

Algorithms. AVL Tree

Algorithms. AVL Tree Algorithms AVL Tree Balanced binary tree The disadvantage of a binary search tree is that its height can be as large as N-1 This means that the time needed to perform insertion and deletion and many other

More information

TREES Lecture 12 CS2110 Fall 2016

TREES Lecture 12 CS2110 Fall 2016 TREES Lecture 12 CS2110 Fall 2016 Prelim 1 tonight! 2 5:30 prelim is very crowded. You HAVE to follow these directions: 1. Students taking the normal 5:30 prelim (not the quiet room) and whose last names

More information

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU Course Review for Midterm Exam 1 Cpt S 223 Fall 2011 1 Midterm Exam 1 When: Friday (10/14) 1:10-2pm Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & in-class

More information

Principles of Computer Science

Principles of Computer Science Principles of Computer Science Binary Trees 08/11/2013 CSCI 2010 - Binary Trees - F.Z. Qureshi 1 Today s Topics Extending LinkedList with Fast Search Sorted Binary Trees Tree Concepts Traversals of a Binary

More information

CS 350 : Data Structures Binary Search Trees

CS 350 : Data Structures Binary Search Trees CS 350 : Data Structures Binary Search Trees David Babcock (courtesy of James Moscola) Department of Physical Sciences York College of Pennsylvania James Moscola Introduction to Binary Search Trees A binary

More information

Cpt S 122 Data Structures. Data Structures Trees

Cpt S 122 Data Structures. Data Structures Trees Cpt S 122 Data Structures Data Structures Trees Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Motivation Trees are one of the most important and extensively

More information

TREES. Tree Overview 9/28/16. Prelim 1 tonight! Important Announcements. Tree terminology. Binary trees were in A1!

TREES. Tree Overview 9/28/16. Prelim 1 tonight! Important Announcements. Tree terminology. Binary trees were in A1! //16 Prelim 1 tonight! :3 prelim is very crowded. You HAVE to follow these directions: 1. Students taking the normal :3 prelim (not the quiet room) and whose last names begin with A through Da MUST go

More information

Chapter 4 Trees. Theorem A graph G has a spanning tree if and only if G is connected.

Chapter 4 Trees. Theorem A graph G has a spanning tree if and only if G is connected. Chapter 4 Trees 4-1 Trees and Spanning Trees Trees, T: A simple, cycle-free, loop-free graph satisfies: If v and w are vertices in T, there is a unique simple path from v to w. Eg. Trees. Spanning trees:

More information

Sorted Arrays. Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min

Sorted Arrays. Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min Binary Search Trees FRIDAY ALGORITHMS Sorted Arrays Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min 6 10 11 17 2 0 6 Running Time O(1) O(lg n) O(1) O(1)

More information

Binary Trees and Binary Search Trees

Binary Trees and Binary Search Trees Binary Trees and Binary Search Trees Learning Goals After this unit, you should be able to... Determine if a given tree is an instance of a particular type (e.g. binary, and later heap, etc.) Describe

More information

Binary Trees. Recursive definition. Is this a binary tree?

Binary Trees. Recursive definition. Is this a binary tree? Binary Search Trees Binary Trees Recursive definition 1. An empty tree is a binary tree 2. A node with two child subtrees is a binary tree 3. Only what you get from 1 by a finite number of applications

More information

Trees. Estruturas de Dados / Programação 2 Árvores. Márcio Ribeiro twitter.com/marciomribeiro. Introduc)on. Hierarchical structure

Trees. Estruturas de Dados / Programação 2 Árvores. Márcio Ribeiro twitter.com/marciomribeiro. Introduc)on. Hierarchical structure Introduc)on Linear structures Removing this idea, treasure of applicaons Estruturas de Dados / Programação 2 Árvores Márcio Ribeiro marcio@ic.ufal.br twitter.com/marciomribeiro Hierarchical structure Companies

More information

Binary Trees. Reading: Lewis & Chase 12.1, 12.3 Eck Programming Course CL I

Binary Trees. Reading: Lewis & Chase 12.1, 12.3 Eck Programming Course CL I inary Trees Reading: Lewis & hase 12.1, 12.3 Eck 9.4.1 Objectives Tree basics Learn the terminology used when talking about trees iscuss methods for traversing trees iscuss a possible implementation of

More information

Terminology. The ADT Binary Tree. The ADT Binary Search Tree

Terminology. The ADT Binary Tree. The ADT Binary Search Tree Terminology The ADT Binary Tree The ADT Binary Search Tree 1 Terminology 3 A general tree A general tree T is a set of one or more nodes such that T is partitioned into disjoint subsets: o A single node

More information