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

On Friday, 29 January 2016 18:41:32 UTC+1, Aditya BSRK wrote:
>
> 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 
> <https://www.topcoder.com/community/data-science/data-science-tutorials/range-minimum-query-and-lowest-common-ancestor/#Another%20easy%20solution%20in%20O(N%20logN,%20O(logN)>
>  
> 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
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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.

Reply via email to