Skip to content

Update display function to display_tree for visual tree representation.#8886

Closed
di-was wants to merge 13 commits intoTheAlgorithms:masterfrom
di-was:binary_display
Closed

Update display function to display_tree for visual tree representation.#8886
di-was wants to merge 13 commits intoTheAlgorithms:masterfrom
di-was:binary_display

Conversation

@di-was
Copy link
Copy Markdown

@di-was di-was commented Jul 23, 2023

Describe your change: The new binary tree display function performs a in order depth-first traversal and displays the tree, in a way which is helpful to visualize the structure of the tree.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

Comment thread data_structures/binary_tree/basic_binary_tree.py Outdated
Comment thread data_structures/binary_tree/basic_binary_tree.py Outdated
@cclauss
Copy link
Copy Markdown
Member

cclauss commented Jul 24, 2023

How is the proposed code better than the current code? The current recursive approach is kinda slick. Perhaps show the output of the two here so we can see the before and after.

di-was and others added 2 commits July 24, 2023 16:04
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
@algorithms-keeper algorithms-keeper Bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Jul 24, 2023
@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass labels Jul 24, 2023
@di-was
Copy link
Copy Markdown
Author

di-was commented Jul 24, 2023

@cclauss The current display function presents nodes in a vertical format, which may lack intuitive clarity for certain people. The proposed method offers a more visually beneficial presentation of the tree.

Initial function

 >>> display(root)
  0
  1
  2

new function

 >>> display_using_in_order_traversal(root)

        2
 1
        0

Both functions display a tree, with one root node and two children nodes , however, the second functions is visually helpful

Comment thread data_structures/binary_tree/basic_binary_tree.py
@algorithms-keeper algorithms-keeper Bot removed the tests are failing Do not merge until tests pass label Jul 25, 2023
@di-was di-was requested a review from cclauss July 25, 2023 01:56
@rohan472000
Copy link
Copy Markdown
Contributor

@cclauss kindly review this also.

2
1
0
"""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I turn this diagram 90 clockwise (so that 1 is on top) then 2 is to the left of 1 and 0 is to the right of 1 which is the opposite of lines 36 and 37.

@SimSeeker
Copy link
Copy Markdown

Nice

@cclauss cclauss closed this Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants