Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is my Tree code too long?
#2
That doesn't strike me as a tree at all. You stated that selecting "b" would take you to the 8th index, which is a "b", but indices 2 and 10 are also "b"; how would this access those?

Plus, there are two strings in the tree that break the str-list-str-list pattern - even if they don't have subnodes, they should still have an empty list for the sake of consistency. This is especially true is you're using indexing to access subsequent subnodes since changes to the pattern will alter the index needed to access all nodes down the line.

Tree structures are complex because there are a variety of checks and behaviors needed to gain the benefits. At a bare minimum, each node needs to be able to contain a value of its own and at least two nodes under it. Try your hand at making a node class that does just that - stores those three attributes. Then, think through how to assign a second node to that one's right or left.
Reply


Messages In This Thread
Is my Tree code too long? - by BladedSupernova - Feb-11-2020, 06:45 AM
RE: Is my Tree code too long? - by stullis - Feb-11-2020, 04:09 PM
RE: Is my Tree code too long? - by BladedSupernova - Feb-11-2020, 05:38 PM
RE: Is my Tree code too long? - by BladedSupernova - Feb-11-2020, 08:35 PM
RE: Is my Tree code too long? - by BladedSupernova - Feb-12-2020, 01:26 AM
RE: Is my Tree code too long? - by Larz60+ - Feb-12-2020, 03:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Code for Preorder Traversal of a Binary Tree Bolt 1 636 Sep-22-2023, 09:32 AM
Last Post: Gribouillis
  Does this code need to be so long? duckredbeard 4 955 Sep-27-2022, 09:36 AM
Last Post: ibreeden
  how long can a line of code be? Skaperen 2 2,242 Jun-09-2021, 06:31 PM
Last Post: Skaperen
  Factorial Code is not working when the given number is very long integer Raj_Kumar 2 2,343 Mar-31-2020, 06:40 PM
Last Post: deanhystad
  Mix-in class tree file not running the self test code. arjunsingh2908 3 3,024 Aug-14-2018, 05:46 PM
Last Post: arjunsingh2908
  What is wrong with code? Bin. Tree counting Peter_EU 3 3,484 Nov-08-2017, 08:41 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020