Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python programming; pleasee help! In his exercise, you need to design and implement the following classes: Abstract Binary Tree (BT) class, with two subclasses: Concrete

Python programming; pleasee help!

In his exercise, you need to design and implement the following classes:

Abstract Binary Tree (BT) class, with two subclasses:

Concrete Binary Search Tree (BST) class Implement all functions as described below.

Concrete Max-Heap class List all functions but do not implement them.

For simplicitys sake, you can assume every item stored in a tree consists of an integer key and other attributes (at least one). Note that you must decide, for each function specified below, in which of the three classes it should be defined, whether it should be abstract or not, what it should be called, what data it should use and return, and (for BT and BST) how to code it.

Required functions:

A default constructor that creates an empty tree.

A constructor that creates a new tree containing all items provided as arguments.

A setter function that inserts a given item into the tree.

A retrieval function that searches for a given item (by key) and returns it if found.

A membership function that searches for a given item (by key) and returns true if found and false if not. It must allow the in() function to work (e.g., if item in tree: )

A delete function that searches for a given item (by key) and removes it from the tree.

A function that counts and returns the number of items in the tree. It must allow the standard len() function to work (i.e., len(tree) returns the number of nodes).

A height function that calculates and returns the (max) depth of the tree.

Four functions that implement pre-order, in-order, post-order and breadth-first traversals, generating items one by one only. (Note that Breadth-first traversal is the one used when converting a binary tree of nodes into an array. The other traversals apply to BST only.)

A function that will allow the standard print() function to output all items in order.

A function that draws the tree, in a format similar to the examples shown below. For simplicitys sake, you can assume all item keys are in the range 0-99.

image text in transcribed

13 13 13 20 20 20 1 10 27 1 10 10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions

Question

Which team solution is more likely to be pursued and why?

Answered: 1 week ago

Question

Did the team members feel that their work mattered

Answered: 1 week ago