SlideShare a Scribd company logo
1 of 41
Lecture 4
Dynamic Data Structure Part 2
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 1
Content Lecture 4 Dynamic Data
Part 2
 Tree structures
 General
 Tree Representation
 Balanced Trees
 Binary Tree
 Sorted Binary Tree
 Binary Search Tree
 Insert an element in a Sorted Binary Tree
 Delete a node in a Sorted Binary Tree
 Other Tree Types
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 2
Tree structures
General
 Trees are one of the most important data structures
 There are several different variants
 We will have a closer look to some of them
 Trees are used in computer science for data storage,
searching and sorting
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 3
Tree structures
Definition
A Tree is a finite amount T of one or several nodes such that
 There is a significant node called root(T)
 The other nodes can be divided in disjunctive amount
T1, .. Tm
 Each of these amounts is again a Tree
 These Trees are called Sub Trees
 This is a recursive definition
 At the end a Tree with only one node remains
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 4
Tree Representation
 You can display Trees in different ways
 In this course outline Trees are illustrated with the root on
the top and the Sub Trees below
 This is a common illustration
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 5
FED
B C
A
Tree Representation
 These are some different representations
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 6
Tree Representation
Family Trees
 A common example for trees are Family Trees
 Two variants of Family Trees exist:
 Starting from an ancestor as root and illustrated all the
descendants
 Starting from a descendant as root and illustrated all the
ancestors
 In Family Trees you can have redundancies if some of the
ancestors have the same ancestors
 In this case the entries represent the role of the ancestor
(for example grandmother on the mother’s side)
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 7
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 8
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 9
Tree structures
Definitions for Trees
 Each node in a Tree is the root of one of the Sub Trees
 Each Tree has zero or more child nodes which are below in
the Tree
 A node with a child node is called parent node to the child
(also ancestor node or superior)
 A root node is a node with no parents
 Each Tree has at least one root node
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 10
Tree structures
Example
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 11
G
FED
B C
A root node
parent node of D, E, Fchild
node of A
Tree structures
 The depth of a node is the length of the path to its root
 A node p is an ancestor to node q if p exists on the path
from q to root
 The node q is called a descendant of p
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 12
Tree structures
Example
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 13
G
FED
B C
A
depth of F is 2
C is ancestor of D
D is a descendant of C
Tree structures
 The size of a node is the number of descendants a node has
including itself
 Siblings are nodes that share the same parent node
 Nodes without a child node are called leaf node or
terminal nodes
 Internal or inner node are nodes with one or more child
nodes therefore size > 0
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 14
Tree structures
Example
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 15
G
FED
B C
A size of A is 7
B and C are siblings
G is a leave node
F is an inner node
Tree structures
 In-degree of a node is the number of edges arriving at that
node
 The only node with In-degree = 0 is the root node
 Out-degree of a node is the number of edges leaving that
node
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 16
Tree structures
Example
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 17
G
FED
B C
A
In-degree of C 1
Out-degree of C is 3
In-degree of D 1
Out-degree
of D is 0
Tree structures
 The level of a node is defined
as:
 The level of the root(T) is 0
 The level of any other node
is increased by 1 to the
level of the node which is
the root of the superior sub
tree
level(node) = level(parent) + 1
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 18
G
FED
B C
A Level 0
Level 1
Level 2
Level 3
Balanced Trees
 If the relative order of the Sub Trees is important you call it
a Balanced Tree
 If the order is not important this is called an Oriented
Tree
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 19
G
FED
B C
A
G
EFD
B C
A
These Trees are
different if you look at
them as Balanced Tree
but they are consider
as the same if you look
at them as Oriented
Trees
Binary Trees
 A Binary Tree is a finite amount of nodes where the
amount is empty or contains a root and two disjunctive
Binary Trees
 These two Binary Trees are called left and right Sub Tree
of the root
 That means that every node of the tree has zero, one or two
child nodes
 Binary Trees are not a special case of Trees in general
 For example you can have an empty amount as a Binary
