question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clarification of memoization in exercise `coordinate-transformation`

See original GitHub issue

Context

In the last task of exercise coordinate-transformation, the instruction introduces memoization as following:

Memoizing is sometimes called dynamic programming, it allows for expensive operations to be done only once since their result is remembered.

However, the instruction also says:

[…] returns a new function that remembers the inputs to the supplied function so that the last return value can be “remembered” and only calculated once if it is called again with the same arguments.

which says that the function should only remember its last input and result.

Problem

This is from a computer science point of view.

Dynamic programming usually memoize all previous computation. Memoizing all the previous results enables dynamic programming algorithms to compute a certain problem only once.

In this task of exercise coordinate-transformation, it only asks to “remember” the last input and result, which does not completely match the idea of dynamic programming in general.

The immediate disadvantage the above mismatch introduce could be:

  • The learner confuses the concept of dynamic programming with caching or something else and meets with obstacles later when studying dynamic programming.
  • The learner who knows about dynamic programming tries to do dynamic programming and fails the test so they get confused.

Potential solutions

  1. Rephrase the quote and indicate that the problem is different from general dynamic programming problem, something like:

Memoizing is sometimes called dynamic programming, it allows for expensive operations to be done only once since their result is remembered. Note that while in dynamic programming often all previous operations are remembered, in this exercise we only want to the last one to be remembered.

  1. Modify the task so it asks the learner to record all previous computations in stead of the just the last one.
  2. Add yet another task which asks the learner to record all previous computations.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
SichangHecommented, Jun 10, 2022

Thanks for linking that other issue. I also don’t have all the background here why it was done this way so following the Chesterton’s Fence guideline, lets stick with solution 1 then. Would you like to create a PR for that?

I would like to adopt solution 1 as well. For the PR, I am worried about the exact wording, so I guess we could discuss a bit first.


@SleeplessByte Thank you for your feedback on this.

I see the revised wording is better.

As for dropping references of dynamic programming, I am in favor of not doing so. I think the exercise introduces memoization, and it is indeed closely related to dynamic programming. Also, these kind of text adds a little sugar in the exercise.

I recognize that dynamic programming does not “usually” memoize, instead, it generally refers to bottom-up approaches. That was a mistake I made. However, in my experience, when dynamic programming does memoize, usually all previous results are remembered. But, that’s debatable.

For the intended use of let or var, I don’t think it would impose any real restriction. What one can do with let, theoretically, one could use a const with an object to achieve the same effect. But, I guess that is fine.


That said, I revised the rewording from @SleeplessByte a bit. Hopefully, it would be an enhancement.

Memoizing is sometimes used in dynamic programming. It allows for expensive operations to be done only once since their results are remembered. Note that in this exercise only the last result is remembered, unlike some solutions in dynamic programming that memoize all results.

Grammar changed a little bit. Using result instead of computation to hopefully reduce confusion. Avoid indicating how much portion of dynamic programming memoizes, just say some.


If we are happy about the wording, I would like to create a PR. Otherwise, we can continue to change it.

0reactions
SleeplessBytecommented, Jun 10, 2022

Wording looks fine to me.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

mdshamoon's solution for Coordinate Transformation in ...
Learn from how mdshamoon solved Coordinate Transformation in JavaScript, and learn how others have solved the exercise.
Read more >
Temporal Approximate Function Memoization - PARAG@N
We propose temporal approximate function memoization (TAF-Memo), a semantically relaxing compiler transformation that leverages this observation.
Read more >
Dynamic Programming Algorithms
The subproblems are stored in a matrix for future access. This is called memoization. For example, d(3,2) can be computed by comparing d(3,1),...
Read more >
How does one explain that transformations 'inside' a function ...
This equation is a rule for telling whether a point is part of the graph or not: you sub the coordinates (x,y) of...
Read more >
Memoization in Dynamic Programming Through Examples
Dynamic programming is a technique for solving problems, whose solution can be expressed recursively in terms of solutions of overlapping sub-problems.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found