Giter VIP home page Giter VIP logo

shreyansh96 / dynamic-programming Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 3.0 37 KB

This repository was made for usage in teaching & learning dynamic programming. This consists of problem statements, various approaches to a problem, time-complexities, running time comparison.

License: MIT License

Python 100.00%
dynamic-programming python tabulation memoization problem-statements problem-solving competitive-programming time-complexity

dynamic-programming's Introduction

Dynamic Programming

This repository was created for teaching or learning dynamic programming using problem statements. Along with the raw implementation, for using dynamic programming easily in real-life, an alternate solution using functools library is also provided.

Identifying and Approaching a Dynamic Programming Problem

  • Notice any overlapping solutions
  • decide what is the trivially smallest input
  • Think recursively to use Memoization
  • Think iteratively to use Tabulation
  • Draw a strategy first!

Memoization (Top - Down) Recipe

  1. Develop a functional code.
  • Visualize the problem as a tree.
  • Implement the tree using recursion
  • Test it out.
  1. Work on Optimality
  • Add a memo object - array, dictionary, etc.
  • Add a base case to return memo values, leaf nodes of the tree.
  • Store return values into the memo.

Tabulation (Bottom - Up) Recipe

  1. Visualize the problem as a table
  2. Size the table based on the inputs
  3. Initialize the table with default values (For python, if necessary)
  4. Seed the trivial answer into the table (Initiate value(s) in the table which will act as activation for others)
  5. Iterate through the table
  6. Fill further positions based on the current position (this can also be modified to fill current position based on past values)

Some Problem Statements taken from Learn to Solve Algorithmic Problems & Coding Challenges by Alvin Zablan

Solutions in Python 3.9

Follow this sequence for proper order of problems:

  1. fibonacci.py
  2. grid_traveller.py
  3. can_sum.py
  4. how_sum.py
  5. best_sum.py
  6. can_construct.py
  7. count_construct.py
  8. all_construct.py
  9. longest_common_subsequence.py

Each file has problem statement mentionend in the docstring, and complexities mentioned in the solution.

There are multiple solutions presented to the same problem, all solutions are encapsulated in a class.

By default it will run all the solutions and compare execution times.

For simplicity, The execution should be done from home directory, simply run
python main.py

This will run all the solutions, modify it accordingly.

For advanced users, you can set your path in IDE, and run the files directly.

dynamic-programming's People

Contributors

shreyansh96 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

dynamic-programming's Issues

Unit test cases integration

For every problem statement, sufficient cases needs to be created so that whenever someone adds a new solution it is easily verified.
Pytests will be preferred for this.

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.