Skip to content

Improve runtime of number_of_nonisomorphic_trees(). - #7917

Merged
dschult merged 3 commits into
networkx:mainfrom
ricbit:improve-nonisomorphic-trees
Mar 23, 2025
Merged

dschult merged 3 commits into
networkx:mainfrom
ricbit:improve-nonisomorphic-trees

Conversation

@ricbit

@ricbit ricbit commented Mar 20, 2025

Copy link
Copy Markdown
Contributor

The current implementation of number_of_nonisomorphic_trees() constructs all trees and output the amount of trees created, which is exponential. The proposed implementation computes directly the number, using an O(n**3) formula.

…tation constructs all trees and output the amount of trees created, which is exponential. The proposed implementation computes directly the number, using an O(n**3) formula.
 - Mv reference to docstring summary and add link.
 - Fix formatting of Returns.

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @ricbit - I took the liberty of pushing up a minor reorganization of the docstring: the References section is expected to follow a certain format to render correctly, so I just got rid of it and moved the description up near the top of the docstring (and added a link).

I was happy to have the ability to generate some eye-wateringly huge numbers with n ~ 1000 (the previous implementation wasn't practical above n ~ 20 or so).

@ricbit

ricbit commented Mar 22, 2025

Copy link
Copy Markdown
Contributor Author

Glad to be helpful!

@ricbit ricbit left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM

@dschult dschult left a comment

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.

Thanks! This looks good -- and much better than creating them all. :)

@dschult
dschult merged commit f02879d into networkx:main Mar 23, 2025
@jarrodmillman jarrodmillman added this to the 3.5 milestone May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants