Computer Science  >  QUESTIONS & ANSWERS  >  CP 164Popularity_Tree_linked(GRADED A) (All)

CP 164Popularity_Tree_linked(GRADED A)

Document Content and Description Below

""" ------------------------------------------------------- Popularity Tree class. ------------------------------------------------------- Author: David Brown ID: 999999999 Email: [email protected] ... __updated__ = "2020-04-11" ------------------------------------------------------- Linked class version of the Popularity_Tree (PT) ADT. ------------------------------------------------------- """ from copy import deepcopy class _PT_Node: def __init__(self, value): """ ------------------------------------------------------- Initializes a PT node containing value. Child pointers are None, height is 1, count is 1 Use: node = _PT_Node(value) ------------------------------------------------------- Parameters: value - value for the node (?) Returns: A _PT_Node object (_PT_Node) ------------------------------------------------------- """ self._value = deepcopy(value) self._left = None self._right = None self._height = 1 self._rcount = 1 # Retrieval count return def _update_height(self): """ ------------------------------------------------------- Updates the height of the current node. _height is 1 plus the maximum of the node's (up to) two child heights. Use: node._update_height() ------------------------------------------------------- Returns: None ------------------------------------------------------- """ if self._left is None: left_height = 0 else: left_height = self._left._height if self._right is None: right_height = 0 else: right_height = self._right._height self._height = max(left_height, right_height) + 1 This study source was downloaded by 100000793680026 from CourseHero.com on 04-20-2021 18:14:49 GMT -05:00 https://www.coursehero.com/file/60414938/Popularity-Tree-linkedtxt/ This study resource was shared via CourseHero.comreturn class Popularity_Tree: def __init__(self): """ ------------------------------------------------------- Initializes an empty PT. Use: pt = PT() ------------------------------------------------------- Returns: A PT object (PT) ------------------------------------------------------- """ self._root = None self._count = 0 return def is_empty(self): """ ------------------------------------------------------- Determines if pt is empty. Use: b = pt.is_empty() ------------------------------------------------------- Returns: True if pt is empty, False otherwise. ------------------------------------------------------- """ return self._root is None def __len__(self): """ ------------------------------------------------------- Returns the number of nodes in the PT. Use: n = len(pt) ------------------------------------------------------- Returns: the number of nodes in pt. ------------------------------------------------------- """ return self._count def height(self): """ ------------------------------------------------------- Returns the maximum height of a PT, i.e. the length of the longest path from root to a leaf node in the tree. Use: h = pt.height() ------------------------------------------------------- Returns: h - maximum height of pt (int) ------------------------------------------------------- """ if self._root is None: h = 0 else: h = self._root._height return h This study source was downloaded by 100000793680026 from CourseHero.com on 04-20-2021 18:14:49 GMT -05:00 https://www.coursehero.com/file/60414938/Popularity-Tree-linkedtxt/ This study [Show More]

Last updated: 3 years ago

Preview 1 out of 7 pages

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)
Preview image of CP 164Popularity_Tree_linked(GRADED A) document

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Reviews( 0 )

$7.00

Buy Now

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Instant download

Can't find what you want? Try our AI powered Search

45
0

Document information


Connected school, study & course


About the document


Uploaded On

Apr 21, 2021

Number of pages

7

Written in

All

Seller


Profile illustration for Expert Tutor
Expert Tutor

Member since 4 years

58 Documents Sold

Reviews Received
6
2
0
0
3
Additional information

This document has been written for:

Uploaded

Apr 21, 2021

Downloads

 0

Views

 45

Document Keyword Tags


$7.00
What is Scholarfriends

Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·