Tree but not as a General Tree
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 20
Binary Trees
 Any data in the Tree structure can be reached by starting at
the rood node and following either the left or the right
child
 Binary Trees are used for implementation of Binary Tree
Search and Binary Heaps
 Examples for Binary Trees are the elimination contest in
tennis or other sport competitions
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 21
Binary Trees
Example
 These two Binary Trees are not the same
 One has left and the other a right Sub Tree
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 22
B
A
B
A
Binary tree with a
left sub tree
Binary tree with a
right sub tree
Binary Trees
Implementation
 Binary Trees are easily implemented as a data type like
 One pointer points to the root
 If this pointer is null than the Tree is empty
 A node in the Binary Tree contains a pointer to an object
or a record and the two pointers to the left and the right
Sub Tree
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 23
Binary Trees
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 24
root
A
B
C
E FD
G H J
ǁ
ǁ
ǁ ǁ ǁ
ǁ
ǁ
ǁ ǁ ǁ
Binary Trees
 There are three possibilities to traverse a Binary Tree:
preorder, inorder and postorder
 If the Tree is empty there is nothing to do
 Otherwise the traverse possibilities are defined as:
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 25
preorder visit the root
traverse the left sub tree
traverse the right sub tree
inorder traverse the left sub tree
visit the root
traverse the right sub tree
postorder traverse the left sub tree
traverse the right sub tree
visit the root
B C
A
A B C
B A C
B C A
Binary Trees
Examples
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 26
preorder: A B D C E G F H I
inorder: D B A E G C H F I
postorder: D B G E H I F C A
G
FED
B C
A
IH
Note
The preorder traverse is also called Polish
notation (after the Polish logician Jan
Lukasiewicz) and the postorder traverse is
therefore called a backwards Polish
notation
Binary Trees
 Mathematical formulas can be represented by Binary Trees:
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 27
preorder - * * + 4 2 7 + 9 3 / 8 – 4
inorder (4 + 2) * 7 * (9 + 3) – (8/(-4)) (adding parentheses)
postorder 4 2 + 7 * 9 3 + * 8 4 - / -
-8*
* /
-
4+ 7
4 2
+
9 3
Sorted Binary Tree
A tree T is a Sorted Binary Tree where
 v: T  V function to receive the value of a node
 T a Binary Tree
 T1 the left Sub Tree (also a Sorted Binary Trees)
 T2 the right Sub Tree (also a Sorted Binary Trees) such that:
v(root(T)) > v(t) for all nodes t in T1
v(root(T)) ≤ v(t) for all nodes t in T2
 If you traverse a Sorted Binary Tree inorder, than all values
are reached in a sorted way
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 28
Sorted Binary Tree
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 29
7
961
3 8
5
Example
Inorder: 1 3 5 6 7 8 9
Binary Tree
Definitions
The height of a Tree is the length of the path from the root to
the deepest node in the Tree:
h(T) = 0 if the Tree T is empty
h(T) = max(h(T1), h(T2)) + 1
where T1 is the left and T2 the right Sub Tree
The cardinality of a Tree T is the number n of elements in
the Tree that means:
n = card(T)
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 30
Binary Tree
Example
The height of this tree is 4
The cardinality of this tree is 7
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 31
7
961
3 8
5
Binary Tree
A Tree is called height-balancing if the Tree T is empty or if
| h(T1) – h (T2) | ≤ 1
where h is the height of a Tree and also the Sub Trees T1 and
T2 are height-balancing Trees
A Tree is called balanced if the Tree T is empty or if
| card(T1) – card(T2) | ≤ 1
and also the Sub Trees T1 and T2 are balanced
If a Tree T is balance he is also balanced in its height
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 32
Sorted Binary Tree
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 33
height-balancing Tree but not a balanced
height left tree = 2, height right tree = 3
 |h(T1) – h(T2) = |2 – 3| = 1
card left tree = 2, card right tree = 4
 |card(T1) – card(T2) = |2 – 4| = 2
