All Questions
Tagged with memoization recursion
18 questions
5
votes
3
answers
957
views
LeetCode 678: Valid Parenthesis String, Recursion memoization to DP
How can the following recursion + memoization code be converted into a tabulation format dynamic programming solution?
The code is working, but I want to improve it.
The challenge I am facing is ...
2
votes
1
answer
194
views
k-dice Ways to get a target value
I'm trying to solve the following problem:
You have a k-dice.
A k-dice is a dice which have k-faces and each face have value written from 1 to k.
Eg. A 6-dice is the normal dice we use while playing ...
2
votes
2
answers
250
views
Generate the number of partitions of each integer
I've coded a program that calculates the number of partitions of n into at least two distinct parts, and is relatively quick too (about N^1.5 complexity). For input 30 000 it takes roughly 4 seconds. ...
2
votes
1
answer
202
views
10
votes
1
answer
2k
views
Find all paths in a graph
My code does a DFS on the given graph and prints all possible paths for a given start and end node. My question is how can this be improved?
Can some form of memoization be used here? There are cases ...
3
votes
1
answer
319
views
Efficiently calculate value of Pascal's Triangle using memoization and recursion
So reading about functional programming, applications to dynamic programming, and learning Scala. I figured I would try it out with a popular example, Pascal's Triangle, tests against known values ...
6
votes
2
answers
1k
views
C++17 Recursive Fibonacci calculation with memoization
Compiler is g++ 4.2. I'm new to C++, but I've done a lot of data science, web scraping, and some socketing stuff in Python. This code generates the nth Fibonacci number, either with a naive ...
0
votes
3
answers
130
views
Advent of Code 2020, Day 10 in Ruby
I'm an amateur programmer making a career change into web development. I've found Advent of Code challenges are great way to sharpen my skills. I've cleaned up this solution for Day 10, 2020 as much ...
3
votes
1
answer
180
views
Fibonacci Sequence using Recursion with Memoisation
File fibonacci.aec:
...
4
votes
3
answers
8k
views
Knapsack problem - recursive approach with memoization
This post is based on the 0-1 Knapsack problem. I came across this problem in Assignment #4 of Professor Tim Roughgarden's course Greedy Algorithms, Minimum Spanning Trees, and Dynamic Programming on ...
12
votes
2
answers
4k
views
Recursive Fibonacci in Rust with memoization
I'm trying to come up with an "elegant" way of calculating Fibonacci for number in Rust, using recursion and memoization (self-imposed requirements).
This is what I have so far:
...
3
votes
1
answer
2k
views
Determine all ways a string can be split into valid words, given a dictionary of all words
This function word_break(s, dictionary) receives a string s and a set of all valid words ...
3
votes
0
answers
2k
views
Robot on a Grid: Find a path between two corners with forbidden cells on the road
Problem statement
The problem is defined in the book as following:
8.2 Robot in a Grid Imagine a robot sitting on the upper left corner of grid with r rows and <...
1
vote
1
answer
460
views
Recursive Fibonacci in Java
I just started learning recursion and memoization, so I decided to give a simple implementation a shot. Works with some simple test cases I came up with. Is there anything I can add to make this more ...
2
votes
1
answer
240
views
Check the equality for each subset of a string S against the target T and return a count
I wrote the following code to solve this leetcode problem:
...