python red black tree
In all the classes for this assignment, use of the following Python language features is mandatory:
- Write one or more classes that define a red black tree which can be used with the following main function.
import random_x000D_ import sys_x000D_ _x000D_ def main( ):_x000D_ if len(sys.argv) < 2:_x000D_ print('Please provide the number of keys to enter.')_x000D_ sys.exit(1)_x000D_ s = int(sys.argv[1])_x000D_ parts = int(s/3)_x000D_ t = RBTree( )_x000D_ r = list(range(1,s+1))_x000D_ _x000D_ print('Randomly inserting the numbers from 1 to {}.'.format(len(r)))_x000D_ _x000D_ random.shuffle(r)_x000D_ _x000D_ for i in r:_x000D_ print('inserted {}'.format(i))_x000D_ t.insert(i)_x000D_ f = open('a.dot', 'w')_x000D_ writeRBTree(t, f)_x000D_ f.flush( )_x000D_ f.close( )_x000D_ random.shuffle(r)_x000D_ _x000D_ for n in range(1, 3):_x000D_ m = r[(n-1) * parts : (n * parts)]_x000D_ print(len(m))_x000D_ for i in m:_x000D_ print('removed {}'.format(i))_x000D_ v = t.remove(i)_x000D_ if v:_x000D_ print('tcompleted.')_x000D_ else:_x000D_ print('terror.')_x000D_ c = chr(n + 97)_x000D_ filename = str(c) + '.dot'_x000D_ f = open(filename, 'w')_x000D_ writeRBTree(t, f)_x000D_ f.flush( )_x000D_ f.close( )_x000D_The output of the program is a file in DOT syntax. . An example output file is the following:
digraph BST{_x000D_ node [fontname="Helvetica"];_x000D_ 7 [style="filled" fillcolor="white"]_x000D_ 2 [style="filled" fillcolor="white"]_x000D_ 7 -> 2;_x000D_ 2 [style="filled" fillcolor="red"]_x000D_ 2 -> 1;_x000D_ null1 [shape=point];_x000D_ 1 -> null1;_x000D_ null2 [shape=point];_x000D_ 1 -> null2;_x000D_ null3 [shape=point];_x000D_ 2 -> null3;_x000D_ 9 [style="filled" fillcolor="white"]_x000D_ 7 -> 9;_x000D_ null4 [shape=point];_x000D_ 9 -> null4;_x000D_ null5 [shape=point];_x000D_ 9 -> null5;_x000D_ }
"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.
Discount Code: CIPD30
Click ORDER NOW..