Balanced Tree ( height-balancing)
height left tree = 2, height right tree = 2
 |h(T1) – h(T2) = |2 – 2| = 0
card left tree = 3, card right tree = 3
 |card(T1) – card(T2) = |3 – 3| = 0
7
961
3 8
5
751
2 6
4
3
Binary Search Tree
k a value and the
s search element
v(s) = k
T (Binary Tree) with t = root(T)
If T is empty than there is nothing to do
If v(t) = k than the search element is found
If not than
 Replace T with the left subtree T1 if k < v(t)  T = T1
 Replace T with the right subtree T2 if k ≥ v(t)  T = T2
The effort for the search is O(h(T))
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 34
Binary Search Tree
Example
Search element k
k = 1
t = 5  1 < 5
t = 3  1 < 3
t = 1  1 = 1 element found!
k = 7
t = 5  7 > 5
t = 8  7 < 8
t = 6  7 > 6
t = 7  7 = 7 element found!
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 35
7
961
3 8
5
Insert a element in a Sorted
Binary Tree
u a values with k = v(u) to be insert
T a tree with t the root of Tree T
 Create a new binary sorted tree U containing only the root
u
 If T is empty replace T by U
 Otherwise
 replace T with the left sub tree T1 if k < v(t)  T = T1
 replace T with the right sub tree T2 if k ≥ v(t)  T = T2
 The effort is also O(h(T))
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 36
Insert a element in a Sorted
Binary Tree
Example
Insert in an empty Tree the elements 5, 1, 3, 2, 8, 4, 6, 7 and 9:
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 37
5
1
3
2 4
9
8
7
6
Delete a node in a Sorted Binary
Tree
Be u ϵ T the node to be removed from Tree T
Be U the sub tree from T with root(U) = u
 If the left Sub Tree U1 of U is empty than replace U by U1
 If the right Sub Tree U2 of U is empty than replace U by U2
 If both Sub Trees are not empty than:
 Chose an u2 ϵ U2 such that v(u2) ≤ v(t) for all t ϵ U2
 u2 has to be removed from U2
 u2 replace the node u
The effort to delete a node in a Tree is O(h(T)) due to the
search for the minimal element u2
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 38
Delete a node in a Sorted Binary
Tree
Example
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 39
Other Tree Types
 2-3 tree
 2-3-4 tree
 AA tree
 AVL tree
 B-tree
 Elastic binary tree
 Random binary tree
 Red-black tree
 Self-balancing binary search tree
 Unrooted binary tree
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 40
Any
questions?
23/10/2018 Lecture 4 Dynamic Data Structure Part 2 41

More Related Content

What's hot

Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)MUHAMMAD AAMIR
 
Dynamic multi level indexing Using B-Trees And B+ Trees
Dynamic multi level indexing Using B-Trees And B+ TreesDynamic multi level indexing Using B-Trees And B+ Trees
Dynamic multi level indexing Using B-Trees And B+ TreesPooja Dixit
 
Introductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueIntroductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueGhaffar Khan
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structureadeel hamid
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsAakash deep Singhal
 
Data Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer ScienceData Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer ScienceTransweb Global Inc
 
Furnish an Index Using the Works of Tree Structures
Furnish an Index Using the Works of Tree StructuresFurnish an Index Using the Works of Tree Structures
Furnish an Index Using the Works of Tree Structuresijceronline
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structuresunilchute1
 
Introduction of Data Structure
Introduction of Data StructureIntroduction of Data Structure
Introduction of Data StructureMandavi Classes
 
Modern Database Systems - Lecture 01
Modern Database Systems - Lecture 01Modern Database Systems - Lecture 01
Modern Database Systems - Lecture 01Michael Mathioudakis
 
Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)pushpalathakrishnan
 
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...Hassan Ahmed
 
DATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTESDATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTESsuthi
 
Data Structure # vpmp polytechnic
Data Structure # vpmp polytechnicData Structure # vpmp polytechnic
Data Structure # vpmp polytechniclavparmar007
 
