n you see the genealogy of the lord of the rings staff using this program in python?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
how can you see the genealogy of the lord of the rings staff using this program in python?
from _future_ import print_function
class Node:
def __init__(self, label):
self.label = label
self._parent = None
self._left = None
self._right = None
self.height = 0
@property
def right(self):
return self._right
@right.setter
def right(self, node):
if node is not None:
node._parent - self
self._right = node
@property
def left(self):
return self._left
@left.setter
def left(self, node):
if node is not None:
node._parent = self
self. left node
@property
def parent (self):
return self._parent
@parent.setter
def parent (self, node):
if node is not None:
self._parent = node
self.height = self.parent.height + 1
else:
self.height = 0
class AVL:
def __init__(self):
self.root = None
self.size = 0
def insert (self, value):
node Node (value)
if self.root is None:
self.root node
self.root.height = 0
self.size=1
else:
dad_node - None
curr_node = self.root
while True:
if curr_node is not None:
dad_node = curr_node
if node.label < curr_node.label:
curr_node = curr_node.left
else:
else:
curr_node = curr_node.right
node.height = dad_node.height
dad_node.height += 1
if node.label < dad_node.label:
dad_node.left = node
else:
dad_node.right = node
self.rebalance (node)
self.size += 1
break
Transcribed Image Text:from _future_ import print_function class Node: def __init__(self, label): self.label = label self._parent = None self._left = None self._right = None self.height = 0 @property def right(self): return self._right @right.setter def right(self, node): if node is not None: node._parent - self self._right = node @property def left(self): return self._left @left.setter def left(self, node): if node is not None: node._parent = self self. left node @property def parent (self): return self._parent @parent.setter def parent (self, node): if node is not None: self._parent = node self.height = self.parent.height + 1 else: self.height = 0 class AVL: def __init__(self): self.root = None self.size = 0 def insert (self, value): node Node (value) if self.root is None: self.root node self.root.height = 0 self.size=1 else: dad_node - None curr_node = self.root while True: if curr_node is not None: dad_node = curr_node if node.label < curr_node.label: curr_node = curr_node.left else: else: curr_node = curr_node.right node.height = dad_node.height dad_node.height += 1 if node.label < dad_node.label: dad_node.left = node else: dad_node.right = node self.rebalance (node) self.size += 1 break
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
def rebalance(self, node):
n = node
while n is not None:
height_right = n.height
height_left = n.height
if n.right is not None:
height_right = n.right.height
if n.left is not None:
height_left = n.left.height
if abs(height_left - height_right) > 1:
if height_left > height_right:
left_child-n.left
if left_child is not None:
h_left=
if (h_left > h_right):
self.rotate_left(n)
else:
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
if (left_child.right is not None) else 0)
(left_child.left.height
142
143
if (left_child.left is not None) else 0)
144
145
146
147
h_right = (left_child.right.height
else:
break
n = n.parent
self.double_rotate_right(n)
break
right_child = n.right
if right_child is not None:
h_right = (right_child.right.height
if (right_child.right is not None) else 0)
h_left= (right_child.left.height
if (right_child.left is not None) else 0)
if (h_left > h_right):
self.double_rotate_left(n)
break
else:
self.rotate_right(n)
break
123
124
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
def rotate_left(self, node):
aux node.parent.label
node.parent.label node.label
node.parent.right = Node (aux)
node.parent.right.height = node.parent.height + 1
node.parent.left = node.right
def rotate_right(self, node):
aux node.parent.label
=
node.parent.label = node.label
node.parent.left - Node (aux)
node.parent.left.height = node.parent.height + 1
node.parent.right = node.right
def double rotate_left(self, node):
self.rotate_right(node.getRight().getRight())
self.rotate_left(node)
def double_rotate_right(self, node):
self.rotate_left (node.getLeft().getLeft())
self.rotate_right(node)
def empty(self):
if self.root is None:
return True
return False
def preShow(self, curr_node):
if curr_node is not None:
self.preShow(curr_node.left)
print(curr_node.label, end=" ")
self.preShow(curr_node.right)
def preorder (self, curr_node):
if curr_node is not None:
self.preShow (curr_node.left)
self.preShow(curr_node.right)
print(curr_node.label, end-" ")
def getRoot (self):
return self.root
Transcribed Image Text:81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 def rebalance(self, node): n = node while n is not None: height_right = n.height height_left = n.height if n.right is not None: height_right = n.right.height if n.left is not None: height_left = n.left.height if abs(height_left - height_right) > 1: if height_left > height_right: left_child-n.left if left_child is not None: h_left= if (h_left > h_right): self.rotate_left(n) else: 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 if (left_child.right is not None) else 0) (left_child.left.height 142 143 if (left_child.left is not None) else 0) 144 145 146 147 h_right = (left_child.right.height else: break n = n.parent self.double_rotate_right(n) break right_child = n.right if right_child is not None: h_right = (right_child.right.height if (right_child.right is not None) else 0) h_left= (right_child.left.height if (right_child.left is not None) else 0) if (h_left > h_right): self.double_rotate_left(n) break else: self.rotate_right(n) break 123 124 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 def rotate_left(self, node): aux node.parent.label node.parent.label node.label node.parent.right = Node (aux) node.parent.right.height = node.parent.height + 1 node.parent.left = node.right def rotate_right(self, node): aux node.parent.label = node.parent.label = node.label node.parent.left - Node (aux) node.parent.left.height = node.parent.height + 1 node.parent.right = node.right def double rotate_left(self, node): self.rotate_right(node.getRight().getRight()) self.rotate_left(node) def double_rotate_right(self, node): self.rotate_left (node.getLeft().getLeft()) self.rotate_right(node) def empty(self): if self.root is None: return True return False def preShow(self, curr_node): if curr_node is not None: self.preShow(curr_node.left) print(curr_node.label, end=" ") self.preShow(curr_node.right) def preorder (self, curr_node): if curr_node is not None: self.preShow (curr_node.left) self.preShow(curr_node.right) print(curr_node.label, end-" ") def getRoot (self): return self.root
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Concept of Threads
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education