Code Monkey home page Code Monkey logo

ackermannfunctionhyperoptimization's Introduction

Hyper optimization of The Ackermann Function

Ackermann function is a recursive function which is used as an example for the functions which can be solved only recursively and not iteratively

function

That is because of the function's third case when none of the parameters is zero, it calls itself with one of the parameters being the function itself

Sometimes for some languages like python, where recursion depth is fixed to 1000 Unless you use 'sys' module to alter it This can never be achieved iteratively.

Hence the function will go recursively until the first parameter becomes zero. There is a workaround for that, that is explained here

Since overtime the function sometimes calculates the same function with the exact same parameters, we can just store the values for each corresponding parameters and hence avoid quite a number of recursions

To avoid runtime memory wastage, that will stored in a file externally Once the function is called, regardless of the depth of iteration, it will check the file if it already has the value, if it does, it just uses that, or else it will calculate and also append the value to the file for future references

use python ackermannOptimized.py for the optimized code and python ackermannOriginal.py for the legacy code

Thank you

ackermannfunctionhyperoptimization's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.