Dsa module 1 ppt
Dsa module 1 pptDsa module 1 ppt
Dsa module 1 pptSree Kanth
 
Programming & Data Structure Lecture Notes
Programming & Data Structure Lecture NotesProgramming & Data Structure Lecture Notes
Programming & Data Structure Lecture NotesFellowBuddy.com
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structureZaid Shabbir
 
[Queue , linked list , tree]
[Queue , linked list , tree][Queue , linked list , tree]
[Queue , linked list , tree]Nowrin Nishat
 

What's hot (20)

Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)
 
Dynamic multi level indexing Using B-Trees And B+ Trees
Dynamic multi level indexing Using B-Trees And B+ TreesDynamic multi level indexing Using B-Trees And B+ Trees
Dynamic multi level indexing Using B-Trees And B+ Trees
 
Introductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueIntroductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, Queue
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
Data Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer ScienceData Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer Science
 
Furnish an Index Using the Works of Tree Structures
Furnish an Index Using the Works of Tree StructuresFurnish an Index Using the Works of Tree Structures
Furnish an Index Using the Works of Tree Structures
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Introduction of Data Structure
Introduction of Data StructureIntroduction of Data Structure
Introduction of Data Structure
 
Modern Database Systems - Lecture 01
Modern Database Systems - Lecture 01Modern Database Systems - Lecture 01
Modern Database Systems - Lecture 01
 
Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)Data Structure Question Bank(2 marks)
Data Structure Question Bank(2 marks)
 
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
 
DATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTESDATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTES
 
Data Structure # vpmp polytechnic
Data Structure # vpmp polytechnicData Structure # vpmp polytechnic
Data Structure # vpmp polytechnic
 
Dsa module 1 ppt
Dsa module 1 pptDsa module 1 ppt
Dsa module 1 ppt
 
104333 sri vidhya eng notes
104333 sri vidhya eng notes104333 sri vidhya eng notes
104333 sri vidhya eng notes
 
Programming & Data Structure Lecture Notes
Programming & Data Structure Lecture NotesProgramming & Data Structure Lecture Notes
Programming & Data Structure Lecture Notes
 
final_presentation
final_presentationfinal_presentation
final_presentation
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
[Queue , linked list , tree]
[Queue , linked list , tree][Queue , linked list , tree]
[Queue , linked list , tree]
 

Similar to Lecture4b dynamic data_structure

mitochondria moment and super computer integration.ppt
mitochondria moment and super computer integration.pptmitochondria moment and super computer integration.ppt
mitochondria moment and super computer integration.pptAMMAD45
 
data structures module III & IV.pptx
data structures module III & IV.pptxdata structures module III & IV.pptx
data structures module III & IV.pptxrani marri
 
non linear data structure -introduction of tree
non linear data structure -introduction of treenon linear data structure -introduction of tree
non linear data structure -introduction of treeSiddhi Viradiya
 
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptxLecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptxHamzaUsman48
 
Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsAakash deep Singhal
 
CS-102 BST_27_3_14v2.pdf
CS-102 BST_27_3_14v2.pdfCS-102 BST_27_3_14v2.pdf
CS-102 BST_27_3_14v2.pdfssuser034ce1
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data StructureOm Prakash
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11ecomputernotes
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeShivam Singh
 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in indiaEdhole.com
 
discrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxdiscrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxansariparveen06
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)Trupti Agrawal
 

Similar to Lecture4b dynamic data_structure (20)

Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
mitochondria moment and super computer integration.ppt
mitochondria moment and super computer integration.pptmitochondria moment and super computer integration.ppt
mitochondria moment and super computer integration.ppt
 
bst.ppt
bst.pptbst.ppt
bst.ppt
 
data structures module III & IV.pptx
data structures module III & IV.pptxdata structures module III & IV.pptx
data structures module III & IV.pptx
 
non linear data structure -introduction of tree
non linear data structure -introduction of treenon linear data structure -introduction of tree
non linear data structure -introduction of tree
 
7.tree
7.tree7.tree
7.tree
 
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptxLecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
 
Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithms
 
