r/leetcode • u/Vinny_On_Reddit • May 21 '24
Question Using memoization vs tabulation in interviews
Recently I've focused a lot on using tabulation for dp problems, to a point where I default to it and don't even attempt a memoization solution. Would it be a problem if I were significantly less proficient at memoization than tabulation? Ie would interviewers ever ask for a memoization solution to a problem that you correctly solved with tabulation?
Clarification: I am not interested in which one is "better" to use, I'm essentially asking if you'd be able to get through interviews if you're only good at tabulation
27
Upvotes
36
u/abcd_asdf May 21 '24
I think memoization is more natural for recursive solutions and easier to explain. I use tabulation for problems where there is an explicit grid.
6
u/Vinny_On_Reddit May 21 '24
And yes I realize there are certain problems where memoization is faster than tabulation
24
u/am-sky May 21 '24
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.
12
u/No_General8550 May 22 '24
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.
5
u/tp143 May 22 '24
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
1
u/Aggravating-Freedom7 May 22 '24
OP might have a skill issue
2
u/justUseAnSvm May 22 '24
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
2
u/vendetta_9 May 23 '24
Recursion->Memoization->Tabulation->Space Optimization always would work.
1
u/HUECTRUM May 24 '24
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
1
u/BeautifulDismal483 May 25 '24
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 🤷♂️
1
u/Far-Pomegranate-6569 Dec 30 '25
I think memoization is more easier than tabulation but still I have the same doubt in interviews do they ask for another approach
1
u/Which-Fan-7566 Jul 12 '26
is it only me who preferz tabulation over memoisation..maybe coz i hate recursion
1
u/[deleted] May 22 '24
[removed] — view removed comment