ssignment: Contains at minimum 20 nodes.  All paths must have a cost between 1-15. You must use each cost at least once with the remaining costs of your choice in the same range. All nodes must be able to communicate with all other nodes (does not have to be a direct path) Each node can only connect to, at maximum, 5 other nodes. The cost of an extra hop is 1 1/2 tim

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

I need to construct a optimal binary search tree (OBST).  I am using Python to create this code. I already started creating the binary search tree. I need help trying to implement the optimal binary search tree. I did the class and then I did the insertion next to add the nodes. There needs to be at least 20 nodes. After that, I'm stuck. Not sure what code is needed to add for optimal cost. 

Criteria from my assignment:

  • Contains at minimum 20 nodes. 
  • All paths must have a cost between 1-15. You must use each cost at least once with the remaining costs of your choice in the same range.
  • All nodes must be able to communicate with all other nodes (does not have to be a direct path)
  • Each node can only connect to, at maximum, 5 other nodes.
  • The cost of an extra hop is 1 1/2 times the cost of the second path and 2 times the cost of a third path.  Any path greater than 3 is at the same cost as the third.

This is what is required for us in the assignment. 

My Code in Python:

class BST:
def __init__(self, value):
self.value = value
self.leftChild = None
self.rightChild = None


def insert(self, value):
# insertion node code
if self == self.value:
return
if self < self.value:
if self.leftChild:
self.leftChild.insert(value)
else:
self.leftChild = BST(value)
else:
# right node recursive function.
if self.rightChild:
self.rightChild.insert(value)
return
else:
self.rightChild = BST(value)

# in order post traversal - comment. 

Questions:

What is the implementation code in Python for the optimal binary search tree? 

Do I need to create a traversal first before doing the optimal cost? I don't think but I'm not sure. 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar 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