All Projects → Bishalsarang → Recursion-Tree-Visualizer

Bishalsarang / Recursion-Tree-Visualizer

Licence: MIT license
A simple python package that helps to visualise any recursive function by adding a single line of code.

Programming Languages

python
139335 projects - #7 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to Recursion-Tree-Visualizer

react-folder-tree
A versatile react treeview library that supports custom icons and event handlers
Stars: ✭ 56 (-37.08%)
Mutual labels:  recursion, recursion-tree, recursion-tree-visualiser, recursion-tree-visualizer
Traverser
Traverser is a Java library that helps software engineers implement advanced iteration of a data structure.
Stars: ✭ 45 (-49.44%)
Mutual labels:  recursion, hacktoberfest2020
Dynamics
A Compositional Object-Based Approach to Learning Physical Dynamics
Stars: ✭ 159 (+78.65%)
Mutual labels:  recursion
interview-cookbook
A playground for learning DataStructures, Algorithms, and Object-Oriented Concepts.
Stars: ✭ 25 (-71.91%)
Mutual labels:  recursion
Golang Examples
Some examples for the programming language Go.
Stars: ✭ 14 (-84.27%)
Mutual labels:  recursion
Leetcode
High-quality LeetCode solutions
Stars: ✭ 178 (+100%)
Mutual labels:  recursion
IssueAi
O Issue Ai cria um espaço de visibilidade para os projetos open source de Computação@UFCG.
Stars: ✭ 32 (-64.04%)
Mutual labels:  hacktoberfest2020
Dsa Geeksclasses
DSA-Self Paced With Doubt Assistance Course Solutions in Python (Python 3)
Stars: ✭ 137 (+53.93%)
Mutual labels:  recursion
AzSubscriptionCleaner
Delete automatically the useless resources in your Azure subscription.
Stars: ✭ 29 (-67.42%)
Mutual labels:  hacktoberfest2020
tetriss
Tetris clone written in JavaScript 🎮 https://antonioolf.github.io/tetriss/
Stars: ✭ 14 (-84.27%)
Mutual labels:  hacktoberfest2020
website-www.codeuino.org
www.codeuino.org/
Stars: ✭ 35 (-60.67%)
Mutual labels:  hacktoberfest2020
Stanley
An Android app explorer for developers (extract the manifest and other info from any installed application)
Stars: ✭ 82 (-7.87%)
Mutual labels:  hacktoberfest2020
Recursion Tree Visualizer
🌳 Input the javascript code of any recursive function and visualize your recursion tree
Stars: ✭ 198 (+122.47%)
Mutual labels:  recursion
Data-Structure-Algorithm-Programs
This Repo consists of Data structures and Algorithms
Stars: ✭ 464 (+421.35%)
Mutual labels:  recursion
Algo Tree
Algo-Tree is a collection of Algorithms and data structures which are fundamentals to efficient code and good software design. Creating and designing excellent algorithms is required for being an exemplary programmer. It contains solutions in various languages such as C++, Python and Java.
Stars: ✭ 166 (+86.52%)
Mutual labels:  recursion
oauth-jsclient
Intuit's NodeJS OAuth client provides a set of methods to make it easier to work with OAuth2.0 and Open ID
Stars: ✭ 102 (+14.61%)
Mutual labels:  hacktoberfest2020
Typelang
🌳 A tiny language interpreter implemented purely in TypeScript's type-system
Stars: ✭ 149 (+67.42%)
Mutual labels:  recursion
Awesome Functional Programming
Yet another resource for collecting articles, videos etc. regarding functional programming
Stars: ✭ 2,725 (+2961.8%)
Mutual labels:  recursion
UberCarAnimation
This app is for animating a car like uber from one position to another with preserving angle and smooth animation
Stars: ✭ 53 (-40.45%)
Mutual labels:  hacktoberfest2020
workshop-subscription-system
No description or website provided.
Stars: ✭ 28 (-68.54%)
Mutual labels:  hacktoberfest2020

Recursion Visualiser

PyPI downloads Stars Forks

Recursion visualiser is a python tool that visualizes recursion tree with animation and draws recursion tree for recursive function. It works with almost any type of recursive function. Just add the recursion-visualiser decorator to your function and let it do the rest of the work.

Installation

1. Installing graphviz

Windows

The only dependency for recursion visualiser is Graphviz

  • Download graphviz binary
  • Add graphviz bin to path manually or by adding the following line on your script. Change the installation directory according to your installation path
# Set it to bin folder of graphviz  
os.environ["PATH"] += os.pathsep +  'C:/Program Files (x86)/Graphviz2.38/bin/'  

Ubuntu

  • Install graphviz
 sudo apt install graphviz

The instructions to install graphviz for other operating system is available here

2. Installing recursion-visualiser

The easiest way to install recursion-visualiser package is from pypi

pip install recursion-visualiser

An alternative way is to clone the repository and install all the requirements.

pip install -r requirements.txt

Alternative Installation using Docker

If you have docker and docker-compose installed then you can install recursion-tree-visualiser using Docker and docker-compose.yml file

  1. Download Docker file from repo
curl https://raw.githubusercontent.com/Bishalsarang/Recursion-Tree-Visualizer/master/Dockerfile --output Dockerfile
  1. Download docker-compose.yml
curl https://raw.githubusercontent.com/Bishalsarang/Recursion-Tree-Visualizer/master/docker-compose.yml --output docker-compose.yml
  1. Start docker container
CURRENT_UID=$(id -u):$(id -g) docker-compose up
  1. Run any python scripts and run using
docker-compose exec vs python fibonacci.py

Usage

The preferred way to import the decorator class from the package is as:

from visualiser.visualiser import Visualiser as vs

1. Fibonacci

Let's draw the recursion tree for fibonacci number.
Here is how the simple code looks like

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

print(fib(6))  

Now we want to draw the recursion tree for this function. It is as simple as adding a decorator

# Author: Bishal Sarang

# Import Visualiser class from module visualiser
from visualiser.visualiser import Visualiser as vs

# Add decorator
# Decorator accepts optional arguments: ignore_args , show_argument_name, show_return_value and node_properties_kwargs
@vs(node_properties_kwargs={"shape":"record", "color":"#f57542", "style":"filled", "fillcolor":"grey"})
def fib(n):
    if n <= 1:
        return n
    return fib(n=n - 1) + fib(n=n - 2)


def main():
    # Call function
    print(fib(n=6))
    # Save recursion tree to a file
    vs.make_animation("fibonacci.gif", delay=2)


if __name__ == "__main__":
    main()

Here are the changes required:

  • Add decorator Visualiser which accepts optional arguments ignore_args, show_argument_name and 'show_return_value'
  • Change every function calls to pass as keyword arguments.
  • Make_animation

The output image are saved as "fibonacci.gif" and "fibonacci.png"

Here is how the recursion tree looks like:
Animation: enter image description here

enter image description here

Support:

Find other examples here and read more about recursion-visualiser here

TODO:

  • Minimal working version
  • Upload package to pypi
  • Support animation
  • Add node styles
  • Support aliasing for function name
  • Show repeated states
  • Support node_color, backgroundcolor etc
  • Refactor
  • Handle base cases
  • Make more beautiful trees
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].