Solved-Binary search trees Lab 3- Solution

$30.00 $19.00

The program bst.py in the class webpage contains implementations of basic binary search tree operations, including insertion, deletion, search and display. Modify the code to include the following operations: 1) Display the binary search tree as a figure, as shown below: Iterative version of the search operation. Building a balanced binary search tree given a…

You’ll get a: . zip file solution

 

 

Description

5/5 – (2 votes)

The program bst.py in the class webpage contains implementations of basic binary search tree operations, including insertion, deletion, search and display.

Modify the code to include the following operations:

1) Display the binary search tree as a figure, as shown below:

  1. Iterative version of the search operation.

  1. Building a balanced binary search tree given a sorted list as input. Note: this should not use the insert operation, the tree must be built directly from the list in O(n) time.

  2. Extracting the elements in a binary search tree into a sorted list. As above, this should be done in O(n) time.

  1. Printing the elements in a binary tree ordered by depth. The root has depth 0, the root’s children have depth one, and so on. For example, for the tree in the figure, your program should output:

Keys at depth 0: 10

Keys at depth 1: 4 15

Keys at depth 2: 2 8 12 18

Keys at depth 3: 1 3 5 9

Keys at depth 4: 7

As usual, write a report describing your work.