CS-102 BST_27_3_14v2.pdf
CS-102 BST_27_3_14v2.pdfCS-102 BST_27_3_14v2.pdf
CS-102 BST_27_3_14v2.pdf
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11
 
Tree
TreeTree
Tree
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in india
 
discrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxdiscrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptx
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Dsc++ unit 3 notes
Dsc++ unit 3 notesDsc++ unit 3 notes
Dsc++ unit 3 notes
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
 

More from mbadhi barnabas

More from mbadhi barnabas (8)

Lecture3b searching
Lecture3b searchingLecture3b searching
Lecture3b searching
 
Lecture3a sorting
Lecture3a sortingLecture3a sorting
Lecture3a sorting
 
Lecture2b algorithm
Lecture2b algorithmLecture2b algorithm
Lecture2b algorithm
 
Lecture2a algorithm
Lecture2a algorithmLecture2a algorithm
Lecture2a algorithm
 
Lecture1b data types
Lecture1b data typesLecture1b data types
Lecture1b data types
 
Lecture1a data types
Lecture1a data typesLecture1a data types
Lecture1a data types
 
Data struture and aligorism
Data struture and aligorismData struture and aligorism
Data struture and aligorism
 
Data structures and algorithm
Data structures and algorithmData structures and algorithm
Data structures and algorithm
 

Recently uploaded

Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...ThinkInnovation
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Jack DiGiovanna
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一F La
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceSapana Sha
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfJohn Sterrett
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)jennyeacort
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDRafezzaman
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 

Recently uploaded (20)

Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
Predictive Analysis - Using Insight-informed Data to Determine Factors Drivin...
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts Service
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdf
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 

Lecture4b dynamic data_structure

  • 1. Lecture 4 Dynamic Data Structure Part 2 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 1
  • 2. Content Lecture 4 Dynamic Data Part 2  Tree structures  General  Tree Representation  Balanced Trees  Binary Tree  Sorted Binary Tree  Binary Search Tree  Insert an element in a Sorted Binary Tree  Delete a node in a Sorted Binary Tree  Other Tree Types 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 2
  • 3. Tree structures General  Trees are one of the most important data structures  There are several different variants  We will have a closer look to some of them  Trees are used in computer science for data storage, searching and sorting 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 3
  • 4. Tree structures Definition A Tree is a finite amount T of one or several nodes such that  There is a significant node called root(T)  The other nodes can be divided in disjunctive amount T1, .. Tm  Each of these amounts is again a Tree  These Trees are called Sub Trees  This is a recursive definition  At the end a Tree with only one node remains 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 4
  • 5. Tree Representation  You can display Trees in different ways  In this course outline Trees are illustrated with the root on the top and the Sub Trees below  This is a common illustration 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 5 FED B C A
  • 6. Tree Representation  These are some different representations 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 6
  • 7. Tree Representation Family Trees  A common example for trees are Family Trees  Two variants of Family Trees exist:  Starting from an ancestor as root and illustrated all the descendants  Starting from a descendant as root and illustrated all the ancestors  In Family Trees you can have redundancies if some of the ancestors have the same ancestors  In this case the entries represent the role of the ancestor (for example grandmother on the mother’s side) 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 7
  • 8. 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 8
  • 9. 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 9
  • 10. Tree structures Definitions for Trees  Each node in a Tree is the root of one of the Sub Trees  Each Tree has zero or more child nodes which are below in the Tree  A node with a child node is called parent node to the child (also ancestor node or superior)  A root node is a node with no parents  Each Tree has at least one root node 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 10
  • 11. Tree structures Example 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 11 G FED B C A root node parent node of D, E, Fchild node of A
  • 12. Tree structures  The depth of a node is the length of the path to its root  A node p is an ancestor to node q if p exists on the path from q to root  The node q is called a descendant of p 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 12
  • 13. Tree structures Example 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 13 G FED B C A depth of F is 2 C is ancestor of D D is a descendant of C
  • 14. Tree structures  The size of a node is the number of descendants a node has including itself  Siblings are nodes that share the same parent node  Nodes without a child node are called leaf node or terminal nodes  Internal or inner node are nodes with one or more child nodes therefore size > 0 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 14
  • 15. Tree structures Example 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 15 G FED B C A size of A is 7 B and C are siblings G is a leave node F is an inner node
  • 16. Tree structures  In-degree of a node is the number of edges arriving at that node  The only node with In-degree = 0 is the root node  Out-degree of a node is the number of edges leaving that node 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 16
  • 17. Tree structures Example 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 17 G FED B C A In-degree of C 1 Out-degree of C is 3 In-degree of D 1 Out-degree of D is 0
  • 18. Tree structures  The level of a node is defined as:  The level of the root(T) is 0  The level of any other node is increased by 1 to the level of the node which is the root of the superior sub tree level(node) = level(parent) + 1 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 18 G FED B C A Level 0 Level 1 Level 2 Level 3
  • 19. Balanced Trees  If the relative order of the Sub Trees is important you call it a Balanced Tree  If the order is not important this is called an Oriented Tree 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 19 G FED B C A G EFD B C A These Trees are different if you look at them as Balanced Tree but they are consider as the same if you look at them as Oriented Trees
  • 20. Binary Trees  A Binary Tree is a finite amount of nodes where the amount is empty or contains a root and two disjunctive Binary Trees  These two Binary Trees are called left and right Sub Tree of the root  That means that every node of the tree has zero, one or two child nodes  Binary Trees are not a special case of Trees in general  For example you can have an empty amount as a Binary Tree but not as a General Tree 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 20
  • 21. Binary Trees  Any data in the Tree structure can be reached by starting at the rood node and following either the left or the right child  Binary Trees are used for implementation of Binary Tree Search and Binary Heaps  Examples for Binary Trees are the elimination contest in tennis or other sport competitions 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 21
  • 22. Binary Trees Example  These two Binary Trees are not the same  One has left and the other a right Sub Tree 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 22 B A B A Binary tree with a left sub tree Binary tree with a right sub tree
  • 23. Binary Trees Implementation  Binary Trees are easily implemented as a data type like  One pointer points to the root  If this pointer is null than the Tree is empty  A node in the Binary Tree contains a pointer to an object or a record and the two pointers to the left and the right Sub Tree 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 23
  • 24. Binary Trees 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 24 root A B C E FD G H J ǁ ǁ ǁ ǁ ǁ ǁ ǁ ǁ ǁ ǁ
  • 25. Binary Trees  There are three possibilities to traverse a Binary Tree: preorder, inorder and postorder  If the Tree is empty there is nothing to do  Otherwise the traverse possibilities are defined as: 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 25 preorder visit the root traverse the left sub tree traverse the right sub tree inorder traverse the left sub tree visit the root traverse the right sub tree postorder traverse the left sub tree traverse the right sub tree visit the root B C A A B C B A C B C A
  • 26. Binary Trees Examples 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 26 preorder: A B D C E G F H I inorder: D B A E G C H F I postorder: D B G E H I F C A G FED B C A IH Note The preorder traverse is also called Polish notation (after the Polish logician Jan Lukasiewicz) and the postorder traverse is therefore called a backwards Polish notation
  • 27. Binary Trees  Mathematical formulas can be represented by Binary Trees: 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 27 preorder - * * + 4 2 7 + 9 3 / 8 – 4 inorder (4 + 2) * 7 * (9 + 3) – (8/(-4)) (adding parentheses) postorder 4 2 + 7 * 9 3 + * 8 4 - / - -8* * / - 4+ 7 4 2 + 9 3
  • 28. Sorted Binary Tree A tree T is a Sorted Binary Tree where  v: T  V function to receive the value of a node  T a Binary Tree  T1 the left Sub Tree (also a Sorted Binary Trees)  T2 the right Sub Tree (also a Sorted Binary Trees) such that: v(root(T)) > v(t) for all nodes t in T1 v(root(T)) ≤ v(t) for all nodes t in T2  If you traverse a Sorted Binary Tree inorder, than all values are reached in a sorted way 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 28
  • 29. Sorted Binary Tree 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 29 7 961 3 8 5 Example Inorder: 1 3 5 6 7 8 9
  • 30. Binary Tree Definitions The height of a Tree is the length of the path from the root to the deepest node in the Tree: h(T) = 0 if the Tree T is empty h(T) = max(h(T1), h(T2)) + 1 where T1 is the left and T2 the right Sub Tree The cardinality of a Tree T is the number n of elements in the Tree that means: n = card(T) 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 30
  • 31. Binary Tree Example The height of this tree is 4 The cardinality of this tree is 7 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 31 7 961 3 8 5
  • 32. Binary Tree A Tree is called height-balancing if the Tree T is empty or if | h(T1) – h (T2) | ≤ 1 where h is the height of a Tree and also the Sub Trees T1 and T2 are height-balancing Trees A Tree is called balanced if the Tree T is empty or if | card(T1) – card(T2) | ≤ 1 and also the Sub Trees T1 and T2 are balanced If a Tree T is balance he is also balanced in its height 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 32
  • 33. Sorted Binary Tree 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 33 height-balancing Tree but not a balanced height left tree = 2, height right tree = 3  |h(T1) – h(T2) = |2 – 3| = 1 card left tree = 2, card right tree = 4  |card(T1) – card(T2) = |2 – 4| = 2 Balanced Tree ( height-balancing) height left tree = 2, height right tree = 2  |h(T1) – h(T2) = |2 – 2| = 0 card left tree = 3, card right tree = 3  |card(T1) – card(T2) = |3 – 3| = 0 7 961 3 8 5 751 2 6 4 3
  • 34. Binary Search Tree k a value and the s search element v(s) = k T (Binary Tree) with t = root(T) If T is empty than there is nothing to do If v(t) = k than the search element is found If not than  Replace T with the left subtree T1 if k < v(t)  T = T1  Replace T with the right subtree T2 if k ≥ v(t)  T = T2 The effort for the search is O(h(T)) 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 34
  • 35. Binary Search Tree Example Search element k k = 1 t = 5  1 < 5 t = 3  1 < 3 t = 1  1 = 1 element found! k = 7 t = 5  7 > 5 t = 8  7 < 8 t = 6  7 > 6 t = 7  7 = 7 element found! 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 35 7 961 3 8 5
  • 36. Insert a element in a Sorted Binary Tree u a values with k = v(u) to be insert T a tree with t the root of Tree T  Create a new binary sorted tree U containing only the root u  If T is empty replace T by U  Otherwise  replace T with the left sub tree T1 if k < v(t)  T = T1  replace T with the right sub tree T2 if k ≥ v(t)  T = T2  The effort is also O(h(T)) 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 36
  • 37. Insert a element in a Sorted Binary Tree Example Insert in an empty Tree the elements 5, 1, 3, 2, 8, 4, 6, 7 and 9: 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 37 5 1 3 2 4 9 8 7 6
  • 38. Delete a node in a Sorted Binary Tree Be u ϵ T the node to be removed from Tree T Be U the sub tree from T with root(U) = u  If the left Sub Tree U1 of U is empty than replace U by U1  If the right Sub Tree U2 of U is empty than replace U by U2  If both Sub Trees are not empty than:  Chose an u2 ϵ U2 such that v(u2) ≤ v(t) for all t ϵ U2  u2 has to be removed from U2  u2 replace the node u The effort to delete a node in a Tree is O(h(T)) due to the search for the minimal element u2 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 38
  • 39. Delete a node in a Sorted Binary Tree Example 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 39
  • 40. Other Tree Types  2-3 tree  2-3-4 tree  AA tree  AVL tree  B-tree  Elastic binary tree  Random binary tree  Red-black tree  Self-balancing binary search tree  Unrooted binary tree 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 40
  • 41. Any questions? 23/10/2018 Lecture 4 Dynamic Data Structure Part 2 41