Skip to main content

A Python package to plot the graph for calls to a recursive function

Project description

Recursion Tree Plotter

A python decorator to generate a visual tree for recursive functions.

Installation

$ pip install recurstion-tree-plotter

Example

Let's say you have a recursive function for finding n-th element in Fibonacci sequence.

def fib(n):
    if n <= 1:
        return n
    return fib(n - 1) + fib(n - 2)

In order to plot a recursion tree for an execution of above function (say fib(5)), we put @plot_recursion_tree decorator over it.

from recursion_tree_plotter import plot_recursion_tree


@plot_recursion_tree
def fib(n):
    if n <= 1:
        return n
    return fib(n - 1) + fib(n - 2)

And boom!

In the tree, node label is constructed as <comma-separated args> [<counter>] where counter specifies the order of execution.

Check out examples folder for more examples!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

recursion-tree-plotter-1.0.1.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

recursion_tree_plotter-1.0.1-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page