Thursday, July 20, 2017

We were discussing file synchronization services. It uses events and callbacks to indicate progress, preview the changes to be made, handle user specified conflict resolution and graceful error handling per file.The file synchronization provider is designed to handle concurrent operations by applications. Changes to the file will not be synchronized until the next synchronization session so that concurrent changes to the source or destination is not lost. Each file synchronization is atomic so that the user does not end up with a partially correct copy of the file. This service provide incremental synchronization between two file system locations based on change detection which is a process that evaluates changes from last synchronization. The service stores metadata about the synchronization which describes where and when the item was changed, giving a snapshot of every file and folder in the replica. Changes are detected by comparing the current file metadata with the version last saved in the snapshot. For files, the comparison is done on the file size, file times, file attributes, file name and optionally a hash of the file contents. For folders, the comparison is done on folder attributes and folder names.
#codingexercise
Find the length of the longest subsequence of one string which is a substring of another string.
// Returns the maximum length of subseq in substr
    static int MaxSubSeqInSubString(string X, string Y)
    {
        char[] subseq = X.ToCharArray();
        int n = subseq.Length;
        char[] substr = Y.ToCharArray();
        int m = substr.Length;

         Debug.Assert (m < 1000 && n < 1000);
         var dp = new int[1000, 1000];
         for (int i = 0; i <= m; i++) // for substr
               for (int j = 0; j <= n; j++) // for subseq
                     dp[i, j] = 0;

         for (int i = 1; i <= m; i++) // for substr
         {
               for (int j = 1; j <= n; j++) // for subseq
               {
                       if (subseq[j-1] == substr[i-1])
                            dp[i,j] = dp[i-1,j-1] + 1;
                       else
                            dp[i,j] = dp[i,j-1];
                }
          }

        int result = 0;
        for (int i = 1; i <=m; i++)
              result = Math.Max(result, dp[i,n]);
        return result;
    }
/*
A, ABC => 1
D, ABC => 0
D, D => 1
A, D => 0
,  => 0
A,  => 0
, A => 0
A, DAG => 1
AG, DAGH => 2
AH, DAGH => 1
DAGH, AH => 2
ABC, ABC => 3
BDIGH, HDGB => 2
*/
Node GetNthElementInInorder(Node root, int N)
{
  var ret = new List<Node>();
  InorderTraversal(root, ref ret);
  if (N <= ret.Count)
     return ret[N-1];
  else
     return null;
}

No comments:

Post a Comment