How to learn algorithms using spaced repetition

62 views
Skip to first unread message

Aditya BSRK

unread,
Jan 29, 2016, 12:41:32 PM1/29/16
to mnemosyne-proj-users
Hi,
I am an on and off user of spaced repetition software. I have been considering on how best to use Mnemosyne to remember code for algorithms.
For example, take the algorithm for finding the least common ancestor of two nodes in a tree. Lifting the code from topcoder:

 void process3(int N, int T[MAXN], int P[MAXN][LOGMAXN])
  {
      int i, j;
   
  //we initialize every element in P with -1
      for (i = 0; i < N; i++)
          for (j = 0; 1 << j < N; j++)
              P[i][j] = -1;
   
  //the first ancestor of every node i is T[i]
      for (i = 0; i < N; i++)
          P[i][0] = T[i];
   
  //bottom up dynamic programing
      for (j = 1; 1 << j < N; j++)
         for (i = 0; i < N; i++)
             if (P[i][j - 1] != -1)
                 P[i][j] = P[P[i][j - 1]][j - 1];
  }

 int query(int N, int P[MAXN][LOGMAXN], int T[MAXN], 
  int L[MAXN], int p, int q)
  {
      int tmp, log, i;
   
  //if p is situated on a higher level than q then we swap them
      if (L[p] < L[q])
          tmp = p, p = q, q = tmp;
  
  //we compute the value of [log(L[p)]
      for (log = 1; 1 << log <= L[p]; log++);
      log--;
   
  //we find the ancestor of node p situated on the same level
  //with q using the values in P
      for (i = log; i >= 0; i--)
          if (L[p] - (1 << i) >= L[q])
              p = P[p][i];
   
      if (p == q)
          return p;
   
  //we compute LCA(p, q) using the values in P
      for (i = log; i >= 0; i--)
          if (P[p][i] != -1 && P[p][i] != P[q][i])
              p = P[p][i], q = P[q][i];
   
      return T[p];
  }

This is a fairly large algorithm, with some intense logic behind it. What is the best way to be able to recall it on the fly when I need it?

Thanks,
Aditya

Peter Bienstman

unread,
Jan 29, 2016, 12:45:40 PM1/29/16
to mnemosyne-proj-users
Hi,

Not sure spaced repetition is the best tool for this. Personally, I would try implementing the algorithm from scratch to try and internalise it.

But perhaps people have other suggestions.

Cheers,

Peter

Oisín Mac Fhearaí

unread,
Jan 29, 2016, 12:58:24 PM1/29/16
to mnemosyne-...@googlegroups.com
I'd agree with Peter in general for this kind of stuff; it's probably better to rewrite the code from scratch a couple of times (maybe a few different ways), and play some code golf or whatnot.

However if you want to use SRS, I'd advise to reduce the code to higher level pseudocode (i.e. not "for(i = s.size()-1; i >= 0; i--) if(P[i] > max) max = P[i]", but "m = max(node weight)" or something).
Then use cloze deletion on each line of the pseudocode. But I'd try to reduce it to less than 10 lines of pseudocode per card - ideally your pseudocode would be the minimal information necessary to remind you how to reconstruct the algorithm.

O

--
You received this message because you are subscribed to the Google Groups "mnemosyne-proj-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mnemosyne-proj-u...@googlegroups.com.
To post to this group, send email to mnemosyne-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mnemosyne-proj-users/c1576a3f-304c-44c5-8597-4a70f8cb384c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Aditya BSRK

unread,
Jan 30, 2016, 12:44:55 AM1/30/16
to mnemosyne-proj-users
Thanks for the replies Peter, and Oisin. I will try to make high level pseudo code for the algorithm, and see if I can break the algorithm into manageable cards.

Aditya
To unsubscribe from this group and stop receiving emails from it, send an email to mnemosyne-proj-users+unsub...@googlegroups.com.

To post to this group, send email to mnemosyne-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages