Skip to content

Tag: memoization

Preventing reference re-use during deepcopy

Consider the following example: The first print outputs what I would expect because the same reference is duplicated in the list. However, the second print surprised me. I would have expected the deepcopy to end up with two independent references inside the copy list. Instead it maintains the property of a si…

Frog Jump Memoization(Python)

Below is the problem description, followed by its recursive solution using Python. This solution is inefficient. I know using memoization, we can improve this solution. I have also gone through similar questions on StackOverflow but I couldn’t figure out the solution. I am fairly new to the memoization …

Memoization using dictionary

So I am trying to implement Lowest common subsequence in Python and was trying this alternative to my previous solution. I tried using a dictionary instead of a 2-D matrix to memoize the results. It’s returning which I understand is because I am not returning anything so how can I do something like this…

Does Python intern strings?

In Java, explicitly declared Strings are interned by the JVM, so that subsequent declarations of the same String results in two pointers to the same String instance, rather than two separate (but identical) Strings. For example: My question is, does CPython (or any other Python runtime) do the same thing for …