Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

COMPLETE IN PYTHON PLEASE! In the Tree class, finish the method called get_nodes. This method should take in a piece of data that the method

COMPLETE IN PYTHON PLEASE!

In the Tree class, finish the method called get_nodes. This method should take in a piece of data that the method is searching for, and it should return a list of all of the nodes in the tree that contain that piece of data. The list returned should be in hierarchical order, meaning the list should be ordered from the highest ranking node to lowest ranking node. You can assume that there will be at most one node with the given data on any particular level of the tree.

"""Tree class and tree node class."""

class Node():

"""Node in a tree."""

def __init__(self, data, children=None):

children = children or []

assert isinstance(children, list), \

"children must be a list!"

self.data = data

self.children = children

def __repr__(self):

"""Reader-friendly representation."""

return f""

class Tree():

"""Tree."""

def __init__(self, root):

self.root = root

def __repr__(self):

"""Reader-friendly representation."""

return f""

def get_nodes(self, data):

""" Return a list of nodes with the given data"""

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

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

Students also viewed these Databases questions