Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need help with the Python code and tree structure Consider following binary tree Node class class Node: def __init__(self, data): selfdeft - None selferight =
Need help with the Python code and tree structure
Consider following binary tree Node class class Node: def __init__(self, data): selfdeft - None selferight = None self data = data # Insert Node def insert(self, data): if self datai if data selfdata: if self right is None: self right - Node (data) else: selferight insert(data) else: self data = data selfdeft - None self right = None INSTRUCTIONS 1. Create your binary tree structure using following data: 0, A,D, F, P, R, Z, C,Q 2. Define your Inorder function in the class and traverse your tree. You will get result ['A', 'C', 'D', 'F', '0', 'P', 'Q', 'R', 'Z'] 3. Define you Preorder and Posterder function and traverse your tree. 4. Add logic to print each node's address and its left link and right link for all three algorithms. ------- Inorder Traversal --------- A Ox7f03e6fe3940 Ox9756e0 Ox7f03e6fe3978 C Ox7f03e6fe3a90 Ox9756e0 Qx2756el D Ox7f03e6fe3978 Ox7f03e6fe3a90 Ox7f03e6fe39b0 F Ox7f03e6fe39b0 0x9756e0 Qx97560 0 0x7f03e6fe3908 Ox7f03ebfe3940 Ox7f03e6fe39e8 P Ox7f03e6fe39e8 Ox9756e0 Ox7f03e6fe3a20 Q Ox7f03e6fe3ac8 0x9756e0 Qx9756e0 R Ox7f03e6fe3a20 Ox7f03e6fe3ac8 Ox7f03e6fe3a58 Z Ox7f03e6fe3a58 0x9756e0 Qx9756e0 ['A', 'C', 'D', 'f', '0', 'P', 'Q', 'R', 'Z'] -------Preorder Traversal --------- O 0x7f03e6fe3908 0x7f03e6fe3940 Ox7f03e6fe39e8 -------Pastordertcaversal --------- C Ox7f03e6fe3a90 Ox9756e0 Ox97560 F Ox7f03e6fe39b0 Ox9756e0 Qx9756e0 D Ox7f03e6fe3978 Ox7f03e6fe3a90 Ox7f03e6fe39b0 A Ox7f03e6fe3940 Ox9756e0 Ox7f03e6fe3978 QOx7f03e6fe3ac8 Ox9756e0 Qx97560 Z Ox7f03e6fe3a58 0x9756e0 Ox9756 R 0x7f03e6fe3a20 Ox7f03e6fe3ac8 Ox7f03e6fe3a58 P Ox7f03e6fe39e8 Ox9756e0 Ox7f03e6fe3a20 0 Ox7f03e6fe3908 Ox7f03e6fe3940 Ox7f03e6fe39e8 ['c', 'F', 'D', 'A', 'Q', 'Z', 'R', 'P', '0'] 5. Based on your traversal result, draw down your tree structure as following example: Ox7f03e6fe3908 Ox7f03e6fe3940 Ox7f03e6fe39e8 None Ox7f03e6fe3978 None Ox7f03e6fe3a20 6. Need the following: - Your python code - Output screenshot - Entire tree structureStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started