Code Monkey home page Code Monkey logo

recurruncewith3methods's Introduction

Recurrunce With 3 Methods

This program implements the following piecewise recurrence relation in C using three different approaches: recursive, dynamic programming, and iterative.

Pros & Cons of each

1 Recursive Approach

Pros:

  • Simple and easy to read.

Cons:

  • Exponential time complexity O(2^n), very slow at large values of n.
  • High memory usage due to duplicate recursive calls, for example f(1) will be called more than 60 if n is equal to 70.

2 Dynamic Programming Approach

Pros:

  • Efficient and faster than the recursive approach for large values of n O(n).
  • Avoids redundant calculations (as in the recursive approach) by storing previously calculated values.

Cons:

  • Requires additional memory to store the array of previously calculated values.
  • Implementation is more complex compared to the recursive approach.

3 Iterative Approach

Pros:

  • Efficient and faster than both the recursive.
  • Very easy to read.
  • Linear time complexity.

Cons:

Development Environment

  • Operating System: Windows 10
  • Compiler: GCC

Compilation

To compile the source code, follow these steps:

  1. Open a terminal or command prompt.
  2. Navigate to the directory where the source code is located.
  3. Run the following command:
gcc Q2.c -o Q2
  1. The program will execute and display the same number but with 3 approaches for the specified input value (n).
  • Change the value of n in main() to get different output.

recurruncewith3methods's People

Contributors

omaar2000 avatar

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.