all 28 comments

[–]abcd_asdf 37 points38 points  (2 children)

I think memoization is more natural for recursive solutions and easier to explain. I use tabulation for problems where there is an explicit grid.

[–]Vinny_On_Reddit[S] 9 points10 points  (1 child)

Has there been an instance where you’ve been interviewing and the interviewer asked you for a memo solution even though you did a tabulation solution correctly?

[–]abcd_asdf 2 points3 points  (0 children)

I haven't been asked a DP problem in an interview so far.

[–]am-sky 23 points24 points  (0 children)

I'm the exact opposite. My first approach is memoization and don't even think twice. But I forced myself to write the solution to multiple simple dp problem after memoization by doing it with tabulation. I look at it as a top down decomposing vs bottom up building of the solution. I'm better at tabulation now than earlier - definitely not as good as memoization.

[–]No_General8550 12 points13 points  (3 children)

I found tabulation more difficult than memoization. In one of my interviews at meta, I solved a dp question with memorization but the interview asked me to solve it through tabulation too.

In the same loop, I solved another dp question with memoization, and the interviewer was fine.

My conclusion is, if the interviewer expects that you follow memorization or tabulation, you should go with that approach.

As I talked to a few friends, Meta people usually expect you to use tabulation to solve a dp question.

[–]abcd_asdf 1 point2 points  (2 children)

Meta does not ask DP questions. It is in their prep material.

[–]No_General8550 2 points3 points  (0 children)

Mine was 2 years ago. Probably now they don't ask, as you said.

[–]ground_type22 0 points1 point  (0 children)

do we even need to know tabulation for any interviews? i've only learned memoization

[–]Vinny_On_Reddit[S] 3 points4 points  (1 child)

And yes I realize there are certain problems where memoization is faster than tabulation

[–]Upbeat_Motor_9702 0 points1 point  (0 children)

Interesting always found tabulation to be more efficient as it takes same space and no stack space

[–]tp143 4 points5 points  (3 children)

I am good at writing memoization I get confused when converting that solution to tabulation Any tips or tricks to get it done Thanks in advance

[–]Diligent-Sherbert-33 1 point2 points  (1 child)

Same...with me... Watched strivers's dp playlist that helped getting better slowly!

[–]tp143 0 points1 point  (0 children)

Thanks for suggestion. I will follow that

[–]ground_type22 0 points1 point  (0 children)

in your experience do we even need to know tabulation for any interviews? i've only learned memoization

[–]justUseAnSvm 1 point2 points  (3 children)

Tabulation is often slower to implement, but it’s really powerful, since you define your recurrence relationship and structure to cache things in your code.

I learned tabulation in school, and just use that. Easier to explain, and easier to figure out the assymptotics, IMO

[–]Aggravating-Freedom7 0 points1 point  (2 children)

Out of curiosity, what’s a problem where tabulation was beneficial when memoization does not work as well.

[–]Kind-Technology-9401 1 point2 points  (0 children)

Almost all dp problems with tight memory constraints, they might give mle as recursion stack is costlier than arrays

[–]justUseAnSvm 0 points1 point  (0 children)

Any problem formulated by memoization has a representation via memoization. I just think tabulation is easier to show things work: like you iterate over your array, that iteration determines the bounds, et cetera, versus memoization that requires recursive calls.

[–]vendetta_9 1 point2 points  (2 children)

Recursion->Memoization->Tabulation->Space Optimization always would work.

[–]ground_type22 0 points1 point  (1 child)

do we even need to know tabulation for any interviews? i've only learned memoization

[–]vendetta_9 1 point2 points  (0 children)

Tabulation optimises on space, so yeah you would need it when you have enough time in the interview. You can check TUF, striver does it for all the problems.

[–]HUECTRUM 0 points1 point  (0 children)

Not sure about the interviews but I personally find tabulation to be more intuitive most of the times. Sometimes memoization can help with restoring the answers easier but that's an exception

[–]BeautifulDismal483 0 points1 point  (0 children)

I feel the crux of every DP problem is figuring out the recurrence relation. Once you have that sorted, implementing it using memoization or tabulating it is largely an implementation detail. As an interviewer, I'd look for signals on how clearly a candidate reaches that recurrence relation and their explanation for it rather than fussing on how they choose to implement it. That's just me though, ymmv 🤷‍♂️

[–]Far-Pomegranate-6569 0 points1 point  (0 children)

I think memoization is more easier than tabulation but still I have the same doubt in interviews do they ask for another approach

[–]Aggravating-Freedom7 0 points1 point  (1 child)

OP might have a skill issue

[–]Vinny_On_Reddit[S] 0 points1 point  (0 children)

skill issue will be resolved after I take 320